Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Java agent based File interceptor #17633

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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', ":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
4 changes: 2 additions & 2 deletions buildSrc/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -110,12 +110,12 @@ dependencies {
api 'com.netflix.nebula:gradle-info-plugin:12.1.6'
api 'org.apache.rat:apache-rat:0.15'
api "commons-io:commons-io:${props.getProperty('commonsio')}"
api "net.java.dev.jna:jna:5.14.0"
api "net.java.dev.jna:jna:5.16.0"
api 'com.gradleup.shadow:shadow-gradle-plugin:8.3.5'
api 'org.jdom:jdom2:2.0.6.1'
api "org.jetbrains.kotlin:kotlin-stdlib-jdk8:${props.getProperty('kotlin')}"
api 'de.thetaphi:forbiddenapis:3.8'
api 'com.avast.gradle:gradle-docker-compose-plugin:0.17.6'
api 'com.avast.gradle:gradle-docker-compose-plugin:0.17.12'
api "org.yaml:snakeyaml:${props.getProperty('snakeyaml')}"
api 'org.apache.maven:maven-model:3.9.6'
api 'com.networknt:json-schema-validator:1.2.0'
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
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,9 @@
import java.util.stream.Stream;

public class DistroTestPlugin implements Plugin<Project> {
private static final String SYSTEM_JDK_VERSION = "21.0.6+7";
private static final String SYSTEM_JDK_VERSION = "23.0.2+7";
private static final String SYSTEM_JDK_VENDOR = "adoptium";
private static final String GRADLE_JDK_VERSION = "21.0.6+7";
private static final String GRADLE_JDK_VERSION = "23.0.2+7";
private static final String GRADLE_JDK_VENDOR = "adoptium";

// all distributions used by distro tests. this is temporary until tests are per distribution
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@

grant {
permission java.net.SocketPermission "*", "connect,resolve";
permission java.net.NetPermission "accessUnixDomainSocket";
};
9 changes: 9 additions & 0 deletions distribution/archives/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ CopySpec archiveFiles(CopySpec modulesFiles, String distributionType, String pla
into('lib') {
with libFiles()
}
into('agent') {
with agentFiles()
}
into('config') {
dirPermissions {
unix 0750
Expand Down Expand Up @@ -226,3 +229,9 @@ subprojects {

group = "org.opensearch.distribution"
}

tasks.each {
if (it.name.startsWith("build")) {
it.dependsOn project(':libs:agent-sm:agent').copyJars, project(':libs:agent-sm:agent').assemble
}
}
6 changes: 6 additions & 0 deletions distribution/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,12 @@ configure(subprojects.findAll { ['archives', 'packages'].contains(it.name) }) {
}
}

agentFiles = {
copySpec {
from(project(':libs:agent-sm:agent').copyJars)
}
}

modulesFiles = { platform ->
copySpec {
eachFile {
Expand Down
5 changes: 4 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,6 @@ ${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

# It should be JDK-24 (but we cannot bring JDK-24 since Gradle does not support it yet)
21-:-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
8 changes: 4 additions & 4 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ opensearch = "3.0.0"
lucene = "10.1.0"

bundled_jdk_vendor = "adoptium"
bundled_jdk = "21.0.6+7"
bundled_jdk = "23.0.2+7"

# optional dependencies
spatial4j = "0.7"
Expand Down Expand Up @@ -31,7 +31,7 @@ grpc = "1.68.2"
json_smart = "2.5.2"

# when updating the JNA version, also update the version in buildSrc/build.gradle
jna = "5.13.0"
jna = "5.16.0"

netty = "4.1.118.Final"
joda = "2.12.7"
Expand Down Expand Up @@ -65,9 +65,9 @@ bouncycastle="1.78"
randomizedrunner = "2.7.1"
junit = "4.13.2"
hamcrest = "2.1"
mockito = "5.14.2"
mockito = "5.16.0"
objenesis = "3.3"
bytebuddy = "1.15.10"
bytebuddy = "1.17.2"

# 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
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/*
* 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.
*/

/**
* Java Agent Policy
*/
package org.opensearch;
Loading
Loading