Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

INTMDB217 - Wait until user is applied to clusters #27

Conversation

thetonymaster
Copy link
Contributor

Overview

As reported in the Vault repo issue: #10
Right now the vault database user plugin for Atlas returns as soon as the API request is successfully accepted by Atlas. However the user takes time to apply to all the clusters in a project, meaning that if the credential is handed to an application that tries to then use that new credential right away- authentication fails. We now have an endpoint to check the status: https://docs.atlas.mongodb.com/reference/api/clusters-check-operation-status/
We need to build in the ability to poll that endpoint and wait to return the credential till it is really applied. Ideally this is an optional function so that if users would rather a faster return over being sure the user is really created we don't inadvertently frustrate them - if not possible then we'll default to the "really applied" default.

https://jira.mongodb.org/browse/INTMDB-217

Design of Change

Create a goroutine for each of the clusters then wait until the change is applied on each of them. Wrap the errors and return error or the user if it's sucessfull.

Related Issues/Pull Requests

https://jira.mongodb.org/browse/INTMDB-217

Contributor Checklist

[ ] Add relevant docs to upstream Vault repository, or sufficient reasoning why docs won’t be added yet
My Docs PR Link
Example
[x] Add output for any tests not ran in CI to the PR description (eg, acceptance tests)
[x] Backwards compatible

No documentation is necessary at the time

@thetonymaster
Copy link
Contributor Author

image

@thetonymaster thetonymaster changed the title Intmdb 217/wait until user applied INTMDB217 - Wait until user is applied to clusters Aug 4, 2021
mongodbatlas.go Outdated
@@ -126,6 +128,56 @@ func (m *MongoDBAtlas) NewUser(ctx context.Context, req dbplugin.NewUserRequest)
return dbplugin.NewUserResponse{}, err
}

clusters, _, err := client.Clusters.List(ctx, m.ProjectID, &mongodbatlas.ListOptions{})
if err != nil {
return dbplugin.NewUserResponse{}, fmt.Errorf("roles array is required in creation statement")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nit] no need for formatting

Suggested change
return dbplugin.NewUserResponse{}, fmt.Errorf("roles array is required in creation statement")
return dbplugin.NewUserResponse{}, errors.New("roles array is required in creation statement")

mongodbatlas.go Outdated

operation := func() error {

status, _, err := client.Clusters.Status(context.Background(), m.ProjectID, clustername)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

any reason not to reuse the context from outside the loop?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nope, will fix this

@@ -126,6 +128,56 @@ func (m *MongoDBAtlas) NewUser(ctx context.Context, req dbplugin.NewUserRequest)
return dbplugin.NewUserResponse{}, err
}

clusters, _, err := client.Clusters.List(ctx, m.ProjectID, &mongodbatlas.ListOptions{})
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this api call is paginated, if someone has more than 100 clusters you may miss those outside the [1,100] range

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems this is not correctly implemented on the client, will raise an issue with the mongo team

@kalafut
Copy link
Contributor

kalafut commented Nov 8, 2021

After some more research we have elected to not merge this PR. Please see #10 (comment) for more details.

@kalafut kalafut closed this Nov 8, 2021
@thetonymaster thetonymaster deleted the INTMDB-217/wait-until-user-applied branch November 8, 2021 17:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants