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

Add option to specify TLS config for mongodb database plugin #5632

Closed
wants to merge 7 commits into from

Conversation

Kaisle
Copy link

@Kaisle Kaisle commented Oct 28, 2018

Fixes #1996

Related: #3191

@@ -153,7 +158,7 @@ func (c *mongoDBConnectionProducer) Close() error {
return nil
}

func parseMongoURL(rawURL string) (*mgo.DialInfo, error) {
func parseMongoURL(rawURL string, sslCert string, sslKey string, sslCA string) (*mgo.DialInfo, error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

If all variable are the same type, you can just repeat the variable names and put the type at the end.

Copy link
Author

Choose a reason for hiding this comment

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

Great advice, thanks

@@ -29,6 +31,9 @@ type mongoDBConnectionProducer struct {
WriteConcern string `json:"write_concern" structs:"write_concern" mapstructure:"write_concern"`
Username string `json:"username" structs:"username" mapstructure:"username"`
Password string `json:"password" structs:"password" mapstructure:"password"`
SSLCert string `json:"ssl_cert" structs:"ssl_cert" mapstructure:"ssl_cert"`
Copy link
Contributor

Choose a reason for hiding this comment

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

These should all be labeled TLS instead of SSL.

Copy link
Author

Choose a reason for hiding this comment

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

Good catch

@@ -46,7 +49,10 @@ has a number of parameters to further configure a connection.
"connection_url": "mongodb://{{username}}:{{password}}@mongodb.acme.com:27017/admin?ssl=true",
"write_concern": "{ \"wmode\": \"majority\", \"wtimeout\": 5000 }",
"username": "admin",
"password": "Password!"
"password": "Password!",
"ssl_cert": "/path/to/ssl/cert",
Copy link
Contributor

Choose a reason for hiding this comment

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

These parameters would not be paths. They should be PEM encoded certs.

Copy link
Author

Choose a reason for hiding this comment

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

You are right

- `password` `(string: "")` - The root credential password used in the connection URL.
- `username` `(string: "")` - The root credential username used in the connection URL.
- `password` `(string: "")` - The root credential password used in the connection URL.
- `ssl_cert` `(string: "")` - Path to a PEM-encoded client certificate.
Copy link
Contributor

Choose a reason for hiding this comment

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

Path is an incorrect description since this is this is an API endpoint not a local resource.

return tls.Dial("tcp", addr.String(), &tls.Config{})
tlsConfig := &tls.Config{}
if sslCert != "" && sslKey != "" && sslCA != "" {
clientCertPEM, err := ioutil.ReadFile(sslCert);
Copy link
Contributor

Choose a reason for hiding this comment

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

The API server will not have access to local resources. You must consume the PEM encoded string directly.

Copy link
Author

Choose a reason for hiding this comment

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

Thanks, I totally forgot about that. I have changed the code to consume as strings instead

@chrishoffman chrishoffman added this to the near-term milestone Oct 29, 2018
@hashicorp-cla
Copy link

CLA assistant check

Thank you for your submission! We require that all contributors sign our Contributor License Agreement ("CLA") before we can accept the contribution. Read and sign the agreement

Learn more about why HashiCorp requires a CLA and what the CLA includes

Have you signed the CLA already but the status is still pending? Recheck it.

@chrishoffman
Copy link
Contributor

Sorry for the delay here. Since this PR was opened, we added a CLA and there are some conflicts with recent changes. Would you mind amending this PR and addressing the CLA?

@zwiebelspaetzle
Copy link

Really hoping to see this TLS config released soon!

@douglasrafael
Copy link

We really need this feature to get a project into production.

@lucasrochagit
Copy link

This feature is very necessary! I work on a large and important project, and this user manager plug-in is very useful in our context.

@jeffsampaio
Copy link

It would be amazing to have this feature on an important project I'm working on.

@salievn
Copy link

salievn commented Mar 1, 2020

@chrishoffman : Hi, is there any news about this issue and a global approach for mysql, mssql and other ? Is there any way to specify the tls_ca through a vault write database/config and also the tls_certificate_key as pem_bundle to have mutual TLS ?
Thanks for your feedback

@tyrannosaurus-becks
Copy link
Contributor

I'm closing this for now because, unfortunately, the CLA hasn't been signed so we can't merge it. Also, it has developed merge conflicts. Just want to give a huge thank-you to @Kaisle for the time and energy dedicated to this. Please do feel free to reopen it if you get a chance to circle back around and update it. Thank you!

@pbernal pbernal removed this from the near-term milestone May 15, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Can't connect with Mongodb 3.0, 3.2 with ssl