lasdf1234 commented on code in PR #14934:
URL: https://github.com/apache/gravitino/pull/14934#discussion_r4546177828
##########
clients/client-java/src/test/java/org/apache/gravitino/client/TestHTTPClientTLS.java:
##########
@@ -143,12 +140,32 @@ public void testClientRejectsUntrustedServerCertificate()
throws Exception {
jettyServer, false, createTestServlet(), TEST_SERVLET_PATH);
TLSConfigurer tlsConfigurer =
- TLSConfigurers.builder()
- .trustStore(
-
TestTlsServerUtils.testResource("test-untrusted-server-truststore.p12"),
- TEST_STORE_PASSWORD)
- .build();
+ TLSConfigurers.withTrustStore(
+
TestTlsServerUtils.testResource("test-untrusted-server-truststore.p12"),
+ TEST_STORE_PASSWORD);
+
+ try (HTTPClient client = createHttpsClient(port, tlsConfigurer)) {
+ RESTException exception =
+ assertThrows(
+ RESTException.class,
+ () -> client.head(TEST_CLIENT_PATH, ImmutableMap.of(), response
-> {}));
+
+ TestTlsServerUtils.assertHandshakeFailure(exception);
+ }
+ }
+
+ @Test
+ public void testMutualTLSWithDefaultTrustStoreRejectsUntrustedServer()
throws Exception {
Review Comment:
**[Medium]** Same gap from the test side: this only asserts handshake
failure with the private-CA test server. Consider a follow-up success path (or
document why it cannot be IT’d with current `TestTlsServerUtils` certs).
##########
clients/client-java/src/main/java/org/apache/gravitino/client/TLSConfigurers.java:
##########
@@ -53,8 +93,52 @@ public static final class Builder {
private String keyStorePassword;
private String storeType = DEFAULT_STORE_TYPE;
+ private String[] protocols = new String[0];
+ private String[] cipherSuites = new String[0];
+
private Builder() {}
+ /**
+ * Configures the allowed TLS protocols.
+ *
+ * <p>If no protocols are specified, the default TLS protocols are used.
+ *
+ * @param protocols allowed TLS protocols, such as {@code TLSv1.3}
+ * @return this builder
+ */
+ public Builder protocols(String... protocols) {
Review Comment:
**[Low]** Validation only rejects null/empty strings. Typos like `TLSv9`
will fail at handshake rather than at `build()`. Acceptable if intentional;
optionally validate against
`SSLContext.getDefault().getSupportedSSLParameters().getProtocols()` (and
similarly for cipher suites) for earlier, clearer errors.
##########
clients/client-java/src/main/java/org/apache/gravitino/client/TLSConfigurers.java:
##########
@@ -45,6 +45,46 @@ public static Builder builder() {
return new Builder();
}
+ /**
+ * Creates a TLS configurer using a custom truststore.
+ *
+ * @param path path to the truststore
+ * @param password truststore password
+ * @return the configured TLS configurer
+ */
+ public static TLSConfigurer withTrustStore(Path path, String password) {
+ return builder().trustStore(path, password).build();
+ }
+
+ /**
+ * Creates a TLS configurer using a default JVM truststore and a custom
client keystore.
+ *
+ * @param path path to the client keystore
+ * @param password keystore password
+ * @return the configured TLS configurer
+ */
+ public static TLSConfigurer withKeyStore(Path path, String password) {
Review Comment:
**[Medium]** `withKeyStore` (client cert + default JVM trust) is only
covered by a *rejection* IT against the self-signed Jetty fixture
(`testMutualTLSWithDefaultTrustStoreRejectsUntrustedServer`). That proves the
JVM trust path rejects untrusted servers, but not that keystore-only mTLS can
succeed against a server the JVM already trusts.
If a success handshake is hard with current fixtures, please at least call
that out in docs/Javadoc (CUJ: public-CA server + client cert), or add a
build/init-level assertion that `sslContext()` initializes with default trust
managers when no truststore is set.
##########
clients/client-java/src/main/java/org/apache/gravitino/client/TLSConfigurers.java:
##########
@@ -63,6 +147,9 @@ private Builder() {}
* @return this builder
*/
public Builder trustStore(Path path, String password) {
+ Preconditions.checkArgument(path != null, "Truststore path must not be
null");
+ Preconditions.checkArgument(password != null, "Truststore password must
not be null");
Review Comment:
**[Low]** `password != null` allows `""`. Fine for some PKCS12 stores, but
worth a Javadoc note that an empty password is permitted (same for keystore
password below).
##########
clients/client-java/src/main/java/org/apache/gravitino/client/TLSConfigurers.java:
##########
@@ -45,6 +45,46 @@ public static Builder builder() {
return new Builder();
}
+ /**
+ * Creates a TLS configurer using a custom truststore.
+ *
+ * @param path path to the truststore
+ * @param password truststore password
+ * @return the configured TLS configurer
+ */
+ public static TLSConfigurer withTrustStore(Path path, String password) {
+ return builder().trustStore(path, password).build();
+ }
+
+ /**
+ * Creates a TLS configurer using a default JVM truststore and a custom
client keystore.
+ *
+ * @param path path to the client keystore
+ * @param password keystore password
+ * @return the configured TLS configurer
+ */
+ public static TLSConfigurer withKeyStore(Path path, String password) {
Review Comment:
**[Medium — docs]** When docs land, please spell out clearly that:
1. A custom truststore **replaces** the JVM default trust for this client
(it is not merged).
2. When to use `withKeyStore` vs `withMutualTls`.
3. Examples for `protocols(...)` / `cipherSuites(...)`.
Without that, operators often assume private CAs are *added* to system trust
and then break other TLS in the same process.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]