-
Notifications
You must be signed in to change notification settings - Fork 3.5k
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
GH-38460: [Java][FlightRPC] Add mTLS support for Flight SQL JDBC driver #38461
GH-38460: [Java][FlightRPC] Add mTLS support for Flight SQL JDBC driver #38461
Conversation
…tls' into feature/flight-sql-jdbc-driver-mtls
|
Thanks @prmoore77 ! @vibhatha @davisusanibar and I can take a look this week. |
...flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/ConnectionMutualTlsTest.java
Outdated
Show resolved
Hide resolved
Thanks for the PR. I'm doing a pass and testing as well. |
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.
The tests are quite thorough, nice work! I'll defer to others who have more experience on Flight SQL for approval.
* @throws Exception on error. | ||
*/ | ||
@Test | ||
public void testTLSConnectionPropertyTrueIntegerCorrectCastUrlAndPropertiesUsingPutWithDriverManager() |
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.
We could use @ParameterizedTest
to reduce some code duplication in the test files.
final ArrowFlightJdbcDataSource dataSource = | ||
ArrowFlightJdbcDataSource.createNewDataSource(properties); | ||
try (final Connection connection = dataSource.getConnection()) { | ||
assert connection.isValid(300); |
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.
Out of curiosity, why is there a 300 second timeout for ArrowFlightJdbcDataSource
connections, but 0 second timeouts for ArrowFlightJdbcDriver
/DriverManager
connections?
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.
Very good question :) - I copied the tests from the ConnectionTlsTest.java
code - while modifying the tests for mTLS of course. I'm not sure of the rationale for the timeout, but I'll research it.
* @param mTlsCACert The CA certificate to use for verifying clients. | ||
*/ | ||
public Builder useMTlsClientVerification(final File mTlsCACert) throws IOException { | ||
this.mTlsCACert = new FileInputStream(mTlsCACert); |
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 user calls this method repeatedly we will leak File handles. Need to close the current one if it exists. Perhaps it would be better to defer opening the physical file until starting the connection, though that delays notification if there's a problem opening it.
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.
Hey @jduo - I'm not a very good Java developer - but I'm learning (thanks for your patience). Would it be like this?
public Builder useMTlsClientVerification(final File mTlsCACert) throws IOException {
if (this.mTlsCACert != null) {
this.mTlsCACert.close();
}
this.mTlsCACert = new FileInputStream(mTlsCACert);
Thanks for your help!
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.
Yes this would work. However I'm leaning towards deferring opening mTlsCACert until the connection is made. It's odd for builders to have more logic than setting fields.
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.
@jduo just for my knowledge and to clarify a point, would it be more easier if we use try-with-resources here?
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.
hi @jduo - this is the FlightServer - I'd rather not change the overall design of the current class's builder. It already uses this approach for useTls
- and I think my change is consistent with that.
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.
@vibhatha , try-with-resources wouldn't help here since we need the stream to have a longer lifetime than this builder function. This is more of a case of tracking ownership.
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.
Got it, thanks @jduo
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.
@jduo - I've added small changes that detect if the InputStream attributes are not null, and if so - closes them. Could you please re-review?
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 @prmoore77 minor comment about another possible error scenario in useTls() that applies here.
* @param mTlsCACert The CA certificate to use for verifying clients. | ||
*/ | ||
public Builder useMTlsClientVerification(final InputStream mTlsCACert) throws IOException { | ||
this.mTlsCACert = mTlsCACert; |
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.
Similar comment as above about this potentially leaking a file. Also, now it is ambiguous whether the Flight client should close() mTlsCACert (presumably it should but there should be a comment).
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.
I mirrored the existing useTls
method here
Does that code have the issue as well?
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.
Correct. It looks to have this issue too.
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.
@vibhatha @davisusanibar can you file an issue to fix this?
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.
@lidavidm I will file one. Will study a bit and file one.
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.
given that this issue will be filed separately - is it acceptable to approve/merge this PR?
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.
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.
Filed #38586
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.
Thank you for the PR. I am adding a few minor questions.
- Path to PEM-encoded client mTLS certificate when the Flight | ||
SQL server requires client verification. | ||
|
||
* - clientKey |
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.
Will it be necessary to provide an optional client key password argument if this client private key is password-protected?
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.
Hello – it could be added, but the Java Flight client doesn’t yet support that to my knowledge – so I just wanted to catch up to that for now. We can add it in a later PR, unless you feel strongly that it should be included here.
...jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/client/ArrowFlightSqlClientHandler.java
Show resolved
Hide resolved
@prmoore77 I left a few comments and nice work with the test cases and comments. Thanks for working on this issue. |
…FlightServer.java Co-authored-by: David Li <[email protected]>
* @param mTlsCACert The CA certificate to use for verifying clients. | ||
*/ | ||
public Builder useMTlsClientVerification(final InputStream mTlsCACert) throws IOException { | ||
this.mTlsCACert = mTlsCACert; |
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.
Filed #38586
@prmoore77 heads up, after #38521 a copy constructor was added to ArrowFlightSqlClientHandler.Builder #38580 also changes ArrowFligthSqlClientHandler to set defaults correctly and adds tests for verifying defaults, so if that goes in first, new fields will be added there too. |
Hi @jduo - I've added the new fields to the new copy constructor (from #38521) - per your recommendation. See: 1975786 - for details. Thanks! |
I did a quick test and review. LGTM. Thanks ! |
After merging your PR, Conbench analyzed the 5 benchmarking runs that have been run so far on merge-commit 4ff1a29. There were no benchmark performance regressions. 🎉 The full Conbench report has more details. It also includes information about 3 possible false positives for unstable benchmarks that are known to sometimes produce them. |
…C driver (apache#38461) ### Rationale for this change I wanted to add additional security capabilities to the Arrow Flight SQL JDBC driver so that it catches up to ADBC. ADBC already supports mTLS - and it is a great security feature. I wanted to bring this to the JDBC driver as well. ### What changes are included in this PR? This PR adds support for mTLS (client certificate verification/authentication) to the Arrow Flight SQL JDBC driver. ### Are these changes tested? Yes, I've added tests of the new mTLS functionality - and have ensured that the change is backward compatible by verifying all existing tests pass. ### Are there any user-facing changes? Yes - but the end-user documentation for the Arrow Flight SQL JDBC driver has been updated in the PR itself. * Closes: apache#38460 Lead-authored-by: prmoore77 <[email protected]> Co-authored-by: David Li <[email protected]> Signed-off-by: David Li <[email protected]>
…C driver (apache#38461) ### Rationale for this change I wanted to add additional security capabilities to the Arrow Flight SQL JDBC driver so that it catches up to ADBC. ADBC already supports mTLS - and it is a great security feature. I wanted to bring this to the JDBC driver as well. ### What changes are included in this PR? This PR adds support for mTLS (client certificate verification/authentication) to the Arrow Flight SQL JDBC driver. ### Are these changes tested? Yes, I've added tests of the new mTLS functionality - and have ensured that the change is backward compatible by verifying all existing tests pass. ### Are there any user-facing changes? Yes - but the end-user documentation for the Arrow Flight SQL JDBC driver has been updated in the PR itself. * Closes: apache#38460 Lead-authored-by: prmoore77 <[email protected]> Co-authored-by: David Li <[email protected]> Signed-off-by: David Li <[email protected]>
…C driver (apache#38461) ### Rationale for this change I wanted to add additional security capabilities to the Arrow Flight SQL JDBC driver so that it catches up to ADBC. ADBC already supports mTLS - and it is a great security feature. I wanted to bring this to the JDBC driver as well. ### What changes are included in this PR? This PR adds support for mTLS (client certificate verification/authentication) to the Arrow Flight SQL JDBC driver. ### Are these changes tested? Yes, I've added tests of the new mTLS functionality - and have ensured that the change is backward compatible by verifying all existing tests pass. ### Are there any user-facing changes? Yes - but the end-user documentation for the Arrow Flight SQL JDBC driver has been updated in the PR itself. * Closes: apache#38460 Lead-authored-by: prmoore77 <[email protected]> Co-authored-by: David Li <[email protected]> Signed-off-by: David Li <[email protected]>
Rationale for this change
I wanted to add additional security capabilities to the Arrow Flight SQL JDBC driver so that it catches up to ADBC. ADBC already supports mTLS - and it is a great security feature. I wanted to bring this to the JDBC driver as well.
What changes are included in this PR?
This PR adds support for mTLS (client certificate verification/authentication) to the Arrow Flight SQL JDBC driver.
Are these changes tested?
Yes, I've added tests of the new mTLS functionality - and have ensured that the change is backward compatible by verifying all existing tests pass.
Are there any user-facing changes?
Yes - but the end-user documentation for the Arrow Flight SQL JDBC driver has been updated in the PR itself.