Skip to content

Commit 8b2c63f

Browse files
committed
Minimal changes to permanently switch from SecurityManager to Entitlements
1 parent 34ec9f2 commit 8b2c63f

File tree

16 files changed

+54
-228
lines changed

16 files changed

+54
-228
lines changed

.buildkite/pipelines/pull-request/part-1-entitlements.yml

Lines changed: 0 additions & 11 deletions
This file was deleted.

.buildkite/pipelines/pull-request/part-2-entitlements.yml

Lines changed: 0 additions & 11 deletions
This file was deleted.

.buildkite/pipelines/pull-request/part-3-entitlements.yml

Lines changed: 0 additions & 11 deletions
This file was deleted.

.buildkite/pipelines/pull-request/part-4-entitlements.yml

Lines changed: 0 additions & 11 deletions
This file was deleted.

.buildkite/pipelines/pull-request/part-5-entitlements.yml

Lines changed: 0 additions & 11 deletions
This file was deleted.

build-tools/src/main/java/org/elasticsearch/gradle/testclusters/RunTask.java

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ public abstract class RunTask extends DefaultTestClustersTask {
4242

4343
private Boolean debug = false;
4444
private Boolean cliDebug = false;
45-
private Boolean entitlementsEnabled = false;
4645
private Boolean apmServerEnabled = false;
4746

4847
private Boolean preserveData = false;
@@ -70,14 +69,6 @@ public void setCliDebug(boolean enabled) {
7069
this.cliDebug = enabled;
7170
}
7271

73-
@Option(
74-
option = "entitlements",
75-
description = "Use the Entitlements agent system in place of SecurityManager to enforce sandbox policies."
76-
)
77-
public void setEntitlementsEnabled(boolean enabled) {
78-
this.entitlementsEnabled = enabled;
79-
}
80-
8172
@Input
8273
public Boolean getDebug() {
8374
return debug;
@@ -88,11 +79,6 @@ public Boolean getCliDebug() {
8879
return cliDebug;
8980
}
9081

91-
@Input
92-
public Boolean getEntitlementsEnabled() {
93-
return entitlementsEnabled;
94-
}
95-
9682
@Input
9783
public Boolean getApmServerEnabled() {
9884
return apmServerEnabled;
@@ -240,9 +226,6 @@ else if (node.getSettingKeys().contains("telemetry.metrics.enabled") == false) {
240226
if (cliDebug) {
241227
enableCliDebug();
242228
}
243-
if (entitlementsEnabled) {
244-
enableEntitlements();
245-
}
246229
}
247230

248231
@TaskAction

build-tools/src/main/java/org/elasticsearch/gradle/testclusters/TestClustersAware.java

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -88,12 +88,4 @@ default void enableCliDebug() {
8888
}
8989
}
9090
}
91-
92-
default void enableEntitlements() {
93-
for (ElasticsearchCluster cluster : getClusters()) {
94-
for (ElasticsearchNode node : cluster.getNodes()) {
95-
node.cliJvmArgs("-Des.entitlements.enabled=true");
96-
}
97-
}
98-
}
9991
}

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

Lines changed: 7 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@
1111

1212
import org.elasticsearch.common.settings.Settings;
1313
import org.elasticsearch.common.util.concurrent.EsExecutors;
14-
import org.elasticsearch.core.Booleans;
15-
import org.elasticsearch.jdk.RuntimeVersionFeature;
1614

1715
import java.io.IOException;
1816
import java.nio.file.Files;
@@ -27,9 +25,6 @@ final class SystemJvmOptions {
2725
static List<String> systemJvmOptions(Settings nodeSettings, final Map<String, String> sysprops) {
2826
String distroType = sysprops.get("es.distribution.type");
2927
boolean isHotspot = sysprops.getOrDefault("sun.management.compiler", "").contains("HotSpot");
30-
boolean entitlementsExplicitlyEnabled = Booleans.parseBoolean(sysprops.getOrDefault("es.entitlements.enabled", "true"));
31-
// java 24+ only supports entitlements, but it may be enabled on earlier versions explicitly
32-
boolean useEntitlements = RuntimeVersionFeature.isSecurityManagerAvailable() == false || entitlementsExplicitlyEnabled;
3328
return Stream.of(
3429
Stream.of(
3530
/*
@@ -71,13 +66,12 @@ static List<String> systemJvmOptions(Settings nodeSettings, final Map<String, St
7166
// Pass through distribution type
7267
"-Des.distribution.type=" + distroType
7368
),
74-
maybeEnableNativeAccess(useEntitlements),
69+
maybeEnableNativeAccess(),
7570
maybeOverrideDockerCgroup(distroType),
7671
maybeSetActiveProcessorCount(nodeSettings),
7772
maybeSetReplayFile(distroType, isHotspot),
7873
maybeWorkaroundG1Bug(),
79-
maybeAllowSecurityManager(useEntitlements),
80-
maybeAttachEntitlementAgent(useEntitlements)
74+
attachEntitlementAgent()
8175
).flatMap(s -> s).toList();
8276
}
8377

@@ -126,15 +120,13 @@ private static Stream<String> maybeSetActiveProcessorCount(Settings nodeSettings
126120
return Stream.empty();
127121
}
128122

129-
private static Stream<String> maybeEnableNativeAccess(boolean useEntitlements) {
123+
private static Stream<String> maybeEnableNativeAccess() {
130124
var enableNativeAccessOptions = new ArrayList<String>();
131125
if (Runtime.version().feature() >= 21) {
132126
enableNativeAccessOptions.add("--enable-native-access=org.elasticsearch.nativeaccess,org.apache.lucene.core");
133-
if (useEntitlements) {
134-
enableNativeAccessOptions.add("--enable-native-access=ALL-UNNAMED");
135-
if (Runtime.version().feature() >= 24) {
136-
enableNativeAccessOptions.add("--illegal-native-access=deny");
137-
}
127+
enableNativeAccessOptions.add("--enable-native-access=ALL-UNNAMED");
128+
if (Runtime.version().feature() >= 24) {
129+
enableNativeAccessOptions.add("--illegal-native-access=deny");
138130
}
139131
}
140132
return enableNativeAccessOptions.stream();
@@ -151,19 +143,7 @@ private static Stream<String> maybeWorkaroundG1Bug() {
151143
return Stream.of();
152144
}
153145

154-
private static Stream<String> maybeAllowSecurityManager(boolean useEntitlements) {
155-
if (RuntimeVersionFeature.isSecurityManagerAvailable()) {
156-
// Will become conditional on useEntitlements once entitlements can run without SM
157-
return Stream.of("-Djava.security.manager=allow");
158-
}
159-
return Stream.of();
160-
}
161-
162-
private static Stream<String> maybeAttachEntitlementAgent(boolean useEntitlements) {
163-
if (useEntitlements == false) {
164-
return Stream.empty();
165-
}
166-
146+
private static Stream<String> attachEntitlementAgent() {
167147
Path dir = Path.of("lib", "entitlement-bridge");
168148
if (Files.exists(dir) == false) {
169149
throw new IllegalStateException("Directory for entitlement bridge jar does not exist: " + dir);
@@ -182,7 +162,6 @@ private static Stream<String> maybeAttachEntitlementAgent(boolean useEntitlement
182162
// into java.base, we must export the bridge from java.base to these modules, as a comma-separated list
183163
String modulesContainingEntitlementInstrumentation = "java.logging,java.net.http,java.naming,jdk.net";
184164
return Stream.of(
185-
"-Des.entitlements.enabled=true",
186165
"-XX:+EnableDynamicAgentLoading",
187166
"-Djdk.attach.allowAttachSelf=true",
188167
"--patch-module=java.base=" + bridgeJar,

libs/entitlement/qa/src/javaRestTest/java/org/elasticsearch/entitlement/qa/EntitlementsTestRule.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,6 @@ protected void before() throws Throwable {
7373
cluster = ElasticsearchCluster.local()
7474
.module("entitled", spec -> buildEntitlements(spec, "org.elasticsearch.entitlement.qa.entitled", ENTITLED_POLICY))
7575
.module("entitlement-test-plugin", spec -> setupEntitlements(spec, modular, policyBuilder))
76-
.systemProperty("es.entitlements.enabled", "true")
7776
.systemProperty("es.entitlements.testdir", () -> testDir.getRoot().getAbsolutePath())
7877
.setting("xpack.security.enabled", "false")
7978
// Logs in libs/entitlement/qa/build/test-results/javaRestTest/TEST-org.elasticsearch.entitlement.qa.EntitlementsXXX.xml

modules/analysis-common/build.gradle

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,11 @@ tasks.named("yamlRestCompatTestTransform").configure { task ->
3838
}
3939

4040
tasks.named("yamlRestTest").configure {
41-
if (buildParams.getRuntimeJavaVersion().map{ it.majorVersion.toInteger() }.get() >= 24 ||
42-
"-Des.entitlements.enabled=true".equals(System.getProperty("tests.jvm.argline"))) {
43-
systemProperty 'tests.rest.blacklist',
44-
[
45-
// AWAITSFIX: this test relies on security manager, which doesn't exist in JDK 24.
46-
// and entitlements don't yet replace the functionality.
47-
// see https://github.com/elastic/elasticsearch/issues/119130
48-
'analysis-common/40_token_filters/stemmer_override file access',
49-
].join(',')
50-
}
41+
systemProperty 'tests.rest.blacklist',
42+
[
43+
// AWAITSFIX: this test relies on security manager, which doesn't exist in JDK 24.
44+
// and entitlements don't yet replace the functionality.
45+
// see https://github.com/elastic/elasticsearch/issues/119130
46+
'analysis-common/40_token_filters/stemmer_override file access',
47+
].join(',')
5148
}

0 commit comments

Comments
 (0)