Skip to content

Commit 4ab0ae9

Browse files
authored
Update forbidden APIs for JDK 25 (#19623)
Update the forbidden APIs plugin to the latest release and also fix or suppress all the usages of APIs that are newly deprecated in JDK 25. Signed-off-by: Andrew Ross <[email protected]>
1 parent 14578f6 commit 4ab0ae9

File tree

9 files changed

+16
-28
lines changed

9 files changed

+16
-28
lines changed

buildSrc/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ dependencies {
114114
api 'com.gradleup.shadow:shadow-gradle-plugin:8.3.9'
115115
api 'org.jdom:jdom2:2.0.6.1'
116116
api "org.jetbrains.kotlin:kotlin-stdlib-jdk8:${props.getProperty('kotlin')}"
117-
api 'de.thetaphi:forbiddenapis:3.9'
117+
api 'de.thetaphi:forbiddenapis:3.10'
118118
api 'com.avast.gradle:gradle-docker-compose-plugin:0.17.12'
119119
api "org.yaml:snakeyaml:${props.getProperty('snakeyaml')}"
120120
api 'org.apache.maven:maven-model:3.9.6'

distribution/tools/plugin-cli/src/main/java/org/opensearch/tools/cli/plugin/PluginSecurity.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
import org.opensearch.cli.Terminal;
3737
import org.opensearch.cli.Terminal.Verbosity;
3838
import org.opensearch.cli.UserException;
39+
import org.opensearch.common.SuppressForbidden;
3940
import org.opensearch.common.util.io.IOUtils;
4041
import org.opensearch.secure_sm.policy.PolicyFile;
4142

@@ -96,6 +97,7 @@ private static void prompt(final Terminal terminal, final boolean batch) throws
9697
}
9798

9899
/** Format permission type, name, and actions into a string */
100+
@SuppressForbidden(reason = "https://github.com/opensearch-project/OpenSearch/issues/19640")
99101
static String formatPermission(Permission permission) {
100102
StringBuilder sb = new StringBuilder();
101103

plugins/repository-hdfs/src/main/java/org/opensearch/repositories/hdfs/HdfsSecurityContext.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333

3434
import org.apache.hadoop.security.UserGroupInformation;
3535
import org.opensearch.SpecialPermission;
36+
import org.opensearch.common.SuppressForbidden;
3637
import org.opensearch.env.Environment;
3738

3839
import javax.security.auth.AuthPermission;
@@ -58,6 +59,7 @@
5859
* permissions to grant the blob store restricted execution methods.
5960
*/
6061
@SuppressWarnings("removal")
62+
@SuppressForbidden(reason = "https://github.com/opensearch-project/OpenSearch/issues/19640")
6163
class HdfsSecurityContext {
6264

6365
private static final Permission[] SIMPLE_AUTH_PERMISSIONS;

qa/evil-tests/src/test/java/org/opensearch/tools/cli/plugin/PluginSecurityTests.java

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
import org.opensearch.secure_sm.policy.PolicyInitializationException;
3636
import org.opensearch.test.OpenSearchTestCase;
3737

38+
import java.net.SocketPermission;
3839
import java.nio.file.Path;
3940
import java.util.Set;
4041

@@ -43,45 +44,35 @@
4344
import static org.hamcrest.Matchers.containsInAnyOrder;
4445

4546
/** Tests plugin manager security check */
46-
@SuppressWarnings("removal")
4747
public class PluginSecurityTests extends OpenSearchTestCase {
4848

4949
/** Test that we can parse the set of permissions correctly for a simple policy */
5050
public void testParsePermissions() throws Exception {
51-
assumeTrue(
52-
"test cannot run with security manager enabled",
53-
System.getSecurityManager() == null);
5451
Path scratch = createTempDir();
5552
Path testFile = this.getDataPath("simple-plugin-security.policy");
5653
Set<String> actual = PluginSecurity.parsePermissions(testFile, scratch);
57-
assertThat(actual, contains(PluginSecurity.formatPermission(new RuntimePermission("queuePrintJob"))));
54+
assertThat(actual, contains(PluginSecurity.formatPermission(new SocketPermission("*", "connect"))));
5855
}
5956

6057
/** Test that we can parse the set of permissions correctly for a complex policy */
6158
public void testParseTwoPermissions() throws Exception {
62-
assumeTrue(
63-
"test cannot run with security manager enabled",
64-
System.getSecurityManager() == null);
6559
Path scratch = createTempDir();
6660
Path testFile = this.getDataPath("complex-plugin-security.policy");
6761
Set<String> actual = PluginSecurity.parsePermissions(testFile, scratch);
6862
assertThat(actual, containsInAnyOrder(
69-
PluginSecurity.formatPermission(new RuntimePermission("getClassLoader")),
70-
PluginSecurity.formatPermission(new RuntimePermission("closeClassLoader"))));
63+
PluginSecurity.formatPermission(new SocketPermission("*", "connect,resolve")),
64+
PluginSecurity.formatPermission(new SocketPermission("opensearch.org", "connect"))));
7165
}
7266

7367
/** Test that we can format some simple permissions properly */
7468
public void testFormatSimplePermission() throws Exception {
7569
assertEquals(
76-
"java.lang.RuntimePermission queuePrintJob",
77-
PluginSecurity.formatPermission(new RuntimePermission("queuePrintJob")));
70+
"java.net.SocketPermission * connect,resolve",
71+
PluginSecurity.formatPermission(new SocketPermission("*", "connect,resolve")));
7872
}
7973

8074
/** Test that we can format an unresolved permission properly */
8175
public void testFormatUnresolvedPermission() throws Exception {
82-
assumeTrue(
83-
"test cannot run with security manager enabled",
84-
System.getSecurityManager() == null);
8576
Path scratch = createTempDir();
8677
Path testFile = this.getDataPath("unresolved-plugin-security.policy");
8778
RuntimeException ex = assertThrows(RuntimeException.class, () -> PluginSecurity.parsePermissions(testFile, scratch));

qa/evil-tests/src/test/resources/org/opensearch/tools/cli/plugin/complex-plugin-security.policy

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131
*/
3232

3333
grant {
34-
// needed to cause problems
35-
permission java.lang.RuntimePermission "getClassLoader";
36-
permission java.lang.RuntimePermission "closeClassLoader";
34+
permission java.net.SocketPermission "opensearch.org" "connect";
35+
permission java.net.SocketPermission "*" "connect,resolve";
3736
};

qa/evil-tests/src/test/resources/org/opensearch/tools/cli/plugin/simple-plugin-security.policy

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,5 @@
3131
*/
3232

3333
grant {
34-
// needed to waste paper
35-
permission java.lang.RuntimePermission "queuePrintJob";
34+
permission java.net.SocketPermission "*" "connect";
3635
};

server/src/main/java/org/opensearch/bootstrap/OpenSearchPolicy.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
* @opensearch.internal
5555
**/
5656
@SuppressWarnings("removal")
57+
@SuppressForbidden(reason = "https://github.com/opensearch-project/OpenSearch/issues/19640")
5758
final class OpenSearchPolicy extends Policy {
5859

5960
/** template policy file, the one used in tests */

server/src/main/java/org/opensearch/monitor/jvm/JvmInfo.java

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@
4646
import java.io.IOException;
4747
import java.lang.management.GarbageCollectorMXBean;
4848
import java.lang.management.ManagementFactory;
49-
import java.lang.management.ManagementPermission;
5049
import java.lang.management.MemoryMXBean;
5150
import java.lang.management.MemoryPoolMXBean;
5251
import java.lang.management.PlatformManagedObject;
@@ -216,13 +215,7 @@ private static boolean usingBundledJdkOrJre() {
216215
}
217216
}
218217

219-
@SuppressWarnings("removal")
220218
public static JvmInfo jvmInfo() {
221-
SecurityManager sm = System.getSecurityManager();
222-
if (sm != null) {
223-
sm.checkPermission(new ManagementPermission("monitor"));
224-
sm.checkPropertyAccess("*");
225-
}
226219
return INSTANCE;
227220
}
228221

test/framework/src/main/java/org/opensearch/bootstrap/BootstrapForTesting.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@
8686
* mode (e.g. assign permissions and install security manager the same way)
8787
*/
8888
@SuppressWarnings("removal")
89+
@SuppressForbidden(reason = "https://github.com/opensearch-project/OpenSearch/issues/19640")
8990
public class BootstrapForTesting {
9091
private static final String[] TEST_RUNNER_PACKAGES = new String[] {
9192
// gradle worker

0 commit comments

Comments
 (0)