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

Changes to enable ssl/tls in hms #24745

Merged
merged 1 commit into from
Apr 7, 2025

Conversation

bibith4
Copy link
Contributor

@bibith4 bibith4 commented Mar 18, 2025

Description

Added SSL/TLS support for hive metastore

Impact

The connection to HMS will be encrypted with TLS for secure communication.

Test Plan

Executed basic queries after enabling TLS in HMS.
Queries got executed successfully.
Screenshot 2025-03-19 at 11 54 15 AM

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

Please follow release notes guidelines and fill in the release notes below.

== RELEASE NOTES ==

Hive Connector Changes
* Add changes to enable SSL/TLS encryption by accepting the following configuration properties:

    * ``hive.metastore.thrift.client.tls.enabled``
    * ``hive.metastore.thrift.client.tls.keystore-path``
    * ``hive.metastore.thrift.client.tls.keystore-password``
    * ``hive.metastore.thrift.client.tls.truststore-path``
    * ``hive.metastore.thrift.client.tls.truststore-password``

@prestodb-ci prestodb-ci added the from:IBM PR from IBM label Mar 18, 2025
Copy link

linux-foundation-easycla bot commented Mar 18, 2025

CLA Signed

The committers listed above are authorized under a signed CLA.

@bibith4 bibith4 force-pushed the ssl_tls_support_for_hms branch 3 times, most recently from 93d3e50 to 237591e Compare March 18, 2025 15:20
@bibith4 bibith4 marked this pull request as ready for review March 19, 2025 06:25
@bibith4 bibith4 requested review from czentgr, a team, steveburnett and elharo as code owners March 19, 2025 06:25
@bibith4 bibith4 requested a review from jaystarshot March 19, 2025 06:25
@prestodb-ci prestodb-ci requested review from a team and jp-sivaprasad and removed request for a team March 19, 2025 06:25
Copy link
Contributor

@steveburnett steveburnett left a comment

Choose a reason for hiding this comment

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

Please fix the formatting of the table in lines 216-245. A local doc build doesn't show the table. See screenshot.
Screenshot 2025-03-19 at 9 10 50 AM

Tag me to request a review after the table is restored and I'll be happy to review this again.

@bibith4 bibith4 force-pushed the ssl_tls_support_for_hms branch 4 times, most recently from 2e8df56 to cf2e4dc Compare March 20, 2025 09:58
Copy link
Contributor

@steveburnett steveburnett left a comment

Choose a reason for hiding this comment

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

Nit of formatting in the Metastore Configuration Properties table.

@bibith4 bibith4 requested a review from steveburnett March 20, 2025 14:08
@bibith4 bibith4 force-pushed the ssl_tls_support_for_hms branch from dd36298 to a62601e Compare March 20, 2025 14:10
Copy link
Contributor

@steveburnett steveburnett left a comment

Choose a reason for hiding this comment

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

Just one nit of formatting in the text, looks good other than that. Thanks for the quick turnaround!

@bibith4 bibith4 force-pushed the ssl_tls_support_for_hms branch from 9ebeb22 to 577afe2 Compare March 20, 2025 15:36
steveburnett
steveburnett previously approved these changes Mar 20, 2025
Copy link
Contributor

@steveburnett steveburnett left a comment

Choose a reason for hiding this comment

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

LGTM! (docs)

Pull updated branch, new local doc build, looks good.

Thanks for the doc!

@bibith4 bibith4 requested a review from agrawalreetika March 20, 2025 16:46
private File metastoreTlsKeystorePath;
private String metastoreTlsKeystorePassword;
private File metastoreTlsTruststorePath;
private String metastoreTlsTruststorePassword;
Copy link
Member

Choose a reason for hiding this comment

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

Since these are already metastore configs, I think we can shorten these variable and call it like in other SSL enabled class -

    private boolean tlsEnabled;
    private File keystorePath;
    private String keystorePassword;
    private File truststorePath;
    private String trustStorePassword;

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@agrawalreetika Changed as per the suggestion. Please check

* @param metastoreTrustStorePassword
* @return SSLContext
*/
private static Optional<SSLContext> metastoreSslContext(boolean metastoreTlsEnabled, Optional<File> metastoreKeyStorePath, Optional<String> metastoreKeyStorePassword, Optional<File> metastoreTrustStorePath, Optional<String> metastoreTrustStorePassword)
Copy link
Member

Choose a reason for hiding this comment

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

We can call this method something like - buildSslContext

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@agrawalreetika Changed as per the suggestion. Please check

*/
private static Optional<SSLContext> metastoreSslContext(boolean metastoreTlsEnabled, Optional<File> metastoreKeyStorePath, Optional<String> metastoreKeyStorePassword, Optional<File> metastoreTrustStorePath, Optional<String> metastoreTrustStorePassword)
{
if (!metastoreTlsEnabled || (!metastoreKeyStorePath.isPresent() && !metastoreTrustStorePath.isPresent())) {
Copy link
Member

Choose a reason for hiding this comment

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

I think we can simply this here -

Suggested change
if (!metastoreTlsEnabled || (!metastoreKeyStorePath.isPresent() && !metastoreTrustStorePath.isPresent())) {
if (!metastoreTlsEnabled || (metastoreKeyStorePath.isEmpty() && metastoreTrustStorePath.isEmpty()) {

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@agrawalreetika Optional#isEmpty() is a Java 11 method. Not available in java 8

// get X509TrustManager
final TrustManager[] trustManagers = trustManagerFactory.getTrustManagers();
if (trustManagers.length != 1 || !(trustManagers[0] instanceof X509TrustManager)) {
throw new RuntimeException("Unexpected default trust managers:" + Arrays.toString(trustManagers));
Copy link
Member

Choose a reason for hiding this comment

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

This could be more clear here based on the condition here -

Suggested change
throw new RuntimeException("Unexpected default trust managers:" + Arrays.toString(trustManagers));
throw new RuntimeException("Expected exactly one X509TrustManager, but found: " + Arrays.toString(trustManagers));
;

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@agrawalreetika Changed as per the suggestion. Please check

testTable));
computeActual(format("INSERT INTO %s values(1, 'TestName1')", testTable));
computeActual(format("INSERT INTO %s values(1, 'TestName2')", testTable));
assertQuery(format("SELECT count(*) FROM %s", testTable), "SELECT 2");
Copy link
Member

Choose a reason for hiding this comment

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

Add one more assert for checking the expected SELECT * values from a table

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@agrawalreetika added assert for select * also

computeActual(format("INSERT INTO %s values(1, 'TestName1')", testTable));
computeActual(format("INSERT INTO %s values(1, 'TestName2')", testTable));
assertQuery(format("SELECT count(*) FROM %s", testTable), "SELECT 2");
}
Copy link
Member

@agrawalreetika agrawalreetika Mar 23, 2025

Choose a reason for hiding this comment

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

We could add some more combinations of test and provide different combination of sslConfigurations in queryRunner -

  1. When just truststore is set
  2. When just keystore is set
  3. When both truststore + keystore is set

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@agrawalreetika added test cases with all the above mentioned connfigurations

agrawalreetika
agrawalreetika previously approved these changes Mar 26, 2025
Copy link
Member

@agrawalreetika agrawalreetika left a comment

Choose a reason for hiding this comment

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

LGTM, Thanks for adding the support

Please plan to squash your commits into one with relevant commit message.

@bibith4 bibith4 force-pushed the ssl_tls_support_for_hms branch 2 times, most recently from d92d49d to e794b25 Compare March 26, 2025 18:56
@bibith4
Copy link
Contributor Author

bibith4 commented Mar 26, 2025

LGTM, Thanks for adding the support

Please plan to squash your commits into one with relevant commit message.

Done

@bibith4 bibith4 requested a review from yingsu00 March 26, 2025 19:01
@@ -232,7 +232,17 @@ Property Name Descriptio
``hive.invalidate-metastore-cache-procedure-enabled`` When enabled, users will be able to invalidate metastore false
cache on demand.

======================================================= ============================================================= ============
``hive.metastore.thrift.client.tls.enabled`` Whether TLS security is enabled. false
Copy link
Contributor

Choose a reason for hiding this comment

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

The release notes shall show these property names. E.g. "Add a configuration property plan-checker.config-dir to set the configuration directory for PlanCheckerProvider configurations. #23955"

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@yingsu00 Updated release notes with newly added properties

@@ -232,7 +232,17 @@ Property Name Descriptio
``hive.invalidate-metastore-cache-procedure-enabled`` When enabled, users will be able to invalidate metastore false
cache on demand.

======================================================= ============================================================= ============
``hive.metastore.thrift.client.tls.enabled`` Whether TLS security is enabled. false
Copy link
Contributor

Choose a reason for hiding this comment

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

Why are they all dot separated?

Copy link
Member

Choose a reason for hiding this comment

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

I think we can follow the similar config naming like other connectors with TLS configs -
https://prestodb.io/docs/current/connector/elasticsearch.html#tls-security

.keystore.path -> .keystore-path
.keystore.password -> .keystore-password
.truststore.path -> .truststore-path
.truststore.password -> .truststore-password

WDYT @yingsu00?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@agrawalreetika @yingsu00 existing properties specified in below format
hive.metastore-thrift-client-tls-enabled
Can we follow the same ?

Copy link
Contributor

Choose a reason for hiding this comment

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

@agrawalreetika @yingsu00 existing properties specified in below format hive.metastore-thrift-client-tls-enabled Can we follow the same ?

Please see my comments inline.

Copy link
Contributor Author

@bibith4 bibith4 Apr 1, 2025

Choose a reason for hiding this comment

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

@yingsu00 Changed as per the suggestion

@@ -49,12 +72,138 @@ public HiveMetastoreClientFactory(
@Inject
public HiveMetastoreClientFactory(MetastoreClientConfig metastoreClientConfig, HiveMetastoreAuthentication metastoreAuthentication)
{
this(Optional.empty(), Optional.ofNullable(metastoreClientConfig.getMetastoreSocksProxy()), metastoreClientConfig.getMetastoreTimeout(), metastoreAuthentication);
this(buildSslContext(metastoreClientConfig.isTlsEnabled(), Optional.ofNullable(metastoreClientConfig.getKeystorePath()), Optional.ofNullable(metastoreClientConfig.getKeystorePassword()), Optional.ofNullable(metastoreClientConfig.getTruststorePath()), Optional.ofNullable(metastoreClientConfig.getTrustStorePassword())), Optional.ofNullable(metastoreClientConfig.getMetastoreSocksProxy()), metastoreClientConfig.getMetastoreTimeout(), metastoreAuthentication);
Copy link
Contributor

Choose a reason for hiding this comment

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

Line too long. Put each parameter on a separate line

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@yingsu00 Updated it by adding parameters in separate lines

* @param trustStorePassword
* @return SSLContext
*/
private static Optional<SSLContext> buildSslContext(boolean tlsEnabled, Optional<File> keystorePath, Optional<String> keystorePassword, Optional<File> truststorePath, Optional<String> trustStorePassword)
Copy link
Contributor

Choose a reason for hiding this comment

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

Line too long. Put each parameter on a separate line

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@yingsu00 Updated it by adding parameters in separate lines

@@ -317,4 +324,60 @@ public MetastoreClientConfig setInvalidateMetastoreCacheProcedureEnabled(boolean
this.invalidateMetastoreCacheProcedureEnabled = invalidateMetastoreCacheProcedureEnabled;
return this;
}

@Config("hive.metastore.thrift.client.tls.enabled")
Copy link
Contributor

Choose a reason for hiding this comment

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

these config properties are specific to the thrift metastore, and they are all used by com/facebook/presto/hive/metastore/thrift/HiveMetastoreClientFactory.java. I think we should create a separate config class under com/facebook/presto/hive/metastore/thrift/. We can name it as ThriftHiveMetastoreConfig.java. All config properties in it shall start with hive.metastore.thrift.

Copy link
Contributor

Choose a reason for hiding this comment

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

I'd suggest we name these new config properties prefix in ThriftHiveMetastoreConfig.java hive.metastore.thrift.client.tls.xxx. e.g.
hive.metastore.thrift.client.tls.enabled
hive.metastore.thrift.client.tls.keystore-path
"hive.metastore.thrift.client.tls.keystore-password...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@yingsu00 created a separate class 'ThriftHiveMetastoreConfig' and moved all the ssl related properties to that

private String keystorePassword;
private File truststorePath;
private String trustStorePassword;

Copy link
Contributor

Choose a reason for hiding this comment

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

This comment is for line 64-74
Move it to the new com/facebook/presto/hive/metastore/thrift/ThriftHiveMetastoreConfig.java

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@yingsu00 when checked i could see that moving this field require changes in many files. Can we do that as a seperate follow-up PR?
cc : @agrawalreetika @imjalpreet

public String getTrustStorePassword()
{
return trustStorePassword;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

This comment is for line 302 to 314
Move "hive.metastore.thrift.delete-files-on-table-drop" to the new com/facebook/presto/hive/metastore/thrift/ThriftHiveMetastoreConfig.java

I'm not sure if this is only for the thrift client? If it is then it's better to rename it to "hive.metastore.thrift.client.delete-files-on-table-drop" and deprecate "hive.metastore.thrift.delete-files-on-table-drop". I think it is not. @imjalpreet Could you please confirm?

Copy link
Member

Choose a reason for hiding this comment

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

Yes, we can move this to the ThriftHiveMetastoreConfig. The config is only valid when Thrift Hive Metastore is used as the metastore in Hive connector due to a limitation observed a few years back: #17369

Copy link
Contributor Author

@bibith4 bibith4 Apr 1, 2025

Choose a reason for hiding this comment

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

@yingsu00 when checked i could see that moving this field require changes in many files. Can we do that as a seperate follow-up PR?
cc : @agrawalreetika @imjalpreet

@ethanyzhang
Copy link
Contributor

@bibith4 can you fix the CLA check? also the failing test

@bibith4 bibith4 force-pushed the ssl_tls_support_for_hms branch 3 times, most recently from 64e2a10 to bcc1294 Compare April 1, 2025 07:41
Co-authored-by: Arin Mathew <[email protected]>

Changes to move ssl related properties to seperate class
@bibith4 bibith4 force-pushed the ssl_tls_support_for_hms branch from 60d92c5 to 693c872 Compare April 1, 2025 13:31
@bibith4
Copy link
Contributor Author

bibith4 commented Apr 1, 2025

@bibith4 can you fix the CLA check? also the failing test

@ethanyzhang Corrected. Please check

@steveburnett
Copy link
Contributor

Thanks for the release note entry! Some suggestions for formatting and to follow the Order of changes in the Release Notes Guidelines:

== RELEASE NOTES ==

General Changes
* Add changes to accept SSL/TLS properties to enable encryption.
* Add configuration properties for SSL/TLS:

    * ``hive.metastore.thrift.client.tls.enabled``
    * ``hive.metastore.thrift.client.tls.keystore-path``
    * ``hive.metastore.thrift.client.tls.keystore-password``
    * ``hive.metastore.thrift.client.tls.truststore-path``
    * ``hive.metastore.thrift.client.tls.truststore-password``
      
Hive Connector Changes
* Improve hive-site.xml to allow configuration of SSL/TLS properties.

Copy link
Contributor

@steveburnett steveburnett left a comment

Choose a reason for hiding this comment

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

LGTM! (docs)

Pull branch, local doc build. Thanks!

Copy link
Contributor

@yingsu00 yingsu00 left a comment

Choose a reason for hiding this comment

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

The release note should only have Hive Connector changes. Could you please move them? Also cc @steveburnett for a second round of the release note section review

@bibith4
Copy link
Contributor Author

bibith4 commented Apr 2, 2025

The release note should only have Hive Connector changes. Could you please move them? Also cc @steveburnett for a second round of the release note section review

@yingsu00 changed release note as per suggestion. @steveburnett Can you please verify

Copy link
Member

@agrawalreetika agrawalreetika left a comment

Choose a reason for hiding this comment

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

Code changes, LGTM

@steveburnett
Copy link
Contributor

The release note should only have Hive Connector changes. Could you please move them? Also cc @steveburnett for a second round of the release note section review

@yingsu00 changed release note as per suggestion. @steveburnett Can you please verify

Yes, verified. Thank you!

@yingsu00
Copy link
Contributor

yingsu00 commented Apr 3, 2025

@bibith4 Could you please squash the 3 bullet points of the release notes into one? The second bullet point can be removed.

@bibith4
Copy link
Contributor Author

bibith4 commented Apr 3, 2025

@bibith4 Could you please squash the 3 bullet points of the release notes into one? The second bullet point can be removed.

@yingsu00 Changed release note as per the suggestion. Can you please check

@bibith4 bibith4 requested a review from yingsu00 April 3, 2025 16:36
@yingsu00 yingsu00 merged commit 832aefb into prestodb:master Apr 7, 2025
98 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.

7 participants