Adding changes to generate jks file programatically to enable ssl/tls in hms#25313
Conversation
imjalpreet
left a comment
There was a problem hiding this comment.
@bibith4, please include the keystore validity information in the PR description.
Additionally, I was considering whether we could explore generating the keystore and truststore in memory. This could help eliminate the need for any refreshing in the future.
Let's wait for feedback from others in the community.
|
I agree with @imjalpreet, we need to avoid checking in the keystore entirely. |
d217c93 to
ef6021d
Compare
imjalpreet
left a comment
There was a problem hiding this comment.
Before starting the review, just a quick note: please exclude these tests from the presto-hive module’s test suite execution, as we have a dedicated suite to run them separately.
You can add the exclusion in the following section:
Lines 536 to 553 in f19fee9
5964162 to
64d6ad9
Compare
|
@imjalpreet @tdcmeehan added code to generate keystore and truststore programatically. Please check |
imjalpreet
left a comment
There was a problem hiding this comment.
Thank you, @bibith4. Let's try to make this utility generic.
There was a problem hiding this comment.
Let's try to make this class generic and move it to presto-plugin-toolkit so that we can reuse it across plugins.
There was a problem hiding this comment.
@imjalpreet moved the keystore file generation to presto-plugin-toolkit. Can you please check
bb28bb2 to
68637f1
Compare
68637f1 to
e614a79
Compare
agrawalreetika
left a comment
There was a problem hiding this comment.
Thanks for making the changes.
I have a question: since we’re making this generic, is the intention also that we’ll be using a single keystore/truststore instance per JVM as I see files & paths are static currenlty?
| // This is required when connecting to ssl enabled hms | ||
| .put("hive.metastore.thrift.client.tls.enabled", "true") | ||
| .put("hive.metastore.thrift.client.tls.keystore-path", Paths.get((TestHiveSslWithTrustStoreKeyStore.class.getResource("/hive_ssl_enable/hive-metastore.jks")).toURI()).toFile().toString()) | ||
| .put("hive.metastore.thrift.client.tls.keystore-path", SslKeystoreManager.getKeystorePath()) |
There was a problem hiding this comment.
@agrawalreetika Corrected . Please check.
| .put("hive.metastore.thrift.client.tls.keystore-path", SslKeystoreManager.getKeystorePath()) | ||
| .put("hive.metastore.thrift.client.tls.keystore-password", "123456") | ||
| .put("hive.metastore.thrift.client.tls.truststore-path", Paths.get((TestHiveSslWithTrustStoreKeyStore.class.getResource("/hive_ssl_enable/hive-metastore-truststore.jks")).toURI()).toFile().toString()) | ||
| .put("hive.metastore.thrift.client.tls.truststore-path", SslKeystoreManager.getTruststorePath()) |
There was a problem hiding this comment.
@agrawalreetika Corrected . Please check.
| // This is required when connecting to ssl enabled hms | ||
| .put("hive.metastore.thrift.client.tls.enabled", "true") | ||
| .put("hive.metastore.thrift.client.tls.truststore-path", Paths.get((TestHiveSslWithTrustStore.class.getResource("/hive_ssl_enable/hive-metastore-truststore.jks")).toURI()).toFile().toString()) | ||
| .put("hive.metastore.thrift.client.tls.truststore-path", SslKeystoreManager.getTruststorePath()) |
There was a problem hiding this comment.
@agrawalreetika Corrected . Please check.
| // This is required when connecting to ssl enabled hms | ||
| .put("hive.metastore.thrift.client.tls.enabled", "true") | ||
| .put("hive.metastore.thrift.client.tls.keystore-path", Paths.get((TestHiveSslWithKeyStore.class.getResource("/hive_ssl_enable/hive-metastore.jks")).toURI()).toFile().toString()) | ||
| .put("hive.metastore.thrift.client.tls.keystore-path", SslKeystoreManager.getKeystorePath()) |
There was a problem hiding this comment.
@agrawalreetika Corrected . Please check.
|
|
||
| AbstractHiveSslTest(Map<String, String> sslConfig) | ||
| { | ||
| SslKeystoreManager.initializeKeystore(); |
There was a problem hiding this comment.
@agrawalreetika Corrected . Please check.
| Path targetDir = Paths.get("target", "test-classes", "ssl_enable"); | ||
| Files.createDirectories(targetDir); | ||
|
|
||
| Path keyStoreTarget = targetDir.resolve("metastore.jks"); | ||
| Path trustStoreTarget = targetDir.resolve("metastore-truststore.jks"); | ||
|
|
||
| // Delete files if they exist | ||
| Files.deleteIfExists(keyStoreTarget); | ||
| Files.deleteIfExists(trustStoreTarget); | ||
|
|
||
| // Copy freshly generated keystores | ||
| Files.copy(keyStoreFile.toPath(), keyStoreTarget); | ||
| Files.copy(trustStoreFile.toPath(), trustStoreTarget); |
There was a problem hiding this comment.
What is the issue when we try to use SslKeystoreManager.getKeystorePath()?
There was a problem hiding this comment.
In any case, we should not use the class variables(keyStoreFile, trustStoreFile) directly. We should use getter methods.
There was a problem hiding this comment.
@imjalpreet If we use SslKeystoreManager.getKeystorePath(), the files will only exist on the filesystem and not in the test runtime classpath, which will cause classpath lookups to fail.
There was a problem hiding this comment.
Changed to use getter methods for keystore and truststore paths
| public static File keyStoreFile; | ||
| public static File trustStoreFile; |
There was a problem hiding this comment.
nit: let's make them private
| { | ||
| initializeKeystore(); | ||
| if (trustStoreFile == null || !trustStoreFile.exists()) { | ||
| throw new IllegalStateException("Keystore file is not initialized or missing"); |
There was a problem hiding this comment.
| throw new IllegalStateException("Keystore file is not initialized or missing"); | |
| throw new IllegalStateException("Truststore file is not initialized or missing"); |
There was a problem hiding this comment.
@agrawalreetika Corrected . Please check.
fa836e2 to
5e6d01f
Compare
@agrawalreetika Yes, SslKeystoreManager class is designed to use a single, static keystore and truststore instance per JVM |
| { | ||
| Security.addProvider(new BouncyCastleProvider()); | ||
|
|
||
| String alias = "metastore"; |
There was a problem hiding this comment.
Since this is gonna be used across multiple connector's ssl test so better to keep some gerric Alias here?
There was a problem hiding this comment.
Also since this is gonna be used for tests of different module, I think we should move it to presto-tests module instead?
There was a problem hiding this comment.
@agrawalreetika moved the jks file generation class to presto-test module and corrected alias. Please check
5e6d01f to
4144f6c
Compare
4144f6c to
4322a3c
Compare
cb5d86c to
4ea07c3
Compare
imjalpreet
left a comment
There was a problem hiding this comment.
Thanks, @bibith4.
LGTM % final few nits
| .put("hive.metastore.thrift.client.tls.enabled", "true") | ||
| .put("hive.metastore.thrift.client.tls.keystore-path", Paths.get((TestHiveSslWithKeyStore.class.getResource("/hive_ssl_enable/hive-metastore.jks")).toURI()).toFile().toString()) | ||
| .put("hive.metastore.thrift.client.tls.keystore-path", getKeystorePath()) | ||
| .put("hive.metastore.thrift.client.tls.keystore-password", "123456") |
There was a problem hiding this comment.
nit: let's create a static constant for the password in SslKeystoreManager and use it everywhere we are currently hardcoding the password.
There was a problem hiding this comment.
@imjalpreet Added static constant for the password. Please check
| { | ||
| } | ||
|
|
||
| public static synchronized void initializeKeystore() |
There was a problem hiding this comment.
nit: should we rename this to initializeKeystoreAndTruststore?
There was a problem hiding this comment.
Corrected. Please check
| <dependency> | ||
| <groupId>org.bouncycastle</groupId> | ||
| <artifactId>bcprov-jdk18on</artifactId> | ||
| <version>1.81</version> |
There was a problem hiding this comment.
nit: introduce a pom property for the version
There was a problem hiding this comment.
Corrected. Please check
| <exclusions> | ||
| <exclusion> | ||
| <groupId>org.bouncycastle</groupId> | ||
| <artifactId>bcpkix-jdk18on</artifactId> | ||
| </exclusion> | ||
| <exclusion> | ||
| <groupId>org.bouncycastle</groupId> | ||
| <artifactId>bcprov-jdk18on</artifactId> | ||
| </exclusion> | ||
| </exclusions> |
There was a problem hiding this comment.
I don't think this is required now
There was a problem hiding this comment.
Corrected. Please check
| <exclusions> | ||
| <exclusion> | ||
| <groupId>org.bouncycastle</groupId> | ||
| <artifactId>bcpkix-jdk18on</artifactId> | ||
| </exclusion> | ||
| <exclusion> | ||
| <groupId>org.bouncycastle</groupId> | ||
| <artifactId>bcprov-jdk18on</artifactId> | ||
| </exclusion> | ||
| </exclusions> |
There was a problem hiding this comment.
same here, not required anymore
There was a problem hiding this comment.
Corrected. Please check
| <exclusions> | ||
| <exclusion> | ||
| <groupId>org.bouncycastle</groupId> | ||
| <artifactId>bcpkix-jdk18on</artifactId> | ||
| </exclusion> | ||
| <exclusion> | ||
| <groupId>org.bouncycastle</groupId> | ||
| <artifactId>bcprov-jdk18on</artifactId> | ||
| </exclusion> | ||
| </exclusions> |
There was a problem hiding this comment.
Corrected. Please check
4ea07c3 to
c5bc8c3
Compare
c5bc8c3 to
c3be88c
Compare
imjalpreet
left a comment
There was a problem hiding this comment.
Thanks, @bibith4. LGTM now.
|
@tdcmeehan, this is ready for a final review, thanks! |
imjalpreet
left a comment
There was a problem hiding this comment.
@bibith4 one minor suggestion
| filesToMount.put("ssl_enable/keystore.jks", "/opt/hive/conf/hive-metastore.jks"); | ||
| filesToMount.put("ssl_enable/truststore.jks", "/opt/hive/conf/hive-metastore-truststore.jks"); |
There was a problem hiding this comment.
Sorry, one more suggestion, let's move these two mounts also inside the synchronized section to ensure there is no flakiness during concurrent test runs
c3be88c to
237d733
Compare
|
Please rebase to pick up the test failure fix |
237d733 to
984e5d5
Compare
984e5d5 to
5d62878
Compare
@tdcmeehan Corrected. Please check |
Description
Adding changes to generate jks file programatically to enable ssl/tls in hms.
Keystore validity

Motivation and Context
Impact
Fixes 25297
Test Plan
CI
Contributor checklist
Release Notes