This is an automated email from the ASF dual-hosted git repository.

rzo1 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/storm.git


The following commit(s) were added to refs/heads/master by this push:
     new 075389a394 Infer UI, DRPC and logviewer HTTPS store types from the 
file extension (#9287)
075389a394 is described below

commit 075389a394074decbad87e394c1328d0354efa36
Author: 龙骑士k <[email protected]>
AuthorDate: Mon Nov 23 18:42:14 2026 +0000

    Infer UI, DRPC and logviewer HTTPS store types from the file extension 
(#9287)
    
    * Infer UI, DRPC and logviewer HTTPS store types from the file extension
    
    Closes issue 7742
    
    ## What is the purpose of the change
    
    When `*.https.keystore.type` or `*.https.truststore.type` is not set, the 
UI, DRPC and logviewer HTTPS connectors now infer the type from the file 
extension, the same way `ThriftClient` and `ReloadableX509KeyManager` already 
do.
    
    - Configurations that set a type keep their behavior.
    - `.jks` is read as JKS, and `.p12`, `.pkcs12` or `.pfx` is read as PKCS12.
    - A keystore with any other extension falls back to JKS.
    - A truststore with any other extension and no type is still not used.
    
    With `drpc.https.keystore.type: "JKS"` in `defaults.yaml`, a DRPC type 
always counts as configured, so the entry is removed. The JKS fallback keeps 
the old DRPC result for files that have no known extension.
    
    The change is in `UIHelpers.mkSslConnector`, the one place the three 
daemons build their HTTPS connector. `ReloadableX509TrustManager` is not 
changed, because with the JDK default `keystore.type.compat=true` its 
default-type `KeyStore` already loads both JKS and PKCS12 files.
    
    ## How was the change tested
    
    New `UIHelpersTest` cases use keystores generated at test time with 
`keytool`:
    
    - With no types set, a `.p12` keystore is read as PKCS12 and a `.jks` 
truststore as JKS, and the SSL context starts with both files.
    - With no type set, a keystore with an unknown extension is read as JKS.
    - With no type set, a truststore with an unknown extension is not used.
    - Explicit types win over the extension.
    
    The first two cases fail without the change in `UIHelpers`, because the 
store type stays null.
    
    ## Upgrade notes
    
    - UI and logviewer HTTPS with no keystore type set used to fail at startup. 
They now start, using the inferred type or JKS.
    - A truststore with a path and password but no type used to be ignored, so 
Jetty validated client certificates against the keystore entries. It is now 
used when its extension is `.jks`, `.p12`, `.pkcs12` or `.pfx`. Deployments 
with client auth enabled then validate client certificates against the 
truststore and can reject clients that only the keystore trusted.
    - DRPC with no keystore type set now reads a `.p12`, `.pkcs12` or `.pfx` 
keystore as PKCS12 instead of JKS. With the JDK default 
`keystore.type.compat=true` this has no visible effect, because both types load 
both formats.
    
    ## AI Disclosure
    
    Human-led contribution. Grok Bot, working for dragonknightk, assisted with 
this change, including the code, tests, and description. All submitted content 
was reviewed by a human before submission.
    
    Signed-off-by: dragonknightk 
<[email protected]>
    
    * Fall back to JKS for an HTTPS truststore with an unknown extension
    
    Closes issue 7742
    
    ## What is the purpose of the change
    
    When `*.https.keystore.type` or `*.https.truststore.type` is not set, the 
UI, DRPC and logviewer HTTPS connectors now infer the type from the file 
extension, the same way `ThriftClient` and `ReloadableX509KeyManager` already 
do.
    
    - Configurations that set a type keep their behavior.
    - `.jks` is read as JKS, and `.p12`, `.pkcs12` or `.pfx` is read as PKCS12.
    - A keystore or truststore with any other extension falls back to JKS, as 
in the Thrift TLS transport.
    
    With `drpc.https.keystore.type: "JKS"` in `defaults.yaml`, a DRPC type 
always counts as configured, so the entry is removed. The JKS fallback keeps 
the old DRPC result for files that have no known extension.
    
    The change is in `UIHelpers.mkSslConnector`, the one place the three 
daemons build their HTTPS connector. `ReloadableX509TrustManager` is not 
changed, because with the JDK default `keystore.type.compat=true` its 
default-type `KeyStore` already loads both JKS and PKCS12 files.
    
    ## How was the change tested
    
    New `UIHelpersTest` cases use keystores generated at test time with 
`keytool`:
    
    - With no types set, a `.p12` keystore is read as PKCS12 and a `.jks` 
truststore as JKS, and the SSL context starts with both files.
    - With no type set, a keystore with an unknown extension is read as JKS.
    - With no type set, a truststore with an unknown extension is read as JKS, 
and the SSL context loads it even though the file holds PKCS12.
    - Explicit types win over the extension.
    
    The first three cases fail without the change in `UIHelpers`: the keystore 
type stays null and the truststore is not used.
    
    ## Upgrade notes
    
    - UI and logviewer HTTPS with no keystore type set used to fail at startup. 
They now start, using the inferred type or JKS.
    - A truststore with a path and password but no type used to be ignored, so 
Jetty validated client certificates against the keystore entries. It is now 
used, with the type inferred from its extension or JKS otherwise. Deployments 
with client auth enabled then validate client certificates against the 
truststore and can reject clients that only the keystore trusted.
    - DRPC with no keystore type set now reads a `.p12`, `.pkcs12` or `.pfx` 
keystore as PKCS12 instead of JKS. With the JDK default 
`keystore.type.compat=true` this has no visible effect, because both types load 
both formats.
    
    ## AI Disclosure
    
    Human-led contribution. Grok Bot, working for dragonknightk, assisted with 
this change, including the code, tests, and description. All submitted content 
was reviewed by a human before submission.
    
    Signed-off-by: dragonknightk 
<[email protected]>
    
    ---------
    
    Signed-off-by: dragonknightk 
<[email protected]>
---
 SECURITY.md                                        |   2 +
 conf/defaults.yaml                                 |   1 -
 docs/SECURITY.md                                   |   2 +
 .../main/java/org/apache/storm/DaemonConfig.java   |   6 ++
 .../java/org/apache/storm/daemon/ui/UIHelpers.java |  19 +++-
 .../org/apache/storm/daemon/ui/UIHelpersTest.java  | 107 +++++++++++++++++++++
 6 files changed, 133 insertions(+), 4 deletions(-)

diff --git a/SECURITY.md b/SECURITY.md
index 661ab24f5a..61b524a87f 100644
--- a/SECURITY.md
+++ b/SECURITY.md
@@ -97,6 +97,8 @@ curl  -i --negotiate -u:anyUser  -b ~/cookiejar.txt -c 
~/cookiejar.txt  http://s
 
 Both UI and DRPC allow users to configure ssl.
 
+The `*.https.keystore.type` and `*.https.truststore.type` configs are 
optional. See [UI / DRPC / LOGVIEWER 
SSL](docs/SECURITY.md#ui--drpc--logviewer-ssl) for how the type is chosen when 
it is not set.
+
 ### UI
 
 For UI, set the following config in `storm.yaml`. Generating keystores with 
proper keys and certs should be taken care of by the user before this step.
diff --git a/conf/defaults.yaml b/conf/defaults.yaml
index 3b49c151e6..993fc9ecb1 100644
--- a/conf/defaults.yaml
+++ b/conf/defaults.yaml
@@ -154,7 +154,6 @@ drpc.childopts: "-Xmx768m"
 drpc.http.port: 3774
 drpc.https.port: -1
 drpc.https.keystore.password: ""
-drpc.https.keystore.type: "JKS"
 drpc.http.creds.plugin: 
org.apache.storm.security.auth.DefaultHttpCredentialsPlugin
 drpc.authorizer.acl.filename: "drpc-auth-acl.yaml"
 drpc.authorizer.acl.strict: false
diff --git a/docs/SECURITY.md b/docs/SECURITY.md
index a46be6a49c..f6957971a4 100644
--- a/docs/SECURITY.md
+++ b/docs/SECURITY.md
@@ -126,6 +126,8 @@ The `drpc.http.creds.plugin` config can be used in cases 
where the default plugi
 
 UI,DRPC and LOGVIEWER allows users to configure ssl .
 
+The `*.https.keystore.type` and `*.https.truststore.type` configs are 
optional. A configured type is always used. When a type is not set, it is 
inferred from the file extension: `.jks` is read as JKS, and `.p12`, `.pkcs12` 
or `.pfx` is read as PKCS12. A keystore or truststore with any other extension 
is read as JKS.
+
 ### UI
 
 These configurations enable HTTPS for the Storm UI, allowing secure 
communication between users and the cluster.
diff --git a/storm-server/src/main/java/org/apache/storm/DaemonConfig.java 
b/storm-server/src/main/java/org/apache/storm/DaemonConfig.java
index c360559b2a..bf544501e2 100644
--- a/storm-server/src/main/java/org/apache/storm/DaemonConfig.java
+++ b/storm-server/src/main/java/org/apache/storm/DaemonConfig.java
@@ -495,6 +495,7 @@ public class DaemonConfig implements Validated {
     /**
      * Type of the keystore for HTTPS for Storm Logviewer. see 
http://docs.oracle.com/javase/8/docs/api/java/security/KeyStore.html for more
      * details.
+     * If unset, it is inferred from the file extension, falling back to JKS. 
See docs/SECURITY.md.
      */
     @IsString
     public static final String LOGVIEWER_HTTPS_KEYSTORE_TYPE = 
"logviewer.https.keystore.type";
@@ -522,6 +523,7 @@ public class DaemonConfig implements Validated {
     /**
      * Type of the truststore for HTTPS for Storm Logviewer. see 
http://docs.oracle.com/javase/8/docs/api/java/security/Truststore.html for
      * more details.
+     * If unset, it is inferred from the file extension, falling back to JKS. 
See docs/SECURITY.md.
      */
     @IsString
     public static final String LOGVIEWER_HTTPS_TRUSTSTORE_TYPE = 
"logviewer.https.truststore.type";
@@ -620,6 +622,7 @@ public class DaemonConfig implements Validated {
      * Type of keystore used by Storm UI for setting up HTTPS (SSL). see 
http://docs.oracle.com/javase/7/docs/api/java/security/KeyStore
      * .html
      * for more details.
+     * If unset, it is inferred from the file extension, falling back to JKS. 
See docs/SECURITY.md.
      */
     @IsString
     public static final String UI_HTTPS_KEYSTORE_TYPE = 
"ui.https.keystore.type";
@@ -648,6 +651,7 @@ public class DaemonConfig implements Validated {
      * Type of truststore used by Storm UI for setting up HTTPS (SSL). see 
http://docs.oracle
      * .com/javase/7/docs/api/java/security/KeyStore.html
      * for more details.
+     * If unset, it is inferred from the file extension, falling back to JKS. 
See docs/SECURITY.md.
      */
     @IsString
     public static final String UI_HTTPS_TRUSTSTORE_TYPE = 
"ui.https.truststore.type";
@@ -719,6 +723,7 @@ public class DaemonConfig implements Validated {
      * Type of keystore used by Storm DRPC for setting up HTTPS (SSL). see 
http://docs.oracle
      * .com/javase/7/docs/api/java/security/KeyStore.html
      * for more details.
+     * If unset, it is inferred from the file extension, falling back to JKS. 
See docs/SECURITY.md.
      */
     @IsString
     public static final String DRPC_HTTPS_KEYSTORE_TYPE = 
"drpc.https.keystore.type";
@@ -747,6 +752,7 @@ public class DaemonConfig implements Validated {
      * Type of truststore used by Storm DRPC for setting up HTTPS (SSL). see 
http://docs.oracle
      * .com/javase/7/docs/api/java/security/KeyStore.html
      * for more details.
+     * If unset, it is inferred from the file extension, falling back to JKS. 
See docs/SECURITY.md.
      */
     @IsString
     public static final String DRPC_HTTPS_TRUSTSTORE_TYPE = 
"drpc.https.truststore.type";
diff --git 
a/storm-webapp/src/main/java/org/apache/storm/daemon/ui/UIHelpers.java 
b/storm-webapp/src/main/java/org/apache/storm/daemon/ui/UIHelpers.java
index 42d5c9a00a..8c2a870621 100644
--- a/storm-webapp/src/main/java/org/apache/storm/daemon/ui/UIHelpers.java
+++ b/storm-webapp/src/main/java/org/apache/storm/daemon/ui/UIHelpers.java
@@ -93,6 +93,7 @@ import org.apache.storm.thrift.TException;
 import org.apache.storm.utils.ConfigUtils;
 import org.apache.storm.utils.IVersionInfo;
 import org.apache.storm.utils.ObjectReader;
+import org.apache.storm.utils.SecurityUtils;
 import org.apache.storm.utils.Time;
 import org.apache.storm.utils.TopologySpoutLag;
 import org.apache.storm.utils.Utils;
@@ -227,6 +228,18 @@ public class UIHelpers {
             "errorMessage", String.format("User %s is not authorized.", user));
     }
 
+    /**
+     * An explicitly configured store type is used as is. Otherwise the type 
is inferred from the
+     * file extension, falling back to JKS like the Thrift TLS transport does.
+     */
+    private static String storeType(String configuredType, String path) {
+        if (configuredType != null) {
+            return configuredType;
+        }
+        String inferredType = SecurityUtils.inferKeyStoreTypeFromPath(path);
+        return inferredType != null ? inferredType : "JKS";
+    }
+
     private static ServerConnector mkSslConnector(Server server, Integer port, 
String ksPath,
                                                   String ksPassword, String 
ksType,
                                                   String keyPassword, String 
tsPath,
@@ -239,13 +252,13 @@ public class UIHelpers {
         factory.addExcludeProtocols("SSLv3");
         factory.setRenegotiationAllowed(false);
         factory.setKeyStorePath(ksPath);
-        factory.setKeyStoreType(ksType);
+        factory.setKeyStoreType(storeType(ksType, ksPath));
         factory.setKeyStorePassword(ksPassword);
         factory.setKeyManagerPassword(keyPassword);
 
-        if (tsPath != null && tsPassword != null && tsType != null) {
+        if (tsPath != null && tsPassword != null) {
             factory.setTrustStorePath(tsPath);
-            factory.setTrustStoreType(tsType);
+            factory.setTrustStoreType(storeType(tsType, tsPath));
             factory.setTrustStorePassword(tsPassword);
         }
 
diff --git 
a/storm-webapp/src/test/java/org/apache/storm/daemon/ui/UIHelpersTest.java 
b/storm-webapp/src/test/java/org/apache/storm/daemon/ui/UIHelpersTest.java
index 09a31f2440..cfe977f132 100644
--- a/storm-webapp/src/test/java/org/apache/storm/daemon/ui/UIHelpersTest.java
+++ b/storm-webapp/src/test/java/org/apache/storm/daemon/ui/UIHelpersTest.java
@@ -41,8 +41,11 @@ import org.junit.jupiter.api.BeforeEach;
 import org.junit.jupiter.api.Test;
 import org.junit.jupiter.api.io.TempDir;
 
+import java.io.InputStream;
 import java.nio.file.Files;
 import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.security.KeyStore;
 import java.util.Arrays;
 import java.util.HashMap;
 import java.util.LinkedHashSet;
@@ -727,6 +730,110 @@ class UIHelpersTest {
         assertEquals(expectedCiphers, new 
LinkedHashSet<>(Arrays.asList(factory.getExcludeCipherSuites())));
     }
 
+    /**
+     * Creates a real keystore holding one self-signed key pair with the JDK 
keytool.
+     */
+    private static Path createKeyStore(Path dir, String fileName, String 
storeType) throws Exception {
+        Path keyStore = dir.resolve(fileName);
+        String keytool = Paths.get(System.getProperty("java.home"), "bin", 
"keytool").toString();
+        Process process = new ProcessBuilder(keytool, "-genkeypair", "-alias", 
"test", "-keyalg", "RSA",
+                "-keysize", "2048", "-dname", "CN=localhost", "-storetype", 
storeType,
+                "-keystore", keyStore.toString(), "-storepass", "password", 
"-keypass", "password")
+                .redirectErrorStream(true)
+                .start();
+        String output = new String(process.getInputStream().readAllBytes());
+        assertEquals(0, process.waitFor(), output);
+        return keyStore;
+    }
+
+    private static SslContextFactory.Server sslContextFactory(Server server) {
+        ServerConnector connector = (ServerConnector) 
server.getConnectors()[0];
+        return (SslContextFactory.Server) 
connector.getConnectionFactory(SslConnectionFactory.class)
+                .getSslContextFactory();
+    }
+
+    @Test
+    public void testConfigSslInfersStoreTypesFromExtension(@TempDir Path 
tempDir) throws Exception {
+        // Expected behavior from issue 7742: without a configured type, a 
keystore or truststore
+        // ending in .p12 is read as PKCS12 and one ending in .jks is read as 
JKS.
+        Path pkcs12KeyStore = createKeyStore(tempDir, "keystore.p12", 
"PKCS12");
+        Path jksTrustStore = createKeyStore(tempDir, "truststore.jks", "JKS");
+        Server server = new Server();
+        UIHelpers.configSsl(server, 8443, pkcs12KeyStore.toString(), 
"password", null, "password",
+                jksTrustStore.toString(), "password", null, false, false, 
false);
+
+        SslContextFactory.Server factory = sslContextFactory(server);
+        assertEquals("PKCS12", factory.getKeyStoreType());
+        assertEquals("JKS", factory.getTrustStoreType());
+        assertNotNull(factory.getTrustStorePath());
+        // Starting the factory loads both files with the inferred types
+        factory.start();
+        try {
+            assertEquals("PKCS12", factory.getKeyStore().getType());
+            assertEquals("JKS", factory.getTrustStore().getType());
+        } finally {
+            factory.stop();
+        }
+    }
+
+    @Test
+    public void 
testConfigSslKeystoreFallsBackToJksForUnknownExtension(@TempDir Path tempDir) 
throws Exception {
+        // drpc.https.keystore.type used to default to "JKS" in defaults.yaml. 
Without a configured
+        // type and without a known extension the keystore is still read as 
JKS.
+        Path keyStore = createKeyStore(tempDir, "keystore.dat", "JKS");
+        Server server = new Server();
+        UIHelpers.configSsl(server, 8443, keyStore.toString(), "password", 
null, "password",
+                null, null, null, false, false, false);
+
+        SslContextFactory.Server factory = sslContextFactory(server);
+        assertEquals("JKS", factory.getKeyStoreType());
+        assertNull(factory.getTrustStorePath());
+    }
+
+    @Test
+    public void 
testConfigSslTruststoreFallsBackToJksForUnknownExtension(@TempDir Path tempDir) 
throws Exception {
+        // A truststore with a path and password must not be ignored just 
because its extension is
+        // unknown. Like the keystore, it falls back to JKS. With the JDK 
default
+        // keystore.type.compat=true the JKS type also loads this PKCS12 file. 
The keystore is PKCS12,
+        // so a JKS truststore cannot be Jetty's fallback to the keystore.
+        Path keyStore = createKeyStore(tempDir, "keystore.p12", "PKCS12");
+        Path trustStore = createKeyStore(tempDir, "truststore.dat", "PKCS12");
+        Server server = new Server();
+        UIHelpers.configSsl(server, 8443, keyStore.toString(), "password", 
null, "password",
+                trustStore.toString(), "password", null, false, false, false);
+
+        SslContextFactory.Server factory = sslContextFactory(server);
+        assertNotNull(factory.getTrustStorePath());
+        factory.start();
+        try {
+            assertNotNull(factory.getTrustStore());
+            assertEquals("JKS", factory.getTrustStore().getType());
+            // Both files use the alias "test" with different key pairs, so 
this proves the
+            // configured truststore file was loaded.
+            KeyStore expected = KeyStore.getInstance("PKCS12");
+            try (InputStream in = Files.newInputStream(trustStore)) {
+                expected.load(in, "password".toCharArray());
+            }
+            assertEquals(expected.getCertificate("test"), 
factory.getTrustStore().getCertificate("test"));
+        } finally {
+            factory.stop();
+        }
+    }
+
+    @Test
+    public void testConfigSslKeepsExplicitStoreTypes(@TempDir Path tempDir) 
throws Exception {
+        // A configured type must win over the extension, so existing 
configurations keep working.
+        Path keyStore = createKeyStore(tempDir, "keystore.p12", "PKCS12");
+        Path trustStore = createKeyStore(tempDir, "truststore.jks", "JKS");
+        Server server = new Server();
+        UIHelpers.configSsl(server, 8443, keyStore.toString(), "password", 
"JKS", "password",
+                trustStore.toString(), "password", "PKCS12", false, false, 
false);
+
+        SslContextFactory.Server factory = sslContextFactory(server);
+        assertEquals("JKS", factory.getKeyStoreType());
+        assertEquals("PKCS12", factory.getTrustStoreType());
+    }
+
     @Test
     public void testCorsFilterHandleSetsExplicitInitParameters() {
         FilterHolder filterHolder = UIHelpers.corsFilterHandle();

Reply via email to