Skip to content

Commit

Permalink
[Security Manager Replacement] Native Java Agent (dynamic code rewrit…
Browse files Browse the repository at this point in the history
…ing, must be low overhead)

Signed-off-by: Andriy Redko <[email protected]>
Signed-off-by: Andriy Redko <[email protected]>
  • Loading branch information
reta committed Feb 23, 2025
1 parent 8447737 commit ec22ea6
Show file tree
Hide file tree
Showing 38 changed files with 4,535 additions and 63 deletions.
8 changes: 7 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -433,12 +433,18 @@ gradle.projectsEvaluated {

project.tasks.withType(Test) { task ->
if (task != null) {
if (BuildParams.runtimeJavaVersion > JavaVersion.VERSION_17) {
if (BuildParams.runtimeJavaVersion > JavaVersion.VERSION_17 && BuildParams.runtimeJavaVersion <= JavaVersion.VERSION_23) {
task.jvmArgs += ["-Djava.security.manager=allow"]
}
if (BuildParams.runtimeJavaVersion >= JavaVersion.VERSION_20) {
task.jvmArgs += ["--add-modules=jdk.incubator.vector"]
}

// Add Java Agent for security sandboxing
if (!(project.path in [':build-tools', ":test:framework", ":libs:agent-sm:bootstrap", ":libs:agent-sm:agent"])) {
dependsOn(project(':libs:agent-sm:agent').copyJars)
jvmArgs += ["-javaagent:" + project(':libs:agent-sm:agent').jar.archiveFile.get()]
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,8 @@ public void execute(Task t) {
test.jvmArgs("--illegal-access=warn");
}
}
if (test.getJavaVersion().compareTo(JavaVersion.VERSION_17) > 0) {
if (test.getJavaVersion().compareTo(JavaVersion.VERSION_17) > 0
&& test.getJavaVersion().compareTo(JavaVersion.VERSION_24) < 0) {
test.jvmArgs("-Djava.security.manager=allow");
}
}
Expand Down
4 changes: 3 additions & 1 deletion distribution/src/config/jvm.options
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ ${error.file}
9-:-Xlog:gc*,gc+age=trace,safepoint:file=${loggc}:utctime,pid,tags:filecount=32,filesize=64m

# Explicitly allow security manager (https://bugs.openjdk.java.net/browse/JDK-8270380)
18-:-Djava.security.manager=allow
18-23:-Djava.security.manager=allow

# JDK 20+ Incubating Vector Module for SIMD optimizations;
# disabling may reduce performance on vector optimized lucene
Expand All @@ -89,3 +89,5 @@ ${error.file}
# See please https://bugs.openjdk.org/browse/JDK-8341127 (openjdk/jdk#21283)
23:-XX:CompileCommand=dontinline,java/lang/invoke/MethodHandle.setAsTypeCache
23:-XX:CompileCommand=dontinline,java/lang/invoke/MethodHandle.asTypeUncached

24:-javaagent:agent/opensearch-agent-3.0.0-SNAPSHOT.jar
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ static List<String> systemJvmOptions() {
}

private static String allowSecurityManagerOption() {
if (Runtime.version().feature() > 17) {
if (Runtime.version().feature() > 17 && Runtime.version().feature() < 24) {
return "-Djava.security.manager=allow";
} else {
return "";
Expand Down
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ junit = "4.13.2"
hamcrest = "2.1"
mockito = "5.14.2"
objenesis = "3.3"
bytebuddy = "1.15.10"
bytebuddy = "1.17.0"

# benchmark dependencies
jmh = "1.35"
Expand Down
1 change: 1 addition & 0 deletions gradle/missing-javadoc.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ configure([
project(":libs:opensearch-secure-sm"),
project(":libs:opensearch-ssl-config"),
project(":libs:opensearch-x-content"),
project(":libs:agent-sm:agent-policy"),
project(":modules:aggs-matrix-stats"),
project(":modules:analysis-common"),
project(":modules:geo"),
Expand Down
32 changes: 32 additions & 0 deletions libs/agent-sm/agent-policy/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* SPDX-License-Identifier: Apache-2.0
*
* The OpenSearch Contributors require contributions made to
* this file be licensed under the Apache-2.0 license or a
* compatible open source license.
*
* Modifications Copyright OpenSearch Contributors. See
* GitHub history for details.
*/

// This file is intentionally blank. All configuration of the
// distribution is done in the parent project.

// See please https://docs.gradle.org/8.5/userguide/upgrading_version_8.html#deprecated_missing_project_directory

apply plugin: 'opensearch.build'
apply plugin: 'opensearch.publish'

ext {
// Do not fail on 'warning: using incubating module(s): jdk.incubator.vector'
failOnJavadocWarning = false
}

base {
archivesName = 'opensearch-agent-policy'
}

disableTasks('forbiddenApisMain')

test.enabled = false
testingConventions.enabled = false
Loading

0 comments on commit ec22ea6

Please sign in to comment.