Skip to content

Commit 32fe444

Browse files
committed
Grant manage_threads to java.desktop for Tika
1 parent 7c957c3 commit 32fe444

File tree

3 files changed

+52
-1
lines changed

3 files changed

+52
-1
lines changed

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,13 @@ private static List<Scope> createServerEntitlements(Path pidFile) {
114114
new FilesEntitlement(serverModuleFileDatas)
115115
)
116116
),
117-
new Scope("java.desktop", List.of(new LoadNativeLibrariesEntitlement())),
117+
new Scope(
118+
"java.desktop",
119+
List.of(
120+
new LoadNativeLibrariesEntitlement(),
121+
new ManageThreadsEntitlement() // For sun.java2d.Disposer
122+
)
123+
),
118124
new Scope(
119125
"java.xml",
120126
List.of(
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the "Elastic License
4+
* 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side
5+
* Public License v 1"; you may not use this file except in compliance with, at
6+
* your election, the "Elastic License 2.0", the "GNU Affero General Public
7+
* License v3.0 only", or the "Server Side Public License, v 1".
8+
*/
9+
10+
package org.elasticsearch.entitlement.bootstrap;
11+
12+
import org.elasticsearch.test.ESTestCase;
13+
import org.elasticsearch.test.ESTestCase.WithEntitlementsOnTestCode;
14+
15+
import java.io.ByteArrayInputStream;
16+
17+
import javax.imageio.stream.MemoryCacheImageInputStream;
18+
19+
import static java.nio.charset.StandardCharsets.UTF_8;
20+
21+
@WithEntitlementsOnTestCode
22+
public class HardcodedEntitlementsTests extends ESTestCase {
23+
24+
/**
25+
* The Tika library can do some things we don't ordinarily want to allow.
26+
* <p>
27+
* <em>NOTE</em>: this test never actually fails, due to
28+
* the artificiality of the non-modular testing environment,
29+
* unless you also change {@link org.elasticsearch.bootstrap.TestScopeResolver#getScope}
30+
* to return a {@link org.elasticsearch.entitlement.runtime.policy.PolicyManager.ComponentKind#SERVER SERVER} scope
31+
* with module name {@code java.desktop} when {@code getCodeSource} returns null.
32+
* <p>
33+
* If we were to generate test build info for the JDK modules, then this could work properly.
34+
* <p>
35+
* Note that {@link MemoryCacheImageInputStream} doesn't even use {@code Disposer} in JDK 26,
36+
* so it's an open question how much effort this deserves.
37+
*/
38+
public void testTikaPDF() {
39+
new MemoryCacheImageInputStream(new ByteArrayInputStream("test test".getBytes(UTF_8)));
40+
}
41+
}

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,10 @@ public final void clearModuleEntitlementsCache() {
9797

9898
@Override
9999
protected boolean isTrustedSystemClass(Class<?> requestingClass) {
100+
if (requestingClass.getPackageName().startsWith("sun.java2d")) {
101+
// This is part of the java.desktop module
102+
return false;
103+
}
100104
ClassLoader loader = requestingClass.getClassLoader();
101105
return loader == null || loader == ClassLoader.getPlatformClassLoader();
102106
}

0 commit comments

Comments
 (0)