Skip to content

Adding changes to generate jks file programatically to enable ssl/tls in hms#25313

Merged
tdcmeehan merged 1 commit into
prestodb:masterfrom
bibith4:fix_hive_ssl_tls_keystore_expiry
Sep 30, 2025
Merged

Adding changes to generate jks file programatically to enable ssl/tls in hms#25313
tdcmeehan merged 1 commit into
prestodb:masterfrom
bibith4:fix_hive_ssl_tls_keystore_expiry

Conversation

@bibith4

@bibith4 bibith4 commented Jun 13, 2025

Copy link
Copy Markdown
Contributor

Description

Adding changes to generate jks file programatically to enable ssl/tls in hms.

Keystore validity
Screenshot 2025-06-19 at 5 36 28 PM

Motivation and Context

Impact

Fixes 25297

Test Plan

CI

Contributor checklist

  • Please make sure your submission complies with our contributing guide, in particular code style and commit standards.
  • PR description addresses the issue accurately and concisely. If the change is non-trivial, a GitHub Issue is referenced.
  • Documented new properties (with its default value), SQL syntax, functions, or other functionality.
  • If release notes are required, they follow the release notes guidelines.
  • Adequate tests were added if applicable.
  • CI passed.

Release Notes

== NO RELEASE NOTE ==

@prestodb-ci prestodb-ci added the from:IBM PR from IBM label Jun 13, 2025

@imjalpreet imjalpreet left a comment

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.

@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.

@tdcmeehan

Copy link
Copy Markdown
Contributor

I agree with @imjalpreet, we need to avoid checking in the keystore entirely.

@bibith4 bibith4 force-pushed the fix_hive_ssl_tls_keystore_expiry branch 3 times, most recently from d217c93 to ef6021d Compare June 18, 2025 05:44

@imjalpreet imjalpreet left a comment

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.

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:

presto/presto-hive/pom.xml

Lines 536 to 553 in f19fee9

<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<excludes>
<!-- Exclude tests against Glue from build -->
<exclude>**/TestHiveClientGlueMetastore.java</exclude>
<exclude>**/TestHiveDistributedAggregationsWithExchangeMaterialization.java</exclude>
<exclude>**/TestHiveDistributedQueriesWithExchangeMaterialization.java</exclude>
<exclude>**/TestHiveDistributedQueriesWithOptimizedRepartitioning.java</exclude>
<exclude>**/TestHiveRecoverableExecution.java</exclude>
<exclude>**/TestHivePushdownFilterQueries.java</exclude>
<exclude>**/TestHivePushdownIntegrationSmokeTest.java</exclude>
<exclude>**/TestHivePushdownDistributedQueries.java</exclude>
<exclude>**/TestParquetDistributedQueries.java</exclude>
<exclude>**/TestHive2InsertOverwrite.java</exclude>
<exclude>**/TestHive3InsertOverwrite.java</exclude>
</excludes>
</configuration>

@bibith4 bibith4 force-pushed the fix_hive_ssl_tls_keystore_expiry branch 2 times, most recently from 5964162 to 64d6ad9 Compare June 19, 2025 06:47
@bibith4

bibith4 commented Jun 19, 2025

Copy link
Copy Markdown
Contributor Author

@imjalpreet @tdcmeehan added code to generate keystore and truststore programatically. Please check

@bibith4 bibith4 marked this pull request as ready for review June 19, 2025 11:13
@bibith4 bibith4 requested a review from a team as a code owner June 19, 2025 11:13
@bibith4 bibith4 requested a review from ZacBlanco June 19, 2025 11:13
@prestodb-ci prestodb-ci requested review from a team, pdabre12 and sh-shamsan and removed request for a team June 19, 2025 11:13
@bibith4 bibith4 changed the title Adding new keystore files with extended validity for Hive tests using SSL/TLS Adding changes to generate jks file programatically to enable ssl/tls in hms Jun 19, 2025

@imjalpreet imjalpreet left a comment

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.

Thank you, @bibith4. Let's try to make this utility generic.

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.

Let's try to make this class generic and move it to presto-plugin-toolkit so that we can reuse it across plugins.

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.

@imjalpreet moved the keystore file generation to presto-plugin-toolkit. Can you please check

@bibith4 bibith4 force-pushed the fix_hive_ssl_tls_keystore_expiry branch 2 times, most recently from bb28bb2 to 68637f1 Compare September 2, 2025 07:31
@bibith4 bibith4 force-pushed the fix_hive_ssl_tls_keystore_expiry branch from 68637f1 to e614a79 Compare September 2, 2025 08:30
@bibith4 bibith4 requested a review from imjalpreet September 2, 2025 09:46

@agrawalreetika agrawalreetika left a comment

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.

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())

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.

use static import

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.

@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())

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.

use static import

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.

@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())

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.

use static import

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.

@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())

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.

use static import

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.

@agrawalreetika Corrected . Please check.


AbstractHiveSslTest(Map<String, String> sslConfig)
{
SslKeystoreManager.initializeKeystore();

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.

use static import

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.

@agrawalreetika Corrected . Please check.

@imjalpreet imjalpreet left a comment

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.

Thanks, @bibith4.

Comment on lines +87 to +99
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);

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.

What is the issue when we try to use SslKeystoreManager.getKeystorePath()?

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.

In any case, we should not use the class variables(keyStoreFile, trustStoreFile) directly. We should use getter methods.

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.

@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.

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.

Changed to use getter methods for keystore and truststore paths

Comment on lines +49 to +50
public static File keyStoreFile;
public static File trustStoreFile;

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.

nit: let's make them private

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.

@imjalpreet Corrected . Please check.

{
initializeKeystore();
if (trustStoreFile == null || !trustStoreFile.exists()) {
throw new IllegalStateException("Keystore file is not initialized or missing");

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.

Suggested change
throw new IllegalStateException("Keystore file is not initialized or missing");
throw new IllegalStateException("Truststore file is not initialized or missing");

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.

@agrawalreetika Corrected . Please check.

@bibith4 bibith4 force-pushed the fix_hive_ssl_tls_keystore_expiry branch 2 times, most recently from fa836e2 to 5e6d01f Compare September 22, 2025 09:08
@bibith4

bibith4 commented Sep 22, 2025

Copy link
Copy Markdown
Contributor Author

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?

@agrawalreetika Yes, SslKeystoreManager class is designed to use a single, static keystore and truststore instance per JVM

{
Security.addProvider(new BouncyCastleProvider());

String alias = "metastore";

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 gonna be used across multiple connector's ssl test so better to keep some gerric Alias here?

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.

Also since this is gonna be used for tests of different module, I think we should move it to presto-tests module instead?

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.

@agrawalreetika moved the jks file generation class to presto-test module and corrected alias. Please check

@bibith4 bibith4 force-pushed the fix_hive_ssl_tls_keystore_expiry branch from 5e6d01f to 4144f6c Compare September 24, 2025 10:41
@bibith4 bibith4 force-pushed the fix_hive_ssl_tls_keystore_expiry branch from 4144f6c to 4322a3c Compare September 24, 2025 12:28
@bibith4 bibith4 force-pushed the fix_hive_ssl_tls_keystore_expiry branch 2 times, most recently from cb5d86c to 4ea07c3 Compare September 24, 2025 13:07
agrawalreetika
agrawalreetika previously approved these changes Sep 25, 2025

@agrawalreetika agrawalreetika left a comment

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.

LGTM

@imjalpreet imjalpreet left a comment

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.

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")

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.

nit: let's create a static constant for the password in SslKeystoreManager and use it everywhere we are currently hardcoding the password.

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.

@imjalpreet Added static constant for the password. Please check

{
}

public static synchronized void initializeKeystore()

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.

nit: should we rename this to initializeKeystoreAndTruststore?

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.

Corrected. Please check

Comment thread presto-tests/pom.xml Outdated
<dependency>
<groupId>org.bouncycastle</groupId>
<artifactId>bcprov-jdk18on</artifactId>
<version>1.81</version>

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.

nit: introduce a pom property for the version

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.

Corrected. Please check

Comment thread presto-main-base/pom.xml Outdated
Comment on lines +428 to +437
<exclusions>
<exclusion>
<groupId>org.bouncycastle</groupId>
<artifactId>bcpkix-jdk18on</artifactId>
</exclusion>
<exclusion>
<groupId>org.bouncycastle</groupId>
<artifactId>bcprov-jdk18on</artifactId>
</exclusion>
</exclusions>

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.

I don't think this is required now

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.

Corrected. Please check

Comment thread presto-iceberg/pom.xml Outdated
Comment on lines +145 to +154
<exclusions>
<exclusion>
<groupId>org.bouncycastle</groupId>
<artifactId>bcpkix-jdk18on</artifactId>
</exclusion>
<exclusion>
<groupId>org.bouncycastle</groupId>
<artifactId>bcprov-jdk18on</artifactId>
</exclusion>
</exclusions>

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 here, not required anymore

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.

Corrected. Please check

Comment thread presto-hive/pom.xml Outdated
Comment on lines +56 to +65
<exclusions>
<exclusion>
<groupId>org.bouncycastle</groupId>
<artifactId>bcpkix-jdk18on</artifactId>
</exclusion>
<exclusion>
<groupId>org.bouncycastle</groupId>
<artifactId>bcprov-jdk18on</artifactId>
</exclusion>
</exclusions>

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 here

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.

Corrected. Please check

@bibith4 bibith4 force-pushed the fix_hive_ssl_tls_keystore_expiry branch from 4ea07c3 to c5bc8c3 Compare September 25, 2025 06:12
@bibith4 bibith4 force-pushed the fix_hive_ssl_tls_keystore_expiry branch from c5bc8c3 to c3be88c Compare September 25, 2025 06:54
imjalpreet
imjalpreet previously approved these changes Sep 25, 2025

@imjalpreet imjalpreet left a comment

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.

Thanks, @bibith4. LGTM now.

@imjalpreet

Copy link
Copy Markdown
Member

@tdcmeehan, this is ready for a final review, thanks!

@imjalpreet imjalpreet left a comment

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.

@bibith4 one minor suggestion

Comment on lines +104 to +105
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");

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.

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

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.

@imjalpreet Corrected. Please check

@imjalpreet imjalpreet left a comment

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.

Thank you, @bibith4.

@tdcmeehan

Copy link
Copy Markdown
Contributor

Please rebase to pick up the test failure fix

@bibith4 bibith4 force-pushed the fix_hive_ssl_tls_keystore_expiry branch from 237d733 to 984e5d5 Compare September 29, 2025 11:59
@bibith4 bibith4 force-pushed the fix_hive_ssl_tls_keystore_expiry branch from 984e5d5 to 5d62878 Compare September 29, 2025 13:56
@bibith4

bibith4 commented Sep 30, 2025

Copy link
Copy Markdown
Contributor Author

Please rebase to pick up the test failure fix

@tdcmeehan Corrected. Please check

@tdcmeehan tdcmeehan merged commit 7c85a98 into prestodb:master Sep 30, 2025
95 of 100 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

from:IBM PR from IBM

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Hive tests using SSL/TLS fail with an expired keystore

5 participants