From e682d8290c0f528fe1c53d544ac189bb067f4930 Mon Sep 17 00:00:00 2001 From: laiyousin Date: Tue, 26 Mar 2024 16:37:45 -0400 Subject: [PATCH] SUBMARINE-1417. Retrieve SUBMARINE_AUTH_SECRET from environment variable instead of using hard-coded value --- .../commons/utils/SubmarineConfVars.java | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/submarine-commons/commons-utils/src/main/java/org/apache/submarine/commons/utils/SubmarineConfVars.java b/submarine-commons/commons-utils/src/main/java/org/apache/submarine/commons/utils/SubmarineConfVars.java index f778bf5bd..815a9679b 100644 --- a/submarine-commons/commons-utils/src/main/java/org/apache/submarine/commons/utils/SubmarineConfVars.java +++ b/submarine-commons/commons-utils/src/main/java/org/apache/submarine/commons/utils/SubmarineConfVars.java @@ -23,6 +23,21 @@ public class SubmarineConfVars { private static final Logger LOG = LoggerFactory.getLogger(SubmarineConfVars.class); + /** + * Retrieves the secret from the environment variable "SUBMARINE_AUTH_DEFAULT_SECRET". + * Throws runtimeException if the environment variable is not set or empty. + * + * @return The secret as a String + */ + private static String getSecretFromEnv() { + String secret = System.getenv("SUBMARINE_AUTH_SECRET"); + if (secret == null || secret.isEmpty()) { + throw new RuntimeException( + "Environment variable SUBMARINE_JWT_SECRET is not set." + + "Please configure a secure key."); + } + return secret; + } public enum ConfVars { SUBMARINE_CONF_DIR("submarine.conf.dir", "conf"), SUBMARINE_LOCALIZATION_MAX_ALLOWED_FILE_SIZE_MB( @@ -93,7 +108,7 @@ public enum ConfVars { /* auth */ SUBMARINE_AUTH_TYPE("submarine.auth.type", "simple"), - SUBMARINE_AUTH_DEFAULT_SECRET("submarine.auth.default.secret", "SUBMARINE_SECRET_12345678901234567890"), + SUBMARINE_AUTH_DEFAULT_SECRET("submarine.auth.default.secret", getSecretFromEnv()), SUBMARINE_AUTH_MAX_AGE_ENV("submarine.auth.maxAge", 60 * 60 * 24); private String varName;