Skip to content

Commit 3403903

Browse files
Revert "Grant manage_threads to java.desktop for Tika (#134454)"
This reverts commit 9b41320.
1 parent 3696c5c commit 3403903

File tree

5 files changed

+13
-99
lines changed

5 files changed

+13
-99
lines changed

libs/entitlement/src/main/java/org/elasticsearch/entitlement/bootstrap/HardcodedEntitlements.java

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -114,13 +114,7 @@ private static List<Scope> createServerEntitlements(Path pidFile) {
114114
new FilesEntitlement(serverModuleFileDatas)
115115
)
116116
),
117-
new Scope(
118-
"java.desktop",
119-
List.of(
120-
new LoadNativeLibrariesEntitlement(),
121-
new ManageThreadsEntitlement() // For sun.java2d.Disposer. TODO: https://elasticco.atlassian.net/browse/ES-12888
122-
)
123-
),
117+
new Scope("java.desktop", List.of(new LoadNativeLibrariesEntitlement())),
124118
new Scope(
125119
"java.xml",
126120
List.of(

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public class PolicyManager {
5454
*/
5555
static final Logger generalLogger = LogManager.getLogger(PolicyManager.class);
5656

57-
public static final Set<String> MODULES_EXCLUDED_FROM_SYSTEM_MODULES = Set.of("java.desktop", "java.xml");
57+
static final Set<String> MODULES_EXCLUDED_FROM_SYSTEM_MODULES = Set.of("java.desktop", "java.xml");
5858

5959
/**
6060
* Identifies a particular entitlement {@link Scope} within a {@link Policy}.
@@ -94,7 +94,7 @@ public enum ComponentKind {
9494
* If this kind corresponds to a single component, this is that component's name;
9595
* otherwise null.
9696
*/
97-
public final String componentName;
97+
final String componentName;
9898

9999
ComponentKind(String componentName) {
100100
this.componentName = componentName;

libs/entitlement/src/test/java/org/elasticsearch/entitlement/bootstrap/HardcodedEntitlementsTests.java

Lines changed: 0 additions & 33 deletions
This file was deleted.

test/framework/src/main/java/org/elasticsearch/bootstrap/TestScopeResolver.java

Lines changed: 10 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,11 @@
99

1010
package org.elasticsearch.bootstrap;
1111

12-
import org.elasticsearch.core.Nullable;
1312
import org.elasticsearch.core.SuppressForbidden;
14-
import org.elasticsearch.entitlement.runtime.policy.PolicyManager.PolicyScope;
13+
import org.elasticsearch.entitlement.runtime.policy.PolicyManager;
1514
import org.elasticsearch.logging.LogManager;
1615
import org.elasticsearch.logging.Logger;
1716

18-
import java.lang.module.ModuleDescriptor;
19-
import java.lang.module.ModuleFinder;
2017
import java.net.MalformedURLException;
2118
import java.net.URL;
2219
import java.util.List;
@@ -25,78 +22,39 @@
2522
import java.util.TreeMap;
2623
import java.util.function.Function;
2724

28-
import static java.util.Objects.requireNonNull;
29-
import static java.util.stream.Collectors.toSet;
3025
import static org.elasticsearch.entitlement.runtime.policy.PolicyManager.ALL_UNNAMED;
3126
import static org.elasticsearch.entitlement.runtime.policy.PolicyManager.ComponentKind.PLUGIN;
32-
import static org.elasticsearch.entitlement.runtime.policy.PolicyManager.ComponentKind.SERVER;
33-
import static org.elasticsearch.entitlement.runtime.policy.PolicyManager.MODULES_EXCLUDED_FROM_SYSTEM_MODULES;
3427

35-
public final class TestScopeResolver {
28+
public record TestScopeResolver(Map<String, PolicyManager.PolicyScope> scopeMap) {
3629

3730
private static final Logger logger = LogManager.getLogger(TestScopeResolver.class);
38-
private final Map<String, PolicyScope> scopeMap;
39-
private static final Map<String, PolicyScope> excludedSystemPackageScopes = computeExcludedSystemPackageScopes();
4031

41-
public TestScopeResolver(Map<String, PolicyScope> scopeMap) {
42-
this.scopeMap = scopeMap;
43-
}
44-
45-
private static Map<String, PolicyScope> computeExcludedSystemPackageScopes() {
46-
// Within any one module layer, module names are unique, so we just need the names
47-
Set<String> systemModuleNames = ModuleFinder.ofSystem()
48-
.findAll()
49-
.stream()
50-
.map(ref -> ref.descriptor().name())
51-
.filter(MODULES_EXCLUDED_FROM_SYSTEM_MODULES::contains)
52-
.collect(toSet());
53-
54-
Map<String, PolicyScope> result = new TreeMap<>();
55-
ModuleLayer.boot().modules().stream().filter(m -> systemModuleNames.contains(m.getName())).forEach(m -> {
56-
ModuleDescriptor desc = m.getDescriptor();
57-
if (desc != null) {
58-
desc.packages().forEach(pkg ->
59-
// Our component identification logic returns SERVER for these
60-
result.put(pkg, new PolicyScope(SERVER, SERVER.componentName, m.getName())));
61-
}
62-
});
63-
return result;
64-
}
65-
66-
public static @Nullable PolicyScope getExcludedSystemPackageScope(Class<?> callerClass) {
67-
return excludedSystemPackageScopes.get(callerClass.getPackageName());
68-
}
69-
70-
PolicyScope getScope(Class<?> callerClass) {
32+
PolicyManager.PolicyScope getScope(Class<?> callerClass) {
7133
var callerCodeSource = callerClass.getProtectionDomain().getCodeSource();
72-
if (callerCodeSource == null) {
73-
// This only happens for JDK classes. Furthermore, for trivially allowed modules, we shouldn't even get here.
74-
// Hence, this must be an excluded system module, so check for that.
75-
return requireNonNull(getExcludedSystemPackageScope(callerClass));
76-
}
34+
assert callerCodeSource != null;
7735

7836
var location = callerCodeSource.getLocation().toString();
7937
var scope = scopeMap.get(location);
8038
if (scope == null) {
8139
// Special cases for libraries not handled by our automatically-generated scopeMap
8240
if (callerClass.getPackageName().startsWith("org.bouncycastle")) {
83-
scope = new PolicyScope(PLUGIN, "security", ALL_UNNAMED);
41+
scope = new PolicyManager.PolicyScope(PLUGIN, "security", ALL_UNNAMED);
8442
logger.debug("Assuming bouncycastle is part of the security plugin");
8543
}
8644
}
8745
if (scope == null) {
8846
logger.warn("Cannot identify a scope for class [{}], location [{}]", callerClass.getName(), location);
89-
return PolicyScope.unknown(location);
47+
return PolicyManager.PolicyScope.unknown(location);
9048
}
9149
return scope;
9250
}
9351

94-
public static Function<Class<?>, PolicyScope> createScopeResolver(
52+
public static Function<Class<?>, PolicyManager.PolicyScope> createScopeResolver(
9553
TestBuildInfo serverBuildInfo,
9654
List<TestBuildInfo> pluginsBuildInfo,
9755
Set<String> modularPlugins
9856
) {
99-
Map<String, PolicyScope> scopeMap = new TreeMap<>(); // Sorted to make it easier to read during debugging
57+
Map<String, PolicyManager.PolicyScope> scopeMap = new TreeMap<>(); // Sorted to make it easier to read during debugging
10058
for (var pluginBuildInfo : pluginsBuildInfo) {
10159
boolean isModular = modularPlugins.contains(pluginBuildInfo.component());
10260
for (var location : pluginBuildInfo.locations()) {
@@ -108,7 +66,7 @@ public static Function<Class<?>, PolicyScope> createScopeResolver(
10866
String module = isModular ? location.module() : ALL_UNNAMED;
10967
scopeMap.put(
11068
getCodeSource(codeSource, location.representativeClass()),
111-
PolicyScope.plugin(pluginBuildInfo.component(), module)
69+
PolicyManager.PolicyScope.plugin(pluginBuildInfo.component(), module)
11270
);
11371
} catch (MalformedURLException e) {
11472
throw new IllegalArgumentException("Cannot locate class [" + location.representativeClass() + "]", e);
@@ -123,7 +81,7 @@ public static Function<Class<?>, PolicyScope> createScopeResolver(
12381
continue;
12482
}
12583
try {
126-
scopeMap.put(getCodeSource(classUrl, location.representativeClass()), PolicyScope.server(location.module()));
84+
scopeMap.put(getCodeSource(classUrl, location.representativeClass()), PolicyManager.PolicyScope.server(location.module()));
12785
} catch (MalformedURLException e) {
12886
throw new IllegalArgumentException("Cannot locate class [" + location.representativeClass() + "]", e);
12987
}

test/framework/src/main/java/org/elasticsearch/entitlement/runtime/policy/TestPolicyManager.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99

1010
package org.elasticsearch.entitlement.runtime.policy;
1111

12-
import org.elasticsearch.bootstrap.TestScopeResolver;
1312
import org.elasticsearch.common.util.ArrayUtils;
1413
import org.elasticsearch.entitlement.runtime.policy.entitlements.Entitlement;
1514
import org.elasticsearch.test.ESTestCase;
@@ -98,10 +97,6 @@ public final void clearModuleEntitlementsCache() {
9897

9998
@Override
10099
protected boolean isTrustedSystemClass(Class<?> requestingClass) {
101-
if (TestScopeResolver.getExcludedSystemPackageScope(requestingClass) != null) {
102-
// We don't trust the excluded packages even though they are in system modules
103-
return false;
104-
}
105100
ClassLoader loader = requestingClass.getClassLoader();
106101
return loader == null || loader == ClassLoader.getPlatformClassLoader();
107102
}

0 commit comments

Comments
 (0)