Skip to content

Commit ba36d5c

Browse files
author
bitflicker64
committed
fix(server): reject security check on JDK 24+
JDK 24 removed the Security Manager (JEP 486), so '-Djava.security.manager=allow' is a fatal VM initialization error and System.setSecurityManager() always throws. Fail the launcher with an actionable message instead of a cryptic VM error, and keep the security-disabled path unchanged. Also assert a positive downstream signal in the launcher success and security-disabled tests, so an unrelated failure such as a missing bootstrap class can no longer pass, and report the underlying cause when bootstrap validation fails.
1 parent 0a07cd8 commit ba36d5c

3 files changed

Lines changed: 66 additions & 4 deletions

File tree

hugegraph-server/hugegraph-dist/src/assembly/static/bin/hugegraph-server.sh

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,10 @@ ensure_path_writable "$PLUGINS"
6464
MAX_MEM=$((32 * 1024))
6565
MIN_MEM=$((1 * 512))
6666
MIN_JAVA_VERSION=11
67+
# JDK 24 removed the Security Manager (JEP 486): "-Djava.security.manager=allow"
68+
# is a fatal VM initialization error there and System.setSecurityManager() always
69+
# throws, so HugeSecurityManager cannot be installed on newer runtimes.
70+
MAX_SECURITY_JAVA_VERSION=23
6771

6872
# Add the slf4j-log4j12 binding
6973
CP=$(find -L $LIB -name 'log4j-slf4j-impl*.jar' | sort | tr '\n' ':')
@@ -144,6 +148,19 @@ esac
144148
JVM_OPTIONS="-Dlog4j.configurationFile=${CONF}/log4j2.xml"
145149
SECURITY_MANAGER_OPTION=""
146150
if [[ ${OPEN_SECURITY_CHECK} == "true" ]]; then
151+
if [[ ${JAVA_VERSION} -gt ${MAX_SECURITY_JAVA_VERSION} ]]; then
152+
SECURITY_UNSUPPORTED_MSG=$(cat <<EOF
153+
The security check requires Java ${MIN_JAVA_VERSION}-${MAX_SECURITY_JAVA_VERSION}, current is ${JAVA_VERSION}.
154+
JDK 24+ removed the Security Manager (JEP 486), so HugeSecurityManager can no longer be installed.
155+
Run the server on Java ${MAX_SECURITY_JAVA_VERSION} or lower, or start it with the security check
156+
disabled: 'start-hugegraph.sh -s false'.
157+
EOF
158+
)
159+
echo "${SECURITY_UNSUPPORTED_MSG}" >&2
160+
echo "${SECURITY_UNSUPPORTED_MSG}" >> "${OUTPUT}"
161+
exit 1
162+
fi
163+
147164
SECURITY_PROPERTIES="${CONF}/java-security.properties"
148165
JVM_OPTIONS="${JVM_OPTIONS} \
149166
-Djava.security.properties=${SECURITY_PROPERTIES}"

hugegraph-server/hugegraph-dist/src/assembly/travis/test-java-security-properties.sh

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,19 @@ assert_invalid_security_properties() {
111111
fi
112112
}
113113

114+
# The bootstrap only hands over to HugeGraphServer once the DNS TTL check and
115+
# the HugeSecurityManager installation have both succeeded, so this downstream
116+
# configuration failure is a positive signal instead of merely a nonzero exit.
117+
assert_reached_server_startup() {
118+
local error_file="$1"
119+
local message="$2"
120+
grep -Fq "Failed to load yaml config file" "$error_file" || fail "$message"
121+
grep -Fq "org.apache.hugegraph.bootstrap.HugeGraphServerBootstrap.main" \
122+
"$error_file" || fail "$message"
123+
grep -Fq "org.apache.hugegraph.dist.HugeGraphServer.main" \
124+
"$error_file" || fail "$message"
125+
}
126+
114127
assert_clean_bootstrap_error() {
115128
local error_file="$1"
116129
if grep -Eq 'Log4j|NetUtils|UnknownHost|hostname' "$error_file"; then
@@ -215,6 +228,8 @@ assert_launcher_accepts_security_properties() {
215228
"$error_file"; then
216229
fail "launcher rejected valid Java security properties"
217230
fi
231+
assert_reached_server_startup "$error_file" \
232+
"valid Java security properties did not reach server startup"
218233
}
219234

220235
assert_launcher_skips_security_validation() {
@@ -230,6 +245,8 @@ assert_launcher_skips_security_validation() {
230245
if grep -Fq "networkaddress.cache.ttl must load" "$error_file"; then
231246
fail "disabled launcher unexpectedly validated DNS TTL"
232247
fi
248+
assert_reached_server_startup "$error_file" \
249+
"disabled security check did not reach server startup"
233250
}
234251

235252
ACTUAL_TTL=$("$JAVA_BIN" \
@@ -381,6 +398,34 @@ if [[ "$LAST_SECURITY_MANAGER_ARGUMENT" != \
381398
fail "operator option overrode the JDK 18+ security manager allowance"
382399
fi
383400

401+
JDK23_CAPTURE="${TEMP_DIR}/jdk23.args"
402+
CAPTURE_FILE="$JDK23_CAPTURE" JAVA_HOME="$MOCK_JAVA_HOME" \
403+
MOCK_JAVA_VERSION=23 STDOUT_MODE=true "$SERVER_SCRIPT" \
404+
"${CONF}/gremlin-server.yaml" "${CONF}/rest-server.properties" true >/dev/null
405+
406+
assert_argument "-Djava.security.manager=allow" "$JDK23_CAPTURE"
407+
assert_argument \
408+
"-Djava.security.properties=${SECURITY_PROPERTIES}" "$JDK23_CAPTURE"
409+
410+
JDK24_ERROR="${TEMP_DIR}/jdk24.err"
411+
if JAVA_HOME="$MOCK_JAVA_HOME" MOCK_JAVA_VERSION=24 STDOUT_MODE=true \
412+
"$SERVER_SCRIPT" "${CONF}/gremlin-server.yaml" \
413+
"${CONF}/rest-server.properties" true >/dev/null 2>"$JDK24_ERROR"; then
414+
fail "launcher accepted a security-enabled JDK 24 runtime"
415+
fi
416+
grep -Fq "JDK 24+ removed the Security Manager" "$JDK24_ERROR" ||
417+
fail "launcher did not explain the JDK 24 security incompatibility"
418+
419+
JDK24_DISABLED_CAPTURE="${TEMP_DIR}/jdk24-disabled.args"
420+
CAPTURE_FILE="$JDK24_DISABLED_CAPTURE" JAVA_HOME="$MOCK_JAVA_HOME" \
421+
MOCK_JAVA_VERSION=24 STDOUT_MODE=true "$SERVER_SCRIPT" \
422+
"${CONF}/gremlin-server.yaml" "${CONF}/rest-server.properties" false \
423+
>/dev/null
424+
425+
assert_no_argument '^-Djava\.security\.manager=' "$JDK24_DISABLED_CAPTURE"
426+
assert_no_argument '^-Djava\.security\.properties=' "$JDK24_DISABLED_CAPTURE"
427+
assert_argument "false" "$JDK24_DISABLED_CAPTURE"
428+
384429
DISABLED_CAPTURE="${TEMP_DIR}/disabled.args"
385430
CAPTURE_FILE="$DISABLED_CAPTURE" JAVA_HOME="$MOCK_JAVA_HOME" \
386431
STDOUT_MODE=true "$SERVER_SCRIPT" \

hugegraph-server/hugegraph-dist/src/main/java/org/apache/hugegraph/bootstrap/HugeGraphServerBootstrap.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,10 @@ public static void main(String[] args) throws Exception {
3939
try {
4040
validateDnsCacheTtl(
4141
Security.getProperty("networkaddress.cache.ttl"));
42-
} catch (Throwable ignored) {
42+
} catch (Throwable e) {
4343
System.err.println("ERROR: Java security property " +
4444
"networkaddress.cache.ttl must load as a " +
45-
"finite positive integer");
45+
"finite positive integer: " + e);
4646
System.exit(1);
4747
return;
4848
}
@@ -54,9 +54,9 @@ public static void main(String[] args) throws Exception {
5454
throw new IllegalStateException(
5555
"Unexpected security manager");
5656
}
57-
} catch (Throwable ignored) {
57+
} catch (Throwable e) {
5858
System.err.println("ERROR: Failed to install " +
59-
"HugeSecurityManager");
59+
"HugeSecurityManager: " + e);
6060
System.exit(1);
6161
return;
6262
}

0 commit comments

Comments
 (0)