- Notifications
You must be signed in to change notification settings - Fork 327
Fix security manager issues #2871
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
Fix security manager issues #2871
Conversation
| public URL findResource(final String name) { | ||
| URL result = null; | ||
| if (!locallyNonAvailableResources.get().contains(name)) { | ||
| | ||
| // while most of the body of default 'findResource' in JDK implementation is in a privileged action | ||
| // an extra URL check is performed just after it, hence we have to wrap the whole method call in a privileged | ||
| // action otherwise the security manager will complain about lack of proper read privileges on the agent jar | ||
| result = AccessController.doPrivileged(new PrivilegedAction<URL>() { | ||
| @Override | ||
| public URL run() { | ||
| return findResourceInternal(getShadedResourceName(name)); | ||
| } | ||
| }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[for reviewer] this fixes the NoClassDefFound exceptions, the JDK implementation of findResource that we call through the super.findResource(name) performs an extra URL check outside of a privileged action.
| /test |
eyalkoren left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome fix!! 👏
See comments
apm-agent-core/src/main/java/co/elastic/apm/agent/bci/IndyBootstrap.java Show resolved Hide resolved
elastic-apm-agent/src/main/java/co/elastic/apm/agent/premain/ShadedClassLoader.java Outdated Show resolved Hide resolved
elastic-apm-agent/src/main/java/co/elastic/apm/agent/premain/ShadedClassLoader.java Show resolved Hide resolved
elastic-apm-agent/src/main/java/co/elastic/apm/agent/premain/ShadedClassLoader.java Outdated Show resolved Hide resolved
elastic-apm-agent/src/main/java/co/elastic/apm/agent/premain/ShadedClassLoader.java Show resolved Hide resolved
| @eyalkoren avoiding allocation here might be something quite challenging, especially for the cases when there are multiple parameters, do you think that would be required ? Alternatively, maybe a simpler approach here would be to simply shortcut this extra wrapping when |
| Status:
|
Definitely, this sounds very reasonable. Just let's not have this overhead penalty to the vast majority of users that don't use the security manager. |
apm-agent-core/src/main/java/co/elastic/apm/agent/logging/Log4j2LoggerBridge.java Show resolved Hide resolved
apm-agent-core/src/main/java/co/elastic/apm/agent/bci/classloading/IndyPluginClassLoader.java Show resolved Hide resolved
| Closes #390 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What a magnificent refactoring! 👏
Looks really good and I recognized lots of stuff I saw failing in #2883, which is a good indication that we are in the right direction.
Some minor comments still.
elastic-apm-agent/src/main/java/co/elastic/apm/agent/premain/ShadedClassLoader.java Show resolved Hide resolved
apm-agent-core/src/main/java/co/elastic/apm/agent/bci/classloading/IndyPluginClassLoader.java Show resolved Hide resolved
apm-agent-core/src/main/java/co/elastic/apm/agent/logging/Log4j2LoggerBridge.java Show resolved Hide resolved
apm-agent-core/src/main/java/co/elastic/apm/agent/util/PrivilegedActionUtils.java Outdated Show resolved Hide resolved
apm-agent-core/src/main/java/co/elastic/apm/agent/util/PrivilegedActionUtils.java Outdated Show resolved Hide resolved
apm-agent-core/src/main/java/co/elastic/apm/agent/util/PrivilegedActionUtils.java Outdated Show resolved Hide resolved
apm-agent-plugin-sdk/src/main/java/co/elastic/apm/agent/sdk/internal/InternalUtil.java Outdated Show resolved Hide resolved
apm-agent-plugin-sdk/src/main/java/co/elastic/apm/agent/sdk/internal/InternalUtil.java Outdated Show resolved Hide resolved
...in/src/main/java/co/elastic/apm/agent/jul/reformatting/AbstractJulEcsReformattingHelper.java Outdated Show resolved Hide resolved
apm-agent-plugin-sdk/src/main/java/co/elastic/apm/agent/sdk/state/GlobalVariables.java Outdated Show resolved Hide resolved
eyalkoren left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Only one more exception to avoid automatic casting in AbstractJulEcsReformattingHelper
What does this PR do?
Fixes #2520
NoClassDefFounderrors triggered in classloading due to URL validation in JDK outside of adoPrivilegedwrapping.doPrivilegedcalls to make the agent able to start properly (reading environment variables, get classloader reference of an existing class and resolve method handles).System.getenvtrigger exception when not called in a privileged action, whereas theSystem.getPropertyorSystem.getPropertiesdo not, as a result I added aPrivilegedActionUtilsclass to properly wrap those calls with minimal code duplication and verbosity.Checklist
./bin/catalina.sh run -security+ enabling most agent features (log reformatting, inferred spans, ...)