-
Notifications
You must be signed in to change notification settings - Fork 285
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
Support certs with separate Extended Key Usage #493
Conversation
@lavacat Please check why CI build failed |
@@ -17,6 +17,7 @@ | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Currently the changes made are only for PEM certs. Since we support jks certs as well, we will probably need to extend these changes to include JKS certs (link)
SSLConfigConstants.OPENDISTRO_SECURITY_SSL_TRANSPORT_MIXED_KEY_USAGE_ENABLED_DEFAULT); | ||
// certificate allows clientAuth and serverAuth, use same cert | ||
SSLCertificateProps sslServerCertProps = sslCertProps; | ||
if (!mixedKeyUsageEnabled) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Slight confused by mixedKeyUsageEnabled
. Does that mean the cert has both clientAuth and serverAuth?
@@ -258,7 +258,7 @@ protected NodeSettingsSupplier minimumSecuritySettingsSslOnly(Settings other) { | |||
return new NodeSettingsSupplier() { | |||
@Override | |||
public Settings get(int i) { | |||
return minimumSecuritySettingsBuilder(i, true, false).put(other).build(); | |||
return minimumSecuritySettingsBuilder(i, true, true).put(other).build(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why update this from true
to false
? It is set to false by default so that custom transport settings are used.
src/main/java/com/amazon/opendistroforelasticsearch/security/ssl/util/SSLConfigConstants.java
Show resolved
Hide resolved
@@ -329,6 +329,12 @@ public Object run() { | |||
settings.add(Setting.simpleString(SSLConfigConstants.OPENDISTRO_SECURITY_SSL_TRANSPORT_PEMKEY_PASSWORD, Property.NodeScope, Property.Filtered)); | |||
settings.add(Setting.simpleString(SSLConfigConstants.OPENDISTRO_SECURITY_SSL_TRANSPORT_PEMTRUSTEDCAS_FILEPATH, Property.NodeScope, Property.Filtered)); | |||
|
|||
settings.add(Setting.boolSetting(SSLConfigConstants.OPENDISTRO_SECURITY_SSL_TRANSPORT_MIXED_KEY_USAGE_ENABLED, SSLConfigConstants.OPENDISTRO_SECURITY_SSL_TRANSPORT_MIXED_KEY_USAGE_ENABLED_DEFAULT, Property.NodeScope, Property.Filtered)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it may be good to disable these settings if mixedKeyUsage is false. Eg -
settings.add(Setting.boolSetting(SSLConfigConstants.OPENDISTRO_SECURITY_SSL_TRANSPORT_MIXED_KEY_USAGE_ENABLED, SSLConfigConstants.OPENDISTRO_SECURITY_SSL_TRANSPORT_MIXED_KEY_USAGE_ENABLED_DEFAULT, Property.NodeScope, Property.Filtered)); | |
if (!isMixedKeyUsageAllowed(settings)) { | |
settings.add(Setting.simpleString(SSLConfigConstants.OPENDISTRO_SECURITY_SSL_TRANSPORT_SERVER_PEMCERT_FILEPATH, Property.NodeScope, Property.Filtered)); | |
settings.add(Setting.simpleString(SSLConfigConstants.OPENDISTRO_SECURITY_SSL_TRANSPORT_SERVER_PEMKEY_FILEPATH, Property.NodeScope, Property.Filtered)); | |
settings.add(Setting.simpleString(SSLConfigConstants.OPENDISTRO_SECURITY_SSL_TRANSPORT_SERVER_PEMKEY_PASSWORD, Property.NodeScope, Property.Filtered)); | |
settings.add(Setting.simpleString(SSLConfigConstants.OPENDISTRO_SECURITY_SSL_TRANSPORT_SERVER_PEMTRUSTEDCAS_FILEPATH, Property.NodeScope, Property.Filtered)); | |
} |
You can create a helper function like -
private static boolean isMixedKeyUsageAllowed(final Settings settings) {
return settings.getAsBoolean(SSLConfigConstants. OPENDISTRO_SECURITY_SSL_TRANSPORT_MIXED_KEY_USAGE_ENABLED, false);
}
@debjanibnrj Thanks for comments. I'll resume working on this.
|
Codecov Report
@@ Coverage Diff @@
## master #493 +/- ##
============================================
+ Coverage 63.91% 64.27% +0.36%
- Complexity 3169 3210 +41
============================================
Files 239 244 +5
Lines 16882 17040 +158
Branches 3036 3034 -2
============================================
+ Hits 10790 10953 +163
+ Misses 4543 4541 -2
+ Partials 1549 1546 -3
Continue to review full report at Codecov.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great to me! Thanks for making these changes.
@@ -0,0 +1,22 @@ | |||
# Commands to generate certs in this folder |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for adding this!
...va/com/amazon/opendistroforelasticsearch/security/ssl/DefaultOpenDistroSecurityKeyStore.java
Outdated
Show resolved
Hide resolved
...ain/java/com/amazon/opendistroforelasticsearch/security/ssl/OpenDistroSecuritySSLPlugin.java
Show resolved
Hide resolved
|
||
} else if (rawPemCertFilePath != null || extendedKeyUsageEnabled) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why add || extendedKeyUsageEnabled
here?
KeystoreProps truststoreProps = new KeystoreProps( | ||
truststoreFilePath, truststoreType, truststorePassword); | ||
try { | ||
CertFromKeystore certFromKeystore; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for refactoring these into classes. Much cleaner approach. 👍
...va/com/amazon/opendistroforelasticsearch/security/ssl/DefaultOpenDistroSecurityKeyStore.java
Show resolved
Hide resolved
...ain/java/com/amazon/opendistroforelasticsearch/security/ssl/OpenDistroSecuritySSLPlugin.java
Show resolved
Hide resolved
src/main/java/com/amazon/opendistroforelasticsearch/security/ssl/util/CertFromKeystore.java
Outdated
Show resolved
Hide resolved
src/main/java/com/amazon/opendistroforelasticsearch/security/ssl/util/CertFromKeystore.java
Outdated
Show resolved
Hide resolved
@debjanibnrj based on your question "Why add || extendedKeyUsageEnabled here?" Nothing else changed |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for your contribution. Added a minor comment but overall looks great!
@hardik-k-shah can you have a look as well |
@debjanibnrj FYI, don't see the new comments. I think I've addressed all older ones. |
...va/com/amazon/opendistroforelasticsearch/security/ssl/DefaultOpenDistroSecurityKeyStore.java
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
...va/com/amazon/opendistroforelasticsearch/security/ssl/DefaultOpenDistroSecurityKeyStore.java
Outdated
Show resolved
Hide resolved
...va/com/amazon/opendistroforelasticsearch/security/ssl/DefaultOpenDistroSecurityKeyStore.java
Outdated
Show resolved
Hide resolved
null); | ||
final String keyPassword = settings.get(SSLConfigConstants.OPENDISTRO_SECURITY_SSL_TRANSPORT_KEYSTORE_KEYPASSWORD, | ||
keystorePassword); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should we also check truststoreAlias and keystoreAlias for non-null and throw exception if anyone of it was set to null?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the alias isn't provided SSLCertificateHelper.exportServerCertChain will take the first one. I've made it required for extended key usage because server/client alias should be different at least for keystore.
Made a comment and added a test
src/test/java/com/amazon/opendistroforelasticsearch/security/ssl/util/CertFromFileTests.java
Show resolved
Hide resolved
@debjanibnrj @hardik-k-shah thanks for comments and noticing those mistakes, made all changes as you've suggested. |
Problem: Right now certs that specify extended key usage must set both clientAuth and serverAuth. Solution: Add settings to path additional server cert and use it when creating ssl server
Problem: Right now certs that specify extended key usage must set both clientAuth and serverAuth. Solution: Add settings to path additional server cert and use it when creating ssl server Co-authored-by: Bogdan Kanivets <bkanivets@twitter.com>
Problem: Right now certs that specify extended key usage must set both clientAuth and serverAuth. Solution: Add settings to path additional server cert and use it when creating ssl server Co-authored-by: Bogdan Kanivets <bkanivets@twitter.com>
Problem: Right now certs that specify extended key usage must set
both clientAuth and serverAuth.
Solution: Add settings to path additional server cert and use it when
creating ssl server
*Issue #474 *
Description of changes:
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.