elastic / elastic/apm-agent-java
Proper error message when trying runtime attach with wrong user
- Dominant language
- Java
- Stars
- 594
- Forks
- 338
- Avg merge
- 1d 13h
- Merged PRs (30d)
- 25
Description
## Description
Runtime attach requires to use the same OS user that is running the target JVM.
While this requirement is written in our documentation in the [Caveats](https://www.elastic.co/guide/en/apm/agent/java/current/setup-attach-cli.html#setup-attach-cli-caveats) section, forgetting about this is rewarded with a very cryptic error message similar to:
```
2020-12-02 17:27:20.717 INFO Attaching the Elastic APM agent to XXXX
Exception in thread "main" java.lang.IllegalStateException: Error during attachment using: co.elastic.apm.attach.bytebuddy.agent.ByteBuddyAgent$AttachmentProvider$Compound@1b9e1916
at co.elastic.apm.attach.bytebuddy.agent.ByteBuddyAgent.install(ByteBuddyAgent.java:613)
at co.elastic.apm.attach.bytebuddy.agent.ByteBuddyAgent.attach(ByteBuddyAgent.java:273)
at co.elastic.apm.attach.ElasticApmAttacher.attach(ElasticApmAttacher.java:170)
at co.elastic.apm.attach.RemoteAttacher.main(RemoteAttacher.java:88)
Caused by: java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at co.elastic.apm.attach.bytebuddy.agent.Attacher.install(Attacher.java:106)
at co.elastic.apm.attach.bytebuddy.agent.ByteBuddyAgent.install(ByteBuddyAgent.java:608)
... 3 more
Caused by: com.sun.jna.LastErrorException: [1] Operation not permitted
...
```
Here the `Operation not permitted` pushes users to try running this as `root` or even try to look for rights/permissions issues without success.
## Proposal
Detect when target JVM and the JVM used for attaching aren't running with the same user and issue a proper error message on how to solve the issue.
Contributor guide
Assessment
This issue has not been assessed yet.