Skip to content
Merged
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
6 changes: 5 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,11 @@ gradle.projectsEvaluated {
task.jvmArgs += [
"--add-modules=jdk.incubator.vector",
"--add-exports=java.base/com.sun.crypto.provider=ALL-UNNAMED",
"--enable-native-access=ALL-UNNAMED"
"--enable-native-access=ALL-UNNAMED",
// Disable ByteBuddy's Unsafe-based class injection path to avoid
// "sun.misc.Unsafe::objectFieldOffset has been called by ByteBuddy" JVM warnings on JDK 21+.
// ByteBuddy still falls back to Lookup/Reflection injection strategies.
"-Dnet.bytebuddy.safe=true"
]

// Add Java Agent for security sandboxing
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* removal. All new code should use this class instead of the JDK's {@code AccessController}.
*
* Running code in a privileged context will ensure that the code has the necessary permissions
* without traversing through the entire call stack. See {@code org.opensearch.javaagent.StackCallerProtectionDomainChainExtractor}
* without traversing through the entire call stack. See {@code org.opensearch.javaagent.bootstrap.internal.StackCallerProtectionDomainChainExtractor}
*
* Example usages:
* <pre>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

package org.opensearch.javaagent;

import org.opensearch.javaagent.bootstrap.AgentPolicy;
import org.opensearch.javaagent.bootstrap.internal.SubjectInterceptor;

import javax.security.auth.Subject;

Expand All @@ -18,14 +18,11 @@
import java.nio.channels.SocketChannel;
import java.nio.file.Files;
import java.nio.file.spi.FileSystemProvider;
import java.util.Map;

import net.bytebuddy.ByteBuddy;
import net.bytebuddy.agent.builder.AgentBuilder;
import net.bytebuddy.asm.Advice;
import net.bytebuddy.description.type.TypeDescription;
import net.bytebuddy.dynamic.ClassFileLocator;
import net.bytebuddy.dynamic.loading.ClassInjector;
import net.bytebuddy.implementation.Implementation;
import net.bytebuddy.implementation.MethodDelegation;
import net.bytebuddy.matcher.ElementMatcher.Junction;
Expand Down Expand Up @@ -96,20 +93,6 @@ private static AgentBuilder createAgentBuilder() throws Exception {
ElementMatchers.named("getSubject")
).intercept(MethodDelegation.to(SubjectInterceptor.class));

ClassInjector.UsingUnsafe.ofBootLoader()
.inject(
Map.of(
new TypeDescription.ForLoadedType(StackCallerProtectionDomainChainExtractor.class),
ClassFileLocator.ForClassLoader.read(StackCallerProtectionDomainChainExtractor.class),
new TypeDescription.ForLoadedType(StackCallerClassChainExtractor.class),
ClassFileLocator.ForClassLoader.read(StackCallerClassChainExtractor.class),
new TypeDescription.ForLoadedType(AgentPolicy.class),
ClassFileLocator.ForClassLoader.read(AgentPolicy.class),
new TypeDescription.ForLoadedType(SubjectInterceptor.class),
ClassFileLocator.ForClassLoader.read(SubjectInterceptor.class)
)
);

final ByteBuddy byteBuddy = new ByteBuddy().with(Implementation.Context.Disabled.Factory.INSTANCE);
var builder = new AgentBuilder.Default(byteBuddy).with(AgentBuilder.InitializationStrategy.NoOp.INSTANCE)
.with(AgentBuilder.RedefinitionStrategy.REDEFINITION)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
package org.opensearch.javaagent;

import org.opensearch.javaagent.bootstrap.AgentPolicy;
import org.opensearch.javaagent.bootstrap.internal.StackCallerClassChainExtractor;
import org.opensearch.javaagent.bootstrap.internal.StackCallerProtectionDomainChainExtractor;

import java.io.FilePermission;
import java.lang.reflect.Method;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
package org.opensearch.javaagent;

import org.opensearch.javaagent.bootstrap.AgentPolicy;
import org.opensearch.javaagent.bootstrap.internal.StackCallerClassChainExtractor;

import java.lang.StackWalker.Option;
import java.security.Policy;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
package org.opensearch.javaagent;

import org.opensearch.javaagent.bootstrap.AgentPolicy;
import org.opensearch.javaagent.bootstrap.internal.StackCallerProtectionDomainChainExtractor;

import java.lang.reflect.Method;
import java.net.InetSocketAddress;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
package org.opensearch.javaagent;

import org.opensearch.javaagent.bootstrap.AgentPolicy;
import org.opensearch.javaagent.bootstrap.internal.StackCallerClassChainExtractor;

import java.lang.StackWalker.Option;
import java.security.Policy;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

package org.opensearch.javaagent;

import org.opensearch.javaagent.bootstrap.internal.StackCallerProtectionDomainChainExtractor;
import org.junit.Assume;
import org.junit.Test;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* compatible open source license.
*/

package org.opensearch.javaagent;
package org.opensearch.javaagent.bootstrap.internal;

import java.lang.StackWalker.StackFrame;
import java.util.Collection;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* compatible open source license.
*/

package org.opensearch.javaagent;
package org.opensearch.javaagent.bootstrap.internal;

import java.lang.StackWalker.StackFrame;
import java.security.ProtectionDomain;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* compatible open source license.
*/

package org.opensearch.javaagent;
package org.opensearch.javaagent.bootstrap.internal;

import javax.security.auth.Subject;

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

/**
* Internal agent support classes that must be loaded by the boot classloader
* so that bytecode woven into JDK classes (either inlined ByteBuddy Advice or
* MethodDelegation stubs) can resolve them. These classes are implementation
* details of the Java agent and are not part of any public API; do not depend
* on them from outside {@code :libs:agent-sm:agent}.
Comment thread
reta marked this conversation as resolved.
*/
package org.opensearch.javaagent.bootstrap.internal;
Loading