Skip to content

Commit 1588d54

Browse files
authored
Remove entitlements flag from startup (elastic#127652)
Entitlements are now always enabled, so we no longer need a flag. This commit also removes the now defunct bootstrap check that ensured AllPermission was never granted in the SM policy.
1 parent 62b2e86 commit 1588d54

File tree

4 files changed

+3
-69
lines changed

4 files changed

+3
-69
lines changed

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: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
import org.elasticsearch.core.SuppressForbidden;
2222
import org.elasticsearch.discovery.DiscoveryModule;
2323
import org.elasticsearch.index.IndexModule;
24-
import org.elasticsearch.jdk.RuntimeVersionFeature;
2524
import org.elasticsearch.monitor.jvm.JvmInfo;
2625
import org.elasticsearch.monitor.process.ProcessProbe;
2726
import org.elasticsearch.nativeaccess.NativeAccess;
@@ -33,7 +32,6 @@
3332
import java.nio.ByteOrder;
3433
import java.nio.file.Files;
3534
import java.nio.file.Path;
36-
import java.security.AllPermission;
3735
import java.util.ArrayList;
3836
import java.util.Arrays;
3937
import java.util.Collections;
@@ -711,36 +709,6 @@ public ReferenceDocs referenceDocs() {
711709

712710
}
713711

714-
static class AllPermissionCheck implements BootstrapCheck {
715-
716-
@Override
717-
public final BootstrapCheckResult check(BootstrapContext context) {
718-
if (isAllPermissionGranted()) {
719-
return BootstrapCheck.BootstrapCheckResult.failure("granting the all permission effectively disables security");
720-
}
721-
return BootstrapCheckResult.success();
722-
}
723-
724-
boolean isAllPermissionGranted() {
725-
if (RuntimeVersionFeature.isSecurityManagerAvailable() == false) {
726-
return false;
727-
}
728-
final SecurityManager sm = System.getSecurityManager();
729-
assert sm != null;
730-
try {
731-
sm.checkPermission(new AllPermission());
732-
} catch (final SecurityException e) {
733-
return false;
734-
}
735-
return true;
736-
}
737-
738-
@Override
739-
public ReferenceDocs referenceDocs() {
740-
return ReferenceDocs.BOOTSTRAP_CHECK_ALL_PERMISSION;
741-
}
742-
}
743-
744712
static class DiscoveryConfiguredCheck implements BootstrapCheck {
745713
@Override
746714
public BootstrapCheckResult check(BootstrapContext context) {

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

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@
6363
import java.nio.file.Files;
6464
import java.nio.file.Path;
6565
import java.security.Security;
66-
import java.util.ArrayList;
6766
import java.util.HashMap;
6867
import java.util.HashSet;
6968
import java.util.List;
@@ -128,7 +127,6 @@ private static Bootstrap initPhase1() {
128127
final PrintStream err = getStderr();
129128
final ServerArgs args;
130129

131-
final boolean useEntitlements = true;
132130
try {
133131
initSecurityProperties();
134132
LogConfigurator.registerErrorListener();
@@ -156,7 +154,7 @@ private static Bootstrap initPhase1() {
156154
return null; // unreachable, to satisfy compiler
157155
}
158156

159-
return new Bootstrap(out, err, args, useEntitlements);
157+
return new Bootstrap(out, err, args);
160158
}
161159

162160
/**
@@ -402,11 +400,7 @@ protected void validateNodeBeforeAcceptingRequests(
402400
final BoundTransportAddress boundTransportAddress,
403401
List<BootstrapCheck> checks
404402
) throws NodeValidationException {
405-
var additionalChecks = new ArrayList<>(checks);
406-
if (bootstrap.useEntitlements() == false) {
407-
additionalChecks.add(new BootstrapChecks.AllPermissionCheck());
408-
}
409-
BootstrapChecks.check(context, boundTransportAddress, additionalChecks);
403+
BootstrapChecks.check(context, boundTransportAddress, checks);
410404
}
411405
};
412406
INSTANCE = new Elasticsearch(bootstrap.spawner(), node);

server/src/test/java/org/elasticsearch/bootstrap/BootstrapChecksTests.java

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -657,28 +657,6 @@ String javaVersion() {
657657

658658
}
659659

660-
public void testAllPermissionCheck() throws NodeValidationException {
661-
final AtomicBoolean isAllPermissionGranted = new AtomicBoolean(true);
662-
final BootstrapChecks.AllPermissionCheck allPermissionCheck = new BootstrapChecks.AllPermissionCheck() {
663-
@Override
664-
boolean isAllPermissionGranted() {
665-
return isAllPermissionGranted.get();
666-
}
667-
};
668-
669-
final List<BootstrapCheck> checks = Collections.singletonList(allPermissionCheck);
670-
final NodeValidationException e = expectThrows(
671-
NodeValidationException.class,
672-
() -> BootstrapChecks.check(emptyContext, true, checks)
673-
);
674-
assertThat(e, hasToString(containsString("granting the all permission effectively disables security")));
675-
assertThat(e.getMessage(), containsString("; for more information see [https://www.elastic.co/docs/"));
676-
677-
// if all permissions are not granted, nothing should happen
678-
isAllPermissionGranted.set(false);
679-
BootstrapChecks.check(emptyContext, true, checks);
680-
}
681-
682660
public void testAlwaysEnforcedChecks() {
683661
final BootstrapCheck check = new BootstrapCheck() {
684662
@Override

0 commit comments

Comments
 (0)