Skip to content

Commit 79d5d70

Browse files
authored
Fix PolicyManager: plugin resolver overrides agent (#121456) (#121540)
1 parent a84c466 commit 79d5d70

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -398,7 +398,9 @@ private ModuleEntitlements computeEntitlements(Class<?> requestingClass) {
398398
var pluginName = pluginResolver.apply(requestingClass);
399399
if (pluginName != null) {
400400
var pluginEntitlements = pluginsEntitlements.get(pluginName);
401-
if (pluginEntitlements != null) {
401+
if (pluginEntitlements == null) {
402+
return ModuleEntitlements.NONE;
403+
} else {
402404
final String scopeName;
403405
if (requestingModule.isNamed() == false) {
404406
scopeName = ALL_UNNAMED;

libs/entitlement/src/test/java/org/elasticsearch/entitlement/runtime/policy/PolicyManagerTests.java

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ public void testAgentsEntitlements() throws IOException, ClassNotFoundException
271271
createEmptyTestServerPolicy(),
272272
List.of(new CreateClassLoaderEntitlement()),
273273
Map.of(),
274-
c -> "test",
274+
c -> c.getPackageName().startsWith(TEST_AGENTS_PACKAGE_NAME) ? null : "test",
275275
TEST_AGENTS_PACKAGE_NAME,
276276
NO_ENTITLEMENTS_MODULE
277277
);
@@ -357,6 +357,22 @@ public void testDuplicateFlagEntitlements() {
357357
);
358358
}
359359

360+
/**
361+
* If the plugin resolver tells us a class is in a plugin, don't conclude that it's in an agent.
362+
*/
363+
public void testPluginResolverOverridesAgents() {
364+
var policyManager = new PolicyManager(
365+
createEmptyTestServerPolicy(),
366+
List.of(new CreateClassLoaderEntitlement()),
367+
Map.of(),
368+
c -> "test", // Insist that the class is in a plugin
369+
TEST_AGENTS_PACKAGE_NAME,
370+
NO_ENTITLEMENTS_MODULE
371+
);
372+
ModuleEntitlements notAgentsEntitlements = policyManager.getEntitlements(TestAgent.class);
373+
assertThat(notAgentsEntitlements.hasEntitlement(CreateClassLoaderEntitlement.class), is(false));
374+
}
375+
360376
private static Class<?> makeClassInItsOwnModule() throws IOException, ClassNotFoundException {
361377
final Path home = createTempDir();
362378
Path jar = createMockPluginJar(home);

0 commit comments

Comments
 (0)