Skip to content

Commit f699242

Browse files
rjernstelasticsearchmachineelasticmachine
authored
Remove entitlements flag from startup (elastic#127652) (elastic#128869)
* 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. * [CI] Auto commit changes from spotless --------- Co-authored-by: elasticsearchmachine <[email protected]> Co-authored-by: Elastic Machine <[email protected]>
1 parent e9d720e commit f699242

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
@@ -22,7 +22,6 @@
2222
import org.elasticsearch.core.SuppressForbidden;
2323
import org.elasticsearch.discovery.DiscoveryModule;
2424
import org.elasticsearch.index.IndexModule;
25-
import org.elasticsearch.jdk.RuntimeVersionFeature;
2625
import org.elasticsearch.monitor.jvm.JvmInfo;
2726
import org.elasticsearch.monitor.process.ProcessProbe;
2827
import org.elasticsearch.nativeaccess.NativeAccess;
@@ -34,7 +33,6 @@
3433
import java.nio.ByteOrder;
3534
import java.nio.file.Files;
3635
import java.nio.file.Path;
37-
import java.security.AllPermission;
3836
import java.util.ArrayList;
3937
import java.util.Arrays;
4038
import java.util.Collections;
@@ -723,36 +721,6 @@ public ReferenceDocs referenceDocs() {
723721

724722
}
725723

726-
static class AllPermissionCheck implements BootstrapCheck {
727-
728-
@Override
729-
public final BootstrapCheckResult check(BootstrapContext context) {
730-
if (isAllPermissionGranted()) {
731-
return BootstrapCheck.BootstrapCheckResult.failure("granting the all permission effectively disables security");
732-
}
733-
return BootstrapCheckResult.success();
734-
}
735-
736-
boolean isAllPermissionGranted() {
737-
if (RuntimeVersionFeature.isSecurityManagerAvailable() == false) {
738-
return false;
739-
}
740-
final SecurityManager sm = System.getSecurityManager();
741-
assert sm != null;
742-
try {
743-
sm.checkPermission(new AllPermission());
744-
} catch (final SecurityException e) {
745-
return false;
746-
}
747-
return true;
748-
}
749-
750-
@Override
751-
public ReferenceDocs referenceDocs() {
752-
return ReferenceDocs.BOOTSTRAP_CHECK_ALL_PERMISSION;
753-
}
754-
}
755-
756724
static class DiscoveryConfiguredCheck implements BootstrapCheck {
757725
@Override
758726
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
@@ -58,7 +58,6 @@
5858
import java.nio.file.Files;
5959
import java.nio.file.Path;
6060
import java.security.Security;
61-
import java.util.ArrayList;
6261
import java.util.HashMap;
6362
import java.util.HashSet;
6463
import java.util.List;
@@ -122,7 +121,6 @@ private static Bootstrap initPhase1() {
122121
final PrintStream err = getStderr();
123122
final ServerArgs args;
124123

125-
final boolean useEntitlements = true;
126124
try {
127125
initSecurityProperties();
128126
LogConfigurator.registerErrorListener();
@@ -150,7 +148,7 @@ private static Bootstrap initPhase1() {
150148
return null; // unreachable, to satisfy compiler
151149
}
152150

153-
return new Bootstrap(out, err, args, useEntitlements);
151+
return new Bootstrap(out, err, args);
154152
}
155153

156154
/**
@@ -358,11 +356,7 @@ protected void validateNodeBeforeAcceptingRequests(
358356
final BoundTransportAddress boundTransportAddress,
359357
List<BootstrapCheck> checks
360358
) throws NodeValidationException {
361-
var additionalChecks = new ArrayList<>(checks);
362-
if (bootstrap.useEntitlements() == false) {
363-
additionalChecks.add(new BootstrapChecks.AllPermissionCheck());
364-
}
365-
BootstrapChecks.check(context, boundTransportAddress, additionalChecks);
359+
BootstrapChecks.check(context, boundTransportAddress, checks);
366360
}
367361
};
368362
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
@@ -688,28 +688,6 @@ String javaVersion() {
688688

689689
}
690690

691-
public void testAllPermissionCheck() throws NodeValidationException {
692-
final AtomicBoolean isAllPermissionGranted = new AtomicBoolean(true);
693-
final BootstrapChecks.AllPermissionCheck allPermissionCheck = new BootstrapChecks.AllPermissionCheck() {
694-
@Override
695-
boolean isAllPermissionGranted() {
696-
return isAllPermissionGranted.get();
697-
}
698-
};
699-
700-
final List<BootstrapCheck> checks = Collections.singletonList(allPermissionCheck);
701-
final NodeValidationException e = expectThrows(
702-
NodeValidationException.class,
703-
() -> BootstrapChecks.check(emptyContext, true, checks)
704-
);
705-
assertThat(e, hasToString(containsString("granting the all permission effectively disables security")));
706-
assertThat(e.getMessage(), containsString("; for more information see [https://www.elastic.co/guide/en/elasticsearch/reference/"));
707-
708-
// if all permissions are not granted, nothing should happen
709-
isAllPermissionGranted.set(false);
710-
BootstrapChecks.check(emptyContext, true, checks);
711-
}
712-
713691
public void testAlwaysEnforcedChecks() {
714692
final BootstrapCheck check = new BootstrapCheck() {
715693
@Override

0 commit comments

Comments
 (0)