Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Entitlements] No SecurityManager when entitlements are enabled #119689

Merged
merged 2 commits into from
Jan 8, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Adjust Bootstrap and JVM options to ensure the SM is never used when …
…entitlements are enabled
  • Loading branch information
ldematte committed Jan 7, 2025
commit dd86b4fed097d092fd588408c766eed2ad9ccdbd
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ static List<String> systemJvmOptions(Settings nodeSettings, final Map<String, St
maybeSetActiveProcessorCount(nodeSettings),
maybeSetReplayFile(distroType, isHotspot),
maybeWorkaroundG1Bug(),
maybeAllowSecurityManager(),
maybeAllowSecurityManager(useEntitlements),
maybeAttachEntitlementAgent(useEntitlements)
).flatMap(s -> s).toList();
}
Expand Down Expand Up @@ -140,8 +140,8 @@ private static Stream<String> maybeWorkaroundG1Bug() {
}

@UpdateForV9(owner = UpdateForV9.Owner.CORE_INFRA)
private static Stream<String> maybeAllowSecurityManager() {
if (RuntimeVersionFeature.isSecurityManagerAvailable()) {
private static Stream<String> maybeAllowSecurityManager(boolean useEntitlements) {
if (useEntitlements == false && RuntimeVersionFeature.isSecurityManagerAvailable()) {
// Will become conditional on useEntitlements once entitlements can run without SM
return Stream.of("-Djava.security.manager=allow");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ class Bootstrap {

// arguments from the CLI process
private final ServerArgs args;
private final boolean useEntitlements;

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

Bootstrap(PrintStream out, PrintStream err, ServerArgs args) {
Bootstrap(PrintStream out, PrintStream err, ServerArgs args, boolean useEntitlements) {
this.out = out;
this.err = err;
this.args = args;
this.useEntitlements = useEntitlements;
}

ServerArgs args() {
Expand All @@ -60,6 +62,10 @@ Spawner spawner() {
return spawner;
}

public boolean useEntitlements() {
return useEntitlements;
}

void setSecureSettings(SecureSettings secureSettings) {
this.secureSettings.set(secureSettings);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,6 @@ static List<BootstrapCheck> checks() {
checks.add(new OnErrorCheck());
checks.add(new OnOutOfMemoryErrorCheck());
checks.add(new EarlyAccessCheck());
checks.add(new AllPermissionCheck());
checks.add(new DiscoveryConfiguredCheck());
checks.add(new ByteOrderCheck());
return Collections.unmodifiableList(checks);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
import java.nio.file.Path;
import java.security.Permission;
import java.security.Security;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.concurrent.CountDownLatch;
Expand Down Expand Up @@ -108,6 +109,7 @@ private static Bootstrap initPhase1() {
final PrintStream out = getStdout();
final PrintStream err = getStderr();
final ServerArgs args;
final boolean useEntitlements = Boolean.parseBoolean(System.getProperty("es.entitlements.enabled"));
try {
initSecurityProperties();

Expand All @@ -116,7 +118,7 @@ private static Bootstrap initPhase1() {
* the presence of a security manager or lack thereof act as if there is a security manager present (e.g., DNS cache policy).
* This forces such policies to take effect immediately.
*/
if (RuntimeVersionFeature.isSecurityManagerAvailable()) {
if (useEntitlements == false && RuntimeVersionFeature.isSecurityManagerAvailable()) {
org.elasticsearch.bootstrap.Security.setSecurityManager(new SecurityManager() {
@Override
public void checkPermission(Permission perm) {
Expand Down Expand Up @@ -149,7 +151,7 @@ public void checkPermission(Permission perm) {
return null; // unreachable, to satisfy compiler
}

return new Bootstrap(out, err, args);
return new Bootstrap(out, err, args, useEntitlements);
}

/**
Expand Down Expand Up @@ -214,7 +216,7 @@ private static void initPhase2(Bootstrap bootstrap) throws IOException {
var pluginsLoader = PluginsLoader.createPluginsLoader(nodeEnv.modulesFile(), nodeEnv.pluginsFile());
bootstrap.setPluginsLoader(pluginsLoader);

if (Boolean.parseBoolean(System.getProperty("es.entitlements.enabled"))) {
if (bootstrap.useEntitlements()) {
LogManager.getLogger(Elasticsearch.class).info("Bootstrapping Entitlements");

List<EntitlementBootstrap.PluginData> pluginData = Stream.concat(
Expand Down Expand Up @@ -280,7 +282,11 @@ protected void validateNodeBeforeAcceptingRequests(
final BoundTransportAddress boundTransportAddress,
List<BootstrapCheck> checks
) throws NodeValidationException {
BootstrapChecks.check(context, boundTransportAddress, checks);
var additionalChecks = new ArrayList<>(checks);
if (bootstrap.useEntitlements() == false) {
additionalChecks.add(new BootstrapChecks.AllPermissionCheck());
}
BootstrapChecks.check(context, boundTransportAddress, additionalChecks);
}
};
INSTANCE = new Elasticsearch(bootstrap.spawner(), node);
Expand Down