Add support for mTLS authentication in Arrow Flight client#25179
Add support for mTLS authentication in Arrow Flight client#25179ZacBlanco merged 1 commit intoprestodb:masterfrom
Conversation
38df200 to
f2aff7e
Compare
|
https://github.com/prestodb/presto/actions/runs/15201290385/job/42755765576?pr=25179 @steveburnett I'm not able to figure out why the presto-docs check is failing. Can you help here? Edit : Waiting for fix to be merged here. |
f2aff7e to
16c6399
Compare
|
Fix has been merged, and the test is now passing - see #25188 for an example. Rebase your PR to re-run the CI tests and |
7bdfc96 to
bb2cf1d
Compare
pratyakshsharma
left a comment
There was a problem hiding this comment.
Thank you for the fix @elbinpallimalilibm. I have added few comments, please check.
| return flightClientSSLCertificate; | ||
| } | ||
|
|
||
| @Config("arrow-flight.client-ssl-certificate") |
There was a problem hiding this comment.
I think it will be good to add a comment here saying this is needed for mTLS auth.
There was a problem hiding this comment.
Added comments.
There was a problem hiding this comment.
instead of a javadoc, could you put this in a @ConfigDescription?
| Optional<InputStream> clientCertificate = Optional.empty(); | ||
| Optional<InputStream> clientKey = Optional.empty(); | ||
| if (config.getFlightClientSSLCertificate() != null && config.getFlightClientSSLKey() != null) { | ||
| clientCertificate = Optional.of(newInputStream(Paths.get(config.getFlightClientSSLCertificate()))); |
There was a problem hiding this comment.
trying to understand it a bit better, what happens if the certificate and key are invalid? Lets use a try-catch block here? And maybe add a test case covering this scenario?
There was a problem hiding this comment.
If the cert is invalid, executing a query will give the user an error that the cert is invalid. Added a test case that covers this scenario.
There was a problem hiding this comment.
Lets add a try-catch here as well and modify the error message in the test case accordingly. Thank you for adding test case for this though.
There was a problem hiding this comment.
The invalid cert exception is thrown only at line 84 FlightClient flightClient = flightClientBuilder.build(); and we might get exception due to other reasons as well from the build method. So adding a try...catch here will not help in modifying the error message.
There was a problem hiding this comment.
Ok, I actually foresee improperly configured client cert/key as a very probable source of error, and hence wanted to cover the scenario with a proper user facing message. Anyways I leave the final decision to you.
There was a problem hiding this comment.
Refactored the code to catch errors due to invalid cert or key file. Rethrowing a Presto Exception with a custom message for those scenarios.
| ``arrow-flight.server.port`` Flight server port | ||
| ``arrow-flight.server-ssl-certificate`` Pass ssl certificate | ||
| ``arrow-flight.server-ssl-certificate`` Path to SSL certificate of Flight server | ||
| ``arrow-flight.client-ssl-certificate`` Path to SSL certificate that Flight client should use |
There was a problem hiding this comment.
nit: lets modify these to include "in case of mTLS authentication" to make it more clear?
There was a problem hiding this comment.
Updated the docs.
| } | ||
|
|
||
| @BeforeClass | ||
| public void setup() |
There was a problem hiding this comment.
The 2 test classes have a lot of duplicate code. Please see if we can use inheritance to avoid this redundant code?
There was a problem hiding this comment.
Refactored the test classes.
bb2cf1d to
60eaa3b
Compare
117c43a to
4a84c3b
Compare
steveburnett
left a comment
There was a problem hiding this comment.
LGTM! (docs)
Pull branch, local doc build, looks good. Thanks!
4a84c3b to
83a005f
Compare
pratyakshsharma
left a comment
There was a problem hiding this comment.
Thank you for addressing earlier comments. I have few more minor comments, once addressed, I will approve.
| } | ||
|
|
||
| private static DistributedQueryRunner createQueryRunner( | ||
| public static DistributedQueryRunner createQueryRunner( |
There was a problem hiding this comment.
why are we modifying the access-modifier?
There was a problem hiding this comment.
We need to create query runner with pre-defined catalog properties from the new test classes. That's why the method was changed to public from private.
There was a problem hiding this comment.
Does protected or other modifier work instead?
There was a problem hiding this comment.
Changed to protected
| Optional<InputStream> clientCertificate = Optional.empty(); | ||
| Optional<InputStream> clientKey = Optional.empty(); | ||
| if (config.getFlightClientSSLCertificate() != null && config.getFlightClientSSLKey() != null) { | ||
| clientCertificate = Optional.of(newInputStream(Paths.get(config.getFlightClientSSLCertificate()))); |
There was a problem hiding this comment.
Lets add a try-catch here as well and modify the error message in the test case accordingly. Thank you for adding test case for this though.
| } | ||
|
|
||
| @BeforeClass | ||
| public void setup() |
There was a problem hiding this comment.
Does this method need to be public? How about making it package private? Similarly for other methods apart from createQueryRunner, lets make them as restricted as possible.
| } | ||
|
|
||
| @Override | ||
| protected Map<String, String> getCatalogProperties() |
There was a problem hiding this comment.
The access modifiers here will change based on my above comment.
83a005f to
1021d94
Compare
pratyakshsharma
left a comment
There was a problem hiding this comment.
Couple more comments, rest looks good
| } | ||
|
|
||
| private static DistributedQueryRunner createQueryRunner( | ||
| public static DistributedQueryRunner createQueryRunner( |
There was a problem hiding this comment.
Does protected or other modifier work instead?
|
|
||
| abstract Map<String, String> getCatalogProperties(); | ||
|
|
||
| protected int getServerPort() |
There was a problem hiding this comment.
Lets change this to package private as well?
3fe0e0e to
4bbfaa5
Compare
pratyakshsharma
left a comment
There was a problem hiding this comment.
Thank you for patiently addressing all comments. Few refactorings needed, rest looks good
| catch (Exception e) { | ||
| throw new ArrowException(ARROW_FLIGHT_CLIENT_ERROR, "Error creating flight client: " + e.getMessage(), e); | ||
| Optional<Throwable> cause = Optional.ofNullable(e.getCause()); | ||
| if (cause.filter(c -> c instanceof InvalidKeyException).isPresent()) { |
There was a problem hiding this comment.
| if (cause.filter(c -> c instanceof InvalidKeyException).isPresent()) { | |
| if (e instanceOf InvalidKeyException) { |
There was a problem hiding this comment.
can be simplified like this.
There was a problem hiding this comment.
e will be instance of IllegalArgumentException. Inner exception e.getCause if not null, will be an instance of InvalidKeyException
| if (cause.filter(c -> c instanceof InvalidKeyException).isPresent()) { | ||
| throw new ArrowException(ARROW_FLIGHT_INVALID_KEY_ERROR, "Error creating flight client, invalid key file: " + e.getMessage(), e); | ||
| } | ||
| else if (cause.filter(c -> c instanceof CertificateException).isPresent()) { |
| clientCertificate.get().close(); | ||
| } | ||
| catch (IOException e) { | ||
| logger.error("Error closing input stream", e); |
There was a problem hiding this comment.
the error messages here are all identical, can be modified in different blocks.
| clientCertificate.get().close(); | ||
| } | ||
| catch (IOException e) { | ||
| logger.error("Error closing input stream", e); |
There was a problem hiding this comment.
| logger.error("Error closing input stream", e); | |
| logger.error("Error closing input stream for clientCertificate", e); |
| clientKey.get().close(); | ||
| } | ||
| catch (IOException e) { | ||
| logger.error("Error closing input stream", e); |
4bbfaa5 to
dd0d61a
Compare
pratyakshsharma
left a comment
There was a problem hiding this comment.
Thank you for the proactive responses. LGTM!
|
@prestodb/committers this should be good for final pass |
ZacBlanco
left a comment
There was a problem hiding this comment.
One comment. Also, I think instead of having 3 test classes, let's combine the TestArrowFlightMTLSFails and TestArrowFlightMTLSInvalidCert into a single file. Just add catalogs to the query runner with those configurations, and then execute the test queries against those catalogs instead. This way we don't need to test 3 separate classes.
| } | ||
| catch (Exception e) { | ||
| throw new ArrowException(ARROW_FLIGHT_CLIENT_ERROR, "Error creating flight client: " + e.getMessage(), e); | ||
| Optional<Throwable> cause = Optional.ofNullable(e.getCause()); |
There was a problem hiding this comment.
This optional also doesn't really provide value. There is no real use of the option value. Let's just use e.getCause() directly and do the cause instanceof <XYZ> check in the conditional instead.
There was a problem hiding this comment.
Refactored to use e.getCause() instanceof ..
dd0d61a to
cd6d803
Compare
Merged the three test classes into one. |
BryanCutler
left a comment
There was a problem hiding this comment.
Looks good, just a few minor nits
| return flightClientSSLCertificate; | ||
| } | ||
|
|
||
| @Config("arrow-flight.client-ssl-certificate") |
There was a problem hiding this comment.
instead of a javadoc, could you put this in a @ConfigDescription?
| } | ||
|
|
||
| /*** | ||
| * Set the client SSL key used for mTLS authentication with Flight server |
There was a problem hiding this comment.
same here about @ConfigDescription
2f38905
ad08755 to
e8a1c06
Compare
Description
Add support for mTLS authentication in Arrow Flight client
Motivation and Context
If the Flight server has mTLS authentication enabled, then the Flight client should be able to use client certificate and key.
Impact
Test Plan
Added positive and negative test cases against an mTLS enabled Flight server.
Contributor checklist
Release Notes
Please follow release notes guidelines and fill in the release notes below.