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

Mongodb plugin #2698

Merged
merged 18 commits into from
May 11, 2017
Merged

Mongodb plugin #2698

merged 18 commits into from
May 11, 2017

Conversation

calvn
Copy link
Contributor

@calvn calvn commented May 9, 2017

No description provided.

@calvn calvn requested review from jefferai and briankassouf May 9, 2017 16:04
@jefferai jefferai added this to the 0.7.3 milestone May 9, 2017
{
"plugin_name": "mongodb-database-plugin",
"allowed_roles": "readonly",
"uri": "mongodb://admin:[email protected]:27017/admin?ssl=true"
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we name this connection_url to match the other plugin types?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure, I kept it as uri since that's the parameter name for the current secret backend, but it makes sense to change it to match the other DBs.


func (cp *MongoDBCredentialsProducer) GenerateExpiration(ttl time.Time) (string, error) {
return "", nil
}
Copy link
Contributor

@briankassouf briankassouf May 9, 2017

Choose a reason for hiding this comment

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

This is essentially the same as the cassandra one, what if we made a generic CredentialsProducer that will work for both?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

GenerateUsername() constructs the username differently though.

}

return &info, nil
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Do you think one-off connection producers like this should live in the helpers folder or in the e.g. database/mongo folder? If they are not going to be used by more than one plugin I'm not sure they need to live in helpers. Open to a discussion and if we decide to move it the cassandra one should probably be moved as well.

Copy link
Contributor Author

@calvn calvn May 9, 2017

Choose a reason for hiding this comment

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

The potential problem I see is that this will produce tighter coupling and a potential dependency cycle since ParseMongoURI is used in both connutil and in plugins/database/mongodb. Even though ParseMongoURI() is only used my one plugin database, connutil has not context (i.e. imports) of the plugin package, which I think is a better tradeoff than creating a bidirectional dependency.

Copy link
Contributor

Choose a reason for hiding this comment

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

But there is no reason connutil will need to use ParseMongoURI() if this whole file is moved to the plugins/database/mongodb package, right? If moved, I don't think there will be a circular dependency

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh, I see. I thought you meant the one function, ParseMongoURI.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah, yeah sorry. I meant the whole file.

Copy link
Contributor Author

@calvn calvn May 9, 2017

Choose a reason for hiding this comment

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

I wouldn't be opposed to moving it, but then we would have some connection producers that live within the plugin package, and some in the connutil package (e.g. sql.go). I guess the same would apply for credsutil then (moving it to the plugin vs keeping it in credsutil)?

}
if statements.CreationStatements == "" {
return "", "", dbutil.ErrEmptyCreationStatement
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you move this check to the top? No need to connect to the database if there is no statement provided.

@calvn
Copy link
Contributor Author

calvn commented May 11, 2017

@briankassouf this should be ready for another review.

Copy link
Contributor

@briankassouf briankassouf left a comment

Choose a reason for hiding this comment

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

Looking pretty good! Just a few real small comments.

// [ "readWrite", { "role": "readWrite", "db": "test" } ]
//
// MongoDB's createUser command accepts the latter.
//
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you move this comment to above the function?

func (roles mongodbRoles) toStandardRolesArray() []interface{} {
// Convert array of role documents like:
//
// [ { "role": "readWrite" }, { "role": "readWrite", "db": "test" } ]
Copy link
Contributor

Choose a reason for hiding this comment

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

If there is no db set here, does it give permissions to the db specified by the role, or does it give permissions to every db?

Copy link
Contributor Author

@calvn calvn May 11, 2017

Choose a reason for hiding this comment

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

In this case the role is applied to the session's database, which will be the "db" string value from the creation_statement's JSON, or "admin" if none is provided.

https://docs.mongodb.com/manual/reference/method/db.createUser/

To specify a role that exists in a different database, specify the role with a document.

--request POST \
--data @payload.json \
https://vault.rocks/v1/database/config/mongodb
```
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's add some specifics about the statements that are required down here. Like in #2718

@calvn calvn merged commit a4c652c into master May 11, 2017
@vishalnayak vishalnayak deleted the mongodb-plugin branch May 18, 2017 18:07
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