feat(plugin-mongodb): TLS configuration support in MongoClientConfig#25374
feat(plugin-mongodb): TLS configuration support in MongoClientConfig#25374imjalpreet merged 1 commit intoprestodb:masterfrom
Conversation
|
@ethanyzhang imported this issue as lakehouse/presto #25374 |
agrawalreetika
left a comment
There was a problem hiding this comment.
Please add required documentation entries with the new configs in Mongo connector documentation.
presto-mongodb/src/main/java/com/facebook/presto/mongodb/MongoClientConfig.java
Outdated
Show resolved
Hide resolved
| implements Module | ||
| { | ||
| private static final Logger log = Logger.get(MongoClientModule.class); | ||
| public static final String PROTOCOL = "SSL"; |
There was a problem hiding this comment.
Would it be better to enhance Security Protocol to TLS?
presto-mongodb/src/main/java/com/facebook/presto/mongodb/MongoClientModule.java
Outdated
Show resolved
Hide resolved
| } | ||
| validateCertificates(keystore); | ||
| KeyManagerFactory keyManagerFactory = | ||
| KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm()); |
There was a problem hiding this comment.
Same here use static import
| return true; | ||
| } | ||
|
|
||
| public boolean getTlsEnabled() |
There was a problem hiding this comment.
| public boolean getTlsEnabled() | |
| public boolean isTlsEnabled() |
presto-mongodb/src/main/java/com/facebook/presto/mongodb/MongoClientModule.java
Show resolved
Hide resolved
presto-mongodb/src/test/java/com/facebook/presto/mongodb/TestMongoClientConfig.java
Outdated
Show resolved
Hide resolved
|
|
||
| /** | ||
| * @deprecated Use {@link #isTlsEnabled()} instead. This method is kept for backward compatibility. | ||
| */ |
There was a problem hiding this comment.
Little confused, What backward compatibility is being enforced with this method now if you are already pointing @LegacyConfig("mongodb.ssl.enabled")? Do we still need this?
There was a problem hiding this comment.
You're absolutely right. Since we're using @LegacyConfig("mongodb.ssl.enabled") on the setTlsEnabled() method, the old SSL configuration will automatically be routed to the new TLS configuration. I will remove the deprecated methods.
| { | ||
| return this.sslEnabled; | ||
| return this.tlsEnabled; | ||
| } |
presto-spi/src/main/java/com/facebook/presto/spi/security/SslContextProvider.java
Show resolved
Hide resolved
| return trustStore; | ||
| } | ||
|
|
||
| public static void validateCertificates(KeyStore keyStore) throws GeneralSecurityException |
| return (X509TrustManager) trustManagers[0]; | ||
| } | ||
|
|
||
| public static KeyStore loadTrustStore(File trustStorePath, Optional<String> trustStorePassword) |
| Optional<SSLContext> sslContext = sslContextProvider.buildSslContext(); | ||
| if (sslContext.isPresent()) { | ||
| options.sslContext(sslContext.get()); | ||
| options.sslEnabled(true); | ||
| log.debug("SSL enabled for MongoDB client with TLS protocol"); | ||
| } |
There was a problem hiding this comment.
| Optional<SSLContext> sslContext = sslContextProvider.buildSslContext(); | |
| if (sslContext.isPresent()) { | |
| options.sslContext(sslContext.get()); | |
| options.sslEnabled(true); | |
| log.debug("SSL enabled for MongoDB client with TLS protocol"); | |
| } | |
| sslContextProvider.buildSslContext() | |
| .ifPresent(sslContext -> { | |
| options.sslContext(sslContext); | |
| options.sslEnabled(true); | |
| }); |
| <dependency> | ||
| <groupId>com.facebook.airlift</groupId> | ||
| <artifactId>security</artifactId> | ||
| </dependency> |
There was a problem hiding this comment.
Why do we need this? and below pom changes?
presto-spi/pom.xml
Outdated
| <dependency> | ||
| <groupId>com.facebook.airlift</groupId> | ||
| <artifactId>security</artifactId> | ||
| <scope>provided</scope> |
There was a problem hiding this comment.
Why are we marking this and below as scope provided?
There was a problem hiding this comment.
The presto-spi pom changes are required because I've moved SslContextProvider to the spi package to make it reusable across connectors. The presto-mongodb dependency was added to resolve compilation issues when using SslContextProvider but I have removed them now with the new changes.
There was a problem hiding this comment.
I added the presto-spi pom changes because SslContextProvider directly imports and uses Logger from airlift.log and PemReader from airlift.security.pem , without these dependencies, the code won't compile as shown in the compilation errors.
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.0:compile (default-compile) on project presto-spi: Compilation failure: Compilation failure:
[ERROR] /Users/sayarimukherjee/Desktop/os-presto/presto/presto-spi/src/main/java/com/facebook/presto/spi/security/SslContextProvider.java:[16,32] package com.facebook.airlift.log does not exist
[ERROR] /Users/sayarimukherjee/Desktop/os-presto/presto/presto-spi/src/main/java/com/facebook/presto/spi/security/SslContextProvider.java:[17,41] package com.facebook.airlift.security.pem does not exist
[ERROR] /Users/sayarimukherjee/Desktop/os-presto/presto/presto-spi/src/main/java/com/facebook/presto/spi/security/SslContextProvider.java:[54,26] cannot find symbol
[ERROR] symbol: class Logger
[ERROR] location: class com.facebook.presto.spi.security.SslContextProvider
[ERROR] /Users/sayarimukherjee/Desktop/os-presto/presto/presto-spi/src/main/java/com/facebook/presto/spi/security/SslContextProvider.java:[54,39] cannot find symbol
[ERROR] symbol: variable Logger
[ERROR] location: class com.facebook.presto.spi.security.SslContextProvider
[ERROR] /Users/sayarimukherjee/Desktop/os-presto/presto/presto-spi/src/main/java/com/facebook/presto/spi/security/SslContextProvider.java:[132,24] cannot find symbol
[ERROR] symbol: variable PemReader
[ERROR] location: class com.facebook.presto.spi.security.SslContextProvider
[ERROR] /Users/sayarimukherjee/Desktop/os-presto/presto/presto-spi/src/main/java/com/facebook/presto/spi/security/SslContextProvider.java:[177,54] cannot find symbol
[ERROR] symbol: variable PemReader
[ERROR] location: class com.facebook.presto.spi.security.SslContextProvider
[ERROR] -> [Help 1]
|
Does https://github.com/prestodb/presto/blob/master/presto-docs/src/main/sphinx/connector/mongodb.rst need any documentation update for this? |
@steveburnett , yes the documentation will need to be updated. I'm currently working on addressing the review feedback from @agrawalreetika and will include the necessary documentation updates for all the new TLS configuration properties in the next commit. This will include proper documentation for the new mongodb.tls.* configs and deprecation notices for the old SSL setting. I'll make sure to get these changes pushed soon. |
agrawalreetika
left a comment
There was a problem hiding this comment.
Thanks for making the changes. Overall LGTM.
Please add the documentation & squash all your commits into one.
| keystorePath != null || | ||
| keystorePassword != null || | ||
| truststorePath != null || | ||
| truststorePassword != null; |
There was a problem hiding this comment.
Why are we checking these here?
There was a problem hiding this comment.
This was added to handle cases where users provide TLS-related configurations like mongodb.tls.keystore-path but forget to explicitly enable mongodb.tls.enabled=true. Automatically enabling TLS in such cases helps prevent common configuration mistakes. However, I'm happy to remove or adjust this logic if you think it’s unnecessary.
There was a problem hiding this comment.
But whenever mongodb.tls.enabled=false then anyways SSL wouldn't be configured right? https://github.com/prestodb/presto/pull/25374/files#diff-5461194df57bf18a7c80e310cc21d80dc5e078b9707226b0d5f49728c02ae12eR87
There was a problem hiding this comment.
You're right. I see the issue now. The current logic in isTlsEnabled() is problematic because it automatically enables TLS whenever any TLS-related properties are set, regardless of the mongodb.tls.enabled flag. This could lead to unexpected behavior.
I'll simplify this to just return this.tlsEnabled and remove the automatic detection logic.
There was a problem hiding this comment.
@imsayari404 There are compilation failures, please fix those, add the documentation & squash all your commits into one.
f6d48f7 to
e89a22c
Compare
@agrawalreetika The updated changes are now pushed to the branch. |
presto-spi/src/main/java/com/facebook/presto/spi/security/SslContextProvider.java
Show resolved
Hide resolved
e025cf6 to
d1b46b5
Compare
There was a problem hiding this comment.
I just want to make sure that this will expire very far into the future?
There was a problem hiding this comment.
or we could generate it programmatically? I just remembered we were trying it for HMS SSL tests: #25313. Looks like I forgot to review it further but that could be one alternative.
There was a problem hiding this comment.
Updated to use programmatic certificate generation similar to the Hive SSL tests (#25313).
d1b46b5 to
3224516
Compare
|
@tdcmeehan, could you please review this PR at your convenience? |
|
@imjalpreet PTAL. @imsayari404 please squash commits. |
3224516 to
e46ea96
Compare
|
Thanks @tdcmeehan , I've squashed the commits |
There was a problem hiding this comment.
Since we are using the same implementation, I will finish the review of #25313 and get it added to a common module so that we can re-use across plugins.
8d72d78 to
a5cb2b3
Compare
imjalpreet
left a comment
There was a problem hiding this comment.
@imsayari404, I don't see the new test for TLS I was reviewing earlier. Can you please take a look?
imjalpreet
left a comment
There was a problem hiding this comment.
Thanks, @imsayari404. I did another pass. One question: Is it possible to add a test for TLS specifically for the MongoDB connector?
presto-mongodb/src/main/java/com/facebook/presto/mongodb/MongoClientConfig.java
Outdated
Show resolved
Hide resolved
presto-mongodb/src/main/java/com/facebook/presto/mongodb/MongoClientConfig.java
Show resolved
Hide resolved
presto-tests/src/test/java/com/facebook/presto/tests/TestSslContextProvider.java
Outdated
Show resolved
Hide resolved
presto-mongodb/src/test/java/com/facebook/presto/mongodb/TestMongoClientConfig.java
Outdated
Show resolved
Hide resolved
| SslContextProvider sslContextProvider = new SslContextProvider( | ||
| config.getKeystorePath(), | ||
| config.getKeystorePassword(), | ||
| config.getTruststorePath(), | ||
| config.getTruststorePassword()); |
There was a problem hiding this comment.
Let's create a method for creating this object and reuse
presto-mongodb/src/test/java/com/facebook/presto/mongodb/TestMongoTlsConfiguration.java
Outdated
Show resolved
Hide resolved
| SslKeystoreManager.initializeKeystoreAndTruststore(); | ||
|
|
||
| keystoreFile = new File(SslKeystoreManager.getKeystorePath()); | ||
| truststoreFile = new File(SslKeystoreManager.getTruststorePath()); |
presto-tests/src/test/java/com/facebook/presto/tests/TestSslContextProvider.java
Show resolved
Hide resolved
presto-mongodb/src/main/java/com/facebook/presto/mongodb/MongoClientModule.java
Outdated
Show resolved
Hide resolved
Cherry-pick of commits in https://github.ibm.com/lakehouse/presto/pull/447/commits Commits picked - d2c50df 7c6a8b1 Co-authored-by: Anant Aneja <1797669+aaneja@users.noreply.github.com>
imjalpreet
left a comment
There was a problem hiding this comment.
Thanks, @imsayari404. LGTM now.
This PR introduces TLS support in the MongoDB connector
Description
Motivation and Context
Impact
Test Plan
Contributor checklist
Release Notes
Please follow release notes guidelines and fill in the release notes below.