ferenc-csaky commented on code in PR #30199:
URL: https://github.com/apache/flink/pull/30199#discussion_r4769701281


##########
flink-runtime/src/test/java/org/apache/flink/runtime/net/SSLUtilsTest.java:
##########
@@ -246,6 +252,101 @@ void testRESTServerSSLBadKeystoreType(String sslProvider) 
{
                 .isInstanceOf(KeyStoreException.class);
     }
 
+    // ------------------- REST server mutual authentication 
---------------------
+
+    /**
+     * Tests that REST mutual authentication without a truststore fails 
instead of being skipped.
+     */
+    @ParameterizedTest
+    @MethodSource("parameters")
+    void testRESTServerSSLMutualAuthWithoutTrustStore(String sslProvider) {
+        Configuration serverConfig = 
createRestSslConfigWithKeyStore(sslProvider);
+        serverConfig.set(SecurityOptions.SSL_REST_AUTHENTICATION_ENABLED, 
true);
+
+        assertThatThrownBy(() -> 
SSLUtils.createRestServerSSLEngineFactory(serverConfig))
+                .isInstanceOf(IllegalConfigurationException.class)
+                .hasMessage(
+                        "Mutual authentication is enabled for the REST 
endpoints "
+                                + "(security.ssl.rest.authentication-enabled), 
but no truststore is "
+                                + "configured to verify the client 
certificates. The config option "
+                                + "security.ssl.rest.truststore or 
security.ssl.truststore is missing.");
+    }
+
+    /** Tests that a REST server with mutual authentication requires a client 
certificate. */
+    @ParameterizedTest
+    @MethodSource("parameters")
+    void testRESTServerSSLMutualAuthEnforcesClientCertificate(String 
sslProvider) throws Exception {
+        Configuration serverConfig = 
createRestSslConfigWithKeyAndTrustStores(sslProvider);
+        serverConfig.set(SecurityOptions.SSL_REST_AUTHENTICATION_ENABLED, 
true);
+
+        assertRESTMutualAuthEnforced(serverConfig, sslProvider);
+    }
+
+    /** Tests that the generic truststore options are accepted for REST mutual 
authentication. */
+    @ParameterizedTest
+    @MethodSource("parameters")
+    void testRESTServerSSLMutualAuthWithGenericTrustStore(String sslProvider) 
throws Exception {
+        Configuration serverConfig = 
createRestSslConfigWithKeyStore(sslProvider);
+        serverConfig.set(SecurityOptions.SSL_REST_AUTHENTICATION_ENABLED, 
true);
+        serverConfig.set(SecurityOptions.SSL_TRUSTSTORE, TRUST_STORE_PATH);
+        serverConfig.set(SecurityOptions.SSL_TRUSTSTORE_PASSWORD, 
TRUST_STORE_PASSWORD);
+
+        assertRESTMutualAuthEnforced(serverConfig, sslProvider);
+    }
+
+    /**
+     * Tests that only the REST server needs a truststore for mutual 
authentication: a REST client
+     * without one is created and verifies the server against the default 
truststore of the JDK.
+     */
+    @ParameterizedTest
+    @MethodSource("parameters")
+    void testRESTClientSSLMutualAuthWithoutTrustStore(String sslProvider) 
throws Exception {
+        Configuration serverConfig =
+                
withTlsCiphers(createRestSslConfigWithKeyAndTrustStores(sslProvider), 
sslProvider);
+        serverConfig.set(SecurityOptions.SSL_REST_AUTHENTICATION_ENABLED, 
true);
+        Configuration clientConfig = 
createRestSslConfigWithKeyStore(sslProvider);
+        clientConfig.set(SecurityOptions.SSL_REST_AUTHENTICATION_ENABLED, 
true);
+
+        SSLHandlerFactory server = 
SSLUtils.createRestServerSSLEngineFactory(serverConfig);
+        SSLHandlerFactory client = 
SSLUtils.createRestClientSSLEngineFactory(clientConfig);
+
+        // the default truststore of the JDK does not contain the self-signed 
test certificate
+        assertThatThrownBy(() -> negotiate(server, client))

Review Comment:
   This passes on any `SSLHandshakeException`, so a cipher or protocol mismatch 
would pass it too. Could you assert the root cause (a 
`CertPathBuilderException` with the JDK provider), or cut the Javadoc down to 
the part about creating the client?



##########
flink-runtime/src/test/java/org/apache/flink/runtime/rest/RestServerEndpointConfigurationTest.java:
##########
@@ -56,4 +66,23 @@ void testBasicMapping(@TempDir File file) throws 
ConfigurationException {
         assertThat(result.getUploadDir().toAbsolutePath().toString())
                 .contains(file.getAbsolutePath());
     }
+
+    @Test
+    void testMutualAuthWithoutTrustStore(@TempDir File file) {

Review Comment:
   I'd drop this test. 
`SSLUtilsTest#testRESTServerSSLMutualAuthWithoutTrustStore` already asserts the 
exact exception, and `fromConfiguration` wrapped 
`createRestServerSSLEngineFactory` the same way before this PR. Dropping it 
also removes `KEY_STORE_PATH` and the four new imports.



##########
docs/content/docs/deployment/security/security-ssl.md:
##########
@@ -136,8 +136,10 @@ For REST endpoints, by default the keystore is used by the 
server endpoint, and
 to accept the server's certificate. In the case where the REST keystore has a 
self-signed certificate, the truststore must trust that certificate directly.
 If the REST endpoint uses a certificate that is signed through a proper 
certification hierarchy, the roots of that hierarchy should
 be in the trust store.
+If no truststore is configured, the REST clients verify the server's 
certificate against the default truststore of the JDK.

Review Comment:
   nit: `security.ssl.rest.verify-hostname` is off by default, so a client 
without a truststore accepts a certificate from any CA the JDK trusts, issued 
for any host. Could you add "Enable `security.ssl.rest.verify-hostname` in this 
case." here and in the Chinese page?



-- 
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]

Reply via email to