Skip to content

Commit 308e8f3

Browse files
Default to entitlements only for JDK 24+ (#119885) (#119974)
Since entitlements are still being developed, we are not yet ready to enable them for all JDK versions. But we must use them for JDK 24+ since the security manager is not useable there. This commit tweaks the logic for determining whether to use entitlements to take into account the runtime version. Co-authored-by: Elastic Machine <[email protected]>
1 parent fdc3208 commit 308e8f3

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

distribution/tools/server-cli/src/main/java/org/elasticsearch/server/cli/SystemJvmOptions.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
import org.elasticsearch.common.settings.Settings;
1313
import org.elasticsearch.common.util.concurrent.EsExecutors;
14+
import org.elasticsearch.core.Booleans;
1415
import org.elasticsearch.core.UpdateForV9;
1516
import org.elasticsearch.jdk.RuntimeVersionFeature;
1617

@@ -26,7 +27,9 @@ final class SystemJvmOptions {
2627
static List<String> systemJvmOptions(Settings nodeSettings, final Map<String, String> sysprops) {
2728
String distroType = sysprops.get("es.distribution.type");
2829
boolean isHotspot = sysprops.getOrDefault("sun.management.compiler", "").contains("HotSpot");
29-
boolean useEntitlements = Boolean.parseBoolean(sysprops.getOrDefault("es.entitlements.enabled", "false"));
30+
boolean entitlementsExplicitlyEnabled = Booleans.parseBoolean(sysprops.getOrDefault("es.entitlements.enabled", "false"));
31+
// java 24+ only supports entitlements, but it may be enabled on earlier versions explicitly
32+
boolean useEntitlements = RuntimeVersionFeature.isSecurityManagerAvailable() == false || entitlementsExplicitlyEnabled;
3033
return Stream.of(
3134
Stream.of(
3235
/*

server/src/main/java/org/elasticsearch/bootstrap/Elasticsearch.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import org.elasticsearch.common.transport.BoundTransportAddress;
2929
import org.elasticsearch.common.util.concurrent.RunOnce;
3030
import org.elasticsearch.core.AbstractRefCounted;
31+
import org.elasticsearch.core.Booleans;
3132
import org.elasticsearch.core.IOUtils;
3233
import org.elasticsearch.core.SuppressForbidden;
3334
import org.elasticsearch.entitlement.bootstrap.EntitlementBootstrap;
@@ -107,7 +108,9 @@ private static Bootstrap initPhase1() {
107108
final PrintStream out = getStdout();
108109
final PrintStream err = getStderr();
109110
final ServerArgs args;
110-
final boolean useEntitlements = Boolean.parseBoolean(System.getProperty("es.entitlements.enabled"));
111+
final boolean entitlementsExplicitlyEnabled = Booleans.parseBoolean(System.getProperty("es.entitlements.enabled", "false"));
112+
// java 24+ only supports entitlements, but it may be enabled on earlier versions explicitly
113+
final boolean useEntitlements = RuntimeVersionFeature.isSecurityManagerAvailable() == false || entitlementsExplicitlyEnabled;
111114
try {
112115
initSecurityProperties();
113116

0 commit comments

Comments
 (0)