mateczagany commented on code in PR #27034:
URL: https://github.com/apache/flink/pull/27034#discussion_r2845032737


##########
flink-core/src/main/java/org/apache/flink/core/security/watch/LocalFSDirectoryWatcher.java:
##########
@@ -0,0 +1,54 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.flink.core.security.watch;
+
+import java.io.IOException;
+import java.nio.file.Path;
+import java.nio.file.WatchService;
+import java.util.Map;
+import java.util.Set;
+
+/**
+ * Interface for watching file system directories and notifying listeners of 
changes.
+ *
+ * <p>Implementations monitor directories for file modifications and invoke 
registered {@link
+ * LocalFSWatchServiceListener} callbacks when changes occur.
+ */
+public interface LocalFSDirectoryWatcher {

Review Comment:
   I think this could be annotated as `@Internal`



##########
flink-core/src/main/java/org/apache/flink/core/security/watch/LocalFSWatchServiceListener.java:
##########
@@ -0,0 +1,215 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.flink.core.security.watch;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.nio.file.Path;
+import java.util.concurrent.atomic.AtomicReference;
+
+/**
+ * Listener interface for file system watch events.
+ *
+ * <p>This interface provides a mechanism for components to respond to file 
system changes and
+ * manage resource reloading (e.g., SSL certificates, configuration files) in 
a thread-safe manner.
+ *
+ * <p>Example usage:
+ *
+ * <pre>{@code
+ * public class MySslContext extends AbstractLocalFSWatchServiceListener {
+ *     private volatile SSLContext sslContext;
+ *
+ *     public SSLContext getContext() {
+ *         reloadContextIfNeeded(this::loadSslContext);
+ *         return sslContext;
+ *     }
+ *
+ *     private void loadSslContext() throws Exception {
+ *         this.sslContext = SSLContext.getInstance("TLS");
+ *         // ... initialize from files
+ *     }
+ * }
+ * }</pre>
+ */
+public interface LocalFSWatchServiceListener {

Review Comment:
   This could also be annotated as `@Internal`



##########
flink-end-to-end-tests/flink-ssl-test/src/test/java/org/apache/flink/ssl/tests/SslNoReloadIT.java:
##########
@@ -0,0 +1,69 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.flink.ssl.tests;
+
+import org.apache.flink.tests.util.flink.ClusterController;
+
+import org.junit.Test;

Review Comment:
   Please try to use JUnit 5 here too



##########
flink-end-to-end-tests/flink-ssl-test/src/test/java/org/apache/flink/ssl/tests/NoSslNoReloadIT.java:
##########
@@ -0,0 +1,72 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.flink.ssl.tests;
+
+import org.apache.flink.tests.util.flink.ClusterController;
+
+import org.junit.Test;
+
+import java.io.IOException;
+import java.nio.file.attribute.FileTime;
+import java.util.Optional;
+
+import static org.junit.Assert.assertTrue;

Review Comment:
   Please try to use JUnit 5 assertions:
   
   ```
   import org.junit.jupiter.api.Test;
   ...
   import static org.assertj.core.api.Assertions.assertThat;
   
   ...
   
               assertThat(maybeCertDate)
                       .as("No certificates on rpc port should be accessible 
when SSL is disabled: " + maybeCertDate)
                       .isEmpty();
   ```



##########
flink-runtime/src/main/java/org/apache/flink/runtime/net/SSLUtils.java:
##########
@@ -418,37 +434,34 @@ public static SslContext createRestNettySSLContext(
             return null;
         }
 
-        String[] sslProtocols = getEnabledProtocols(config);
-        List<String> ciphers = Arrays.asList(getEnabledCipherSuites(config));
-
-        final SslContextBuilder sslContextBuilder;
-        if (clientMode) {
-            sslContextBuilder = SslContextBuilder.forClient();
-            if (clientAuth != ClientAuth.NONE) {
-                KeyManagerFactory kmf = getKeyManagerFactory(config, false, 
provider);
-                sslContextBuilder.keyManager(kmf);
+        // ssl context is loaded in constructor
+        ReloadableSslContext reloadableSslContext =
+                new ReloadableSslContext(config, clientMode, clientAuth, 
provider);
+
+        if (SecurityOptions.isCertificateReloadEnabled(config)) {
+            HashSet<Path> certificatePaths = new HashSet<>();
+            String keystoreFilePath =
+                    config.get(
+                            SecurityOptions.SSL_REST_KEYSTORE,
+                            config.get(SecurityOptions.SSL_KEYSTORE));
+            if (keystoreFilePath != null) {
+                certificatePaths.add(Path.of(keystoreFilePath).getParent());
+            }
+            String truststoreFilePath =
+                    config.get(
+                            SecurityOptions.SSL_REST_TRUSTSTORE,
+                            config.get(SecurityOptions.SSL_TRUSTSTORE));
+            if (truststoreFilePath != null) {
+                certificatePaths.add(Path.of(truststoreFilePath).getParent());
             }
-            sslContextBuilder.endpointIdentificationAlgorithm(
-                    config.get(SecurityOptions.SSL_REST_VERIFY_HOSTNAME) ? 
"HTTPS" : null);
-        } else {
-            KeyManagerFactory kmf = getKeyManagerFactory(config, false, 
provider);
-            sslContextBuilder = SslContextBuilder.forServer(kmf);
-        }
 
-        if (clientMode || clientAuth != ClientAuth.NONE) {
-            Optional<TrustManagerFactory> tmf = getTrustManagerFactory(config, 
false);
-            tmf.map(
-                    // Use specific ciphers and protocols if SSL is configured 
with self-signed
-                    // certificates (user-supplied truststore)
-                    tm ->
-                            sslContextBuilder
-                                    .trustManager(tm)
-                                    .protocols(sslProtocols)
-                                    .ciphers(ciphers)
-                                    .clientAuth(clientAuth));
+            Path[] pathsToWatch = new Path[certificatePaths.size()];
+            certificatePaths.toArray(pathsToWatch);

Review Comment:
   I think in any of the modern JVMs, it's unnecessary and slower to use 
pre-sized arrays, so it's safe to get rid of the unnecessary line:
   
   ```
   certificatePaths.toArray(Path[]::new);
   ```
   or
   ```
   certificatePaths.toArray(new Path[0]);
   ```



##########
flink-end-to-end-tests/flink-ssl-test/src/test/java/org/apache/flink/ssl/tests/SslWithReloadIT.java:
##########
@@ -0,0 +1,88 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.flink.ssl.tests;
+
+import org.apache.flink.tests.util.flink.ClusterController;
+
+import org.junit.Test;

Review Comment:
   Please try to use JUnit 5 here too



##########
flink-end-to-end-tests/flink-ssl-test/src/test/java/org/apache/flink/ssl/tests/SslEndToEndITCaseBase.java:
##########
@@ -0,0 +1,411 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.flink.ssl.tests;
+
+import org.apache.flink.configuration.BlobServerOptions;
+import org.apache.flink.configuration.Configuration;
+import org.apache.flink.configuration.JobManagerOptions;
+import org.apache.flink.configuration.SecurityOptions;
+import org.apache.flink.configuration.TaskManagerOptions;
+import org.apache.flink.tests.util.flink.FlinkResource;
+import org.apache.flink.tests.util.flink.FlinkResourceSetup;
+import org.apache.flink.tests.util.flink.LocalStandaloneFlinkResourceFactory;
+import org.apache.flink.util.TestLogger;
+
+import org.junit.BeforeClass;
+import org.junit.Rule;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.attribute.FileTime;
+import java.time.Duration;
+import java.util.Optional;
+
+import static org.junit.Assert.assertEquals;

Review Comment:
   Please try to use JUnit 5 here too



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