Skip to content

Support for encryption of MySQL connections#5122

Merged
jon-wei merged 12 commits intoapache:masterfrom
a2l007:secure_mysql
Jan 10, 2018
Merged

Support for encryption of MySQL connections#5122
jon-wei merged 12 commits intoapache:masterfrom
a2l007:secure_mysql

Conversation

@a2l007
Copy link
Copy Markdown
Contributor

@a2l007 a2l007 commented Nov 28, 2017

With the MySQL versions 5.5.45+, 5.6.26+ and 5.7.6+, it is required that SSL connection must be explicitly enabled or disabled by default. Since this cannot be done with our existing code, MySQL would keep spewing warning messages everytime about explicitly enabling/disabling SSL on the connection.
This PR includes changes to support SSL/TLS encryption on MySQL connections. By default SSL is explicitly disabled on the connection so that existing users would not receive the SSL warning. Once useSSL is enabled, it would verify the server certificate by default and thus the trust store information would have to be provided along with the client keystore information for the TLS/SSL configuration.

private String trustCertificateKeyStoreType;

@JsonProperty
private String trustCertificateKeyStorePassword;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

for passwords use same mechanism as the db password so that users can provide non plain text passwords.

|`druid.metadata.mysql.ssl.trustCertificateKeyStorePassword`|Password for the trust store.|none|no|
|`druid.metadata.mysql.ssl.clientCertificateKeyStoreUrl`|The file path URL to the client certificate key store.|none|no|
|`druid.metadata.mysql.ssl.clientCertificateKeyStoreType`|The type of the key store where the client certificate is stored.|none|no|
|`druid.metadata.mysql.ssl.clientCertificateKeyStorePassword`|Password for the client key store.|none|no|
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

is it possible in some cases to have same values for “trustCertificateKeyStoreUrl” and “clientCertificateKeyStoreUrl” .. their types and passwords ? in that case we could default client* properties to be same as trust* properties

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

ignore it, i think in all cases they would be independent.

log.info("SSL is enabled on this MySQL connection. ");

// Server certificate verification is enabled by default
datasource.addConnectionProperty("verifyServerCertificate", String.valueOf(true));
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

we should have this configurable

|`druid.metadata.mysql.ssl.clientCertificateKeyStorePassword`|The [Password Provider](../operations/password-provider.html) or String password for the client key store.|none|no|
|`druid.metadata.mysql.ssl.enabledSSLCipherSuites`|Overrides the existing cipher suites with these cipher suites.|none|no|
|`druid.metadata.mysql.ssl.enabledTLSProtocols`|Overrides the TLS protocols with these protocols.|none|no|
|`druid.metadata.mysql.ssl.verifyServerCertificate`|Enables server certificate verification.|true|no|
Copy link
Copy Markdown
Contributor

@himanshug himanshug Dec 7, 2017

Choose a reason for hiding this comment

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

can you please specify configurations that don't remain mandatory when this is set to false.

@himanshug
Copy link
Copy Markdown
Contributor

👍

@himanshug himanshug added this to the 0.12.0 milestone Dec 18, 2017
Copy link
Copy Markdown
Member

@pjain1 pjain1 left a comment

Choose a reason for hiding this comment

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

Apart from the comments 👍

datasource.addConnectionProperty("verifyServerCertificate", String.valueOf(connectorConfig.isVerifyServerCertificate()));
if (connectorConfig.isVerifyServerCertificate()) {
log.info("Server certificate verification is enabled. ");
if (connectorConfig.getTrustCertificateKeyStoreUrl() != null) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Since this is required when verifyServerCertificate is set to true, what happens when user does not set this and it is null. Will there be some explicit exception/warning in the logs which would make it obvious for user what's the problem ? otherwise it would be better to explicitly check and throw exception.

Copy link
Copy Markdown
Contributor Author

@a2l007 a2l007 Jan 9, 2018

Choose a reason for hiding this comment

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

The user does receive a generic error message that the TrustManager was not configured correctly, but it does not tell them the reason was because it was null.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

According to the Mysql docs, the user can leave these properties as null, in which case the default values would be used. The password can also be set to null. In that case, I'm not sure if we need to enforce a null check here. I have clarified this in the documentation. Please review.

);
}
if (connectorConfig.getTrustCertificateKeyStoreType() != null) {
datasource.addConnectionProperty(
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

same as above

connectorConfig.getTrustCertificateKeyStoreType()
);
}
if (connectorConfig.getTrustCertificateKeyStorePassword() != null) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

same as above

@drcrallen
Copy link
Copy Markdown
Contributor

@a2l007 can this be finished up?

@himanshug
Copy link
Copy Markdown
Contributor

@drcrallen : @a2l007 is on vacation this week. this will be wrapped up next week. thanks for reviewing.

Copy link
Copy Markdown
Member

@pjain1 pjain1 left a comment

Choose a reason for hiding this comment

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

👍 after travis

@jon-wei jon-wei merged commit 3cc4a0a into apache:master Jan 10, 2018
jon-wei pushed a commit to jon-wei/druid that referenced this pull request Jan 10, 2018
* Encrypting MySQL connections

* Update docs

* Make verifyServerCertificate a configurable parameter

* Change password parameter and doc update

* Make server certificate verification disabled by default

* Update tostring

* Update docs

* Add check for trust store passwords

* Add warning for null password
himanshug pushed a commit that referenced this pull request Jan 10, 2018
* Encrypting MySQL connections

* Update docs

* Make verifyServerCertificate a configurable parameter

* Change password parameter and doc update

* Make server certificate verification disabled by default

* Update tostring

* Update docs

* Add check for trust store passwords

* Add warning for null password
@a2l007 a2l007 deleted the secure_mysql branch October 24, 2018 14:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants