Skip to content

Commit 1f82273

Browse files
committed
Revert "Adjust Bootstrap and JVM options to ensure the SM is never used when entitlements are enabled (#119689)"
This reverts commit e4a4eb1.
1 parent e4a4eb1 commit 1f82273

File tree

4 files changed

+16
-36
lines changed

4 files changed

+16
-36
lines changed

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

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ static List<String> systemJvmOptions(Settings nodeSettings, final Map<String, St
7070
maybeSetActiveProcessorCount(nodeSettings),
7171
maybeSetReplayFile(distroType, isHotspot),
7272
maybeWorkaroundG1Bug(),
73-
maybeAllowSecurityManager(useEntitlements),
73+
maybeAllowSecurityManager(),
7474
maybeAttachEntitlementAgent(useEntitlements)
7575
).flatMap(s -> s).toList();
7676
}
@@ -148,12 +148,9 @@ private static Stream<String> maybeWorkaroundG1Bug() {
148148
return Stream.of();
149149
}
150150

151-
private static Stream<String> maybeAllowSecurityManager(boolean useEntitlements) {
152-
if (useEntitlements == false) {
153-
// Will become conditional on useEntitlements once entitlements can run without SM
154-
return Stream.of("-Djava.security.manager=allow");
155-
}
156-
return Stream.of();
151+
private static Stream<String> maybeAllowSecurityManager() {
152+
// Will become conditional on useEntitlements once entitlements can run without SM
153+
return Stream.of("-Djava.security.manager=allow");
157154
}
158155

159156
private static Stream<String> maybeAttachEntitlementAgent(boolean useEntitlements) {
@@ -175,16 +172,12 @@ private static Stream<String> maybeAttachEntitlementAgent(boolean useEntitlement
175172
} catch (IOException e) {
176173
throw new IllegalStateException("Failed to list entitlement jars in: " + dir, e);
177174
}
178-
// We instrument classes in these modules to call the bridge. Because the bridge gets patched
179-
// into java.base, we must export the bridge from java.base to these modules.
180-
String modulesContainingEntitlementInstrumentation = "java.logging";
181175
return Stream.of(
182176
"-Des.entitlements.enabled=true",
183177
"-XX:+EnableDynamicAgentLoading",
184178
"-Djdk.attach.allowAttachSelf=true",
185179
"--patch-module=java.base=" + bridgeJar,
186-
"--add-exports=java.base/org.elasticsearch.entitlement.bridge=org.elasticsearch.entitlement,"
187-
+ modulesContainingEntitlementInstrumentation
180+
"--add-exports=java.base/org.elasticsearch.entitlement.bridge=org.elasticsearch.entitlement"
188181
);
189182
}
190183
}

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

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ class Bootstrap {
3333

3434
// arguments from the CLI process
3535
private final ServerArgs args;
36-
private final boolean useEntitlements;
3736

3837
// controller for spawning component subprocesses
3938
private final Spawner spawner = new Spawner();
@@ -47,11 +46,10 @@ class Bootstrap {
4746
// loads information about plugins required for entitlements in phase 2, used by plugins service in phase 3
4847
private final SetOnce<PluginsLoader> pluginsLoader = new SetOnce<>();
4948

50-
Bootstrap(PrintStream out, PrintStream err, ServerArgs args, boolean useEntitlements) {
49+
Bootstrap(PrintStream out, PrintStream err, ServerArgs args) {
5150
this.out = out;
5251
this.err = err;
5352
this.args = args;
54-
this.useEntitlements = useEntitlements;
5553
}
5654

5755
ServerArgs args() {
@@ -62,10 +60,6 @@ Spawner spawner() {
6260
return spawner;
6361
}
6462

65-
public boolean useEntitlements() {
66-
return useEntitlements;
67-
}
68-
6963
void setSecureSettings(SecureSettings secureSettings) {
7064
this.secureSettings.set(secureSettings);
7165
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,7 @@ static List<BootstrapCheck> checks() {
211211
checks.add(new OnErrorCheck());
212212
checks.add(new OnOutOfMemoryErrorCheck());
213213
checks.add(new EarlyAccessCheck());
214+
checks.add(new AllPermissionCheck());
214215
checks.add(new DiscoveryConfiguredCheck());
215216
checks.add(new ByteOrderCheck());
216217
return Collections.unmodifiableList(checks);

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

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@
5151
import java.nio.file.Path;
5252
import java.security.Permission;
5353
import java.security.Security;
54-
import java.util.ArrayList;
5554
import java.util.List;
5655
import java.util.Objects;
5756
import java.util.concurrent.CountDownLatch;
@@ -106,7 +105,6 @@ private static Bootstrap initPhase1() {
106105
final PrintStream out = getStdout();
107106
final PrintStream err = getStderr();
108107
final ServerArgs args;
109-
final boolean useEntitlements = Boolean.parseBoolean(System.getProperty("es.entitlements.enabled"));
110108
try {
111109
initSecurityProperties();
112110

@@ -115,14 +113,12 @@ private static Bootstrap initPhase1() {
115113
* the presence of a security manager or lack thereof act as if there is a security manager present (e.g., DNS cache policy).
116114
* This forces such policies to take effect immediately.
117115
*/
118-
if (useEntitlements == false) {
119-
org.elasticsearch.bootstrap.Security.setSecurityManager(new SecurityManager() {
120-
@Override
121-
public void checkPermission(Permission perm) {
122-
// grant all permissions so that we can later set the security manager to the one that we want
123-
}
124-
});
125-
}
116+
org.elasticsearch.bootstrap.Security.setSecurityManager(new SecurityManager() {
117+
@Override
118+
public void checkPermission(Permission perm) {
119+
// grant all permissions so that we can later set the security manager to the one that we want
120+
}
121+
});
126122
LogConfigurator.registerErrorListener();
127123

128124
BootstrapInfo.init();
@@ -148,7 +144,7 @@ public void checkPermission(Permission perm) {
148144
return null; // unreachable, to satisfy compiler
149145
}
150146

151-
return new Bootstrap(out, err, args, useEntitlements);
147+
return new Bootstrap(out, err, args);
152148
}
153149

154150
/**
@@ -209,7 +205,7 @@ private static void initPhase2(Bootstrap bootstrap) throws IOException {
209205
var pluginsLoader = PluginsLoader.createPluginsLoader(nodeEnv.modulesFile(), nodeEnv.pluginsFile());
210206
bootstrap.setPluginsLoader(pluginsLoader);
211207

212-
if (bootstrap.useEntitlements()) {
208+
if (Boolean.parseBoolean(System.getProperty("es.entitlements.enabled"))) {
213209
LogManager.getLogger(Elasticsearch.class).info("Bootstrapping Entitlements");
214210

215211
List<EntitlementBootstrap.PluginData> pluginData = Stream.concat(
@@ -273,11 +269,7 @@ protected void validateNodeBeforeAcceptingRequests(
273269
final BoundTransportAddress boundTransportAddress,
274270
List<BootstrapCheck> checks
275271
) throws NodeValidationException {
276-
var additionalChecks = new ArrayList<>(checks);
277-
if (bootstrap.useEntitlements() == false) {
278-
additionalChecks.add(new BootstrapChecks.AllPermissionCheck());
279-
}
280-
BootstrapChecks.check(context, boundTransportAddress, additionalChecks);
272+
BootstrapChecks.check(context, boundTransportAddress, checks);
281273
}
282274
};
283275
INSTANCE = new Elasticsearch(bootstrap.spawner(), node);

0 commit comments

Comments
 (0)