Skip to content

Commit 1b69de3

Browse files
committed
Add jdk.management.agent module to server
1 parent 275efd3 commit 1b69de3

File tree

2 files changed

+15
-22
lines changed

2 files changed

+15
-22
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ private List<String> getJvmArgs() {
109109
esHome.resolve("lib").toString(),
110110
// Special circumstances require some modules (not depended on by the main server module) to be explicitly added:
111111
"--add-modules=jdk.net", // needed to reflectively set extended socket options
112+
"--add-modules=jdk.management.agent", // needed by external debug tools to grab thread and heap dumps
112113
// we control the module path, which may have additional modules not required by server
113114
"--add-modules=ALL-MODULE-PATH",
114115
"-m",

libs/entitlement/src/main/java/org/elasticsearch/entitlement/runtime/policy/PolicyManager.java

Lines changed: 14 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@
3434
import java.lang.StackWalker.StackFrame;
3535
import java.lang.module.ModuleFinder;
3636
import java.lang.module.ModuleReference;
37-
import java.lang.module.ResolvedModule;
3837
import java.nio.file.Path;
3938
import java.util.ArrayList;
4039
import java.util.HashSet;
@@ -124,10 +123,20 @@ ModuleEntitlements policyEntitlements(String componentName, String moduleName, L
124123

125124
public static final String ALL_UNNAMED = "ALL-UNNAMED";
126125

127-
private static final Set<ModuleReference> systemModules = findSystemModules();
126+
private static final Set<Module> systemModules = findSystemModules();
128127

129-
private static Set<ModuleReference> findSystemModules() {
130-
return ModuleFinder.ofSystem().findAll().stream().collect(Collectors.toUnmodifiableSet());
128+
private static Set<Module> findSystemModules() {
129+
var systemModulesDescriptors = ModuleFinder.ofSystem()
130+
.findAll()
131+
.stream()
132+
.map(ModuleReference::descriptor)
133+
.collect(Collectors.toUnmodifiableSet());
134+
return Stream.concat(
135+
// entitlements is a "system" module, we can do anything from it
136+
Stream.of(PolicyManager.class.getModule()),
137+
// anything in the boot layer is also part of the system
138+
ModuleLayer.boot().modules().stream().filter(m -> systemModulesDescriptors.contains(m.getDescriptor()))
139+
).collect(Collectors.toUnmodifiableSet());
131140
}
132141

133142
/**
@@ -606,31 +615,14 @@ private static boolean isTriviallyAllowed(Class<?> requestingClass) {
606615
logger.debug("Entitlement trivially allowed: no caller frames outside the entitlement library");
607616
return true;
608617
}
609-
if (isSystemModule(requestingClass.getModule())) {
618+
if (systemModules.contains(requestingClass.getModule())) {
610619
logger.debug("Entitlement trivially allowed from system module [{}]", requestingClass.getModule().getName());
611620
return true;
612621
}
613622
logger.trace("Entitlement not trivially allowed");
614623
return false;
615624
}
616625

617-
/**
618-
* Determines if the given {@link Module} is a system module. That is, a module that is included as part of the Java runtime.
619-
*/
620-
private static boolean isSystemModule(Module module) {
621-
if (module.getLayer() == null) {
622-
// This is an unnamed module, so not a system module
623-
return false;
624-
}
625-
626-
ModuleReference moduleReference = module.getLayer()
627-
.configuration()
628-
.findModule(module.getName())
629-
.map(ResolvedModule::reference)
630-
.orElse(null);
631-
return module == PolicyManager.class.getModule() || (moduleReference != null && systemModules.contains(moduleReference));
632-
}
633-
634626
@Override
635627
public String toString() {
636628
return "PolicyManager{" + "serverEntitlements=" + serverEntitlements + ", pluginsEntitlements=" + pluginsEntitlements + '}';

0 commit comments

Comments
 (0)