Skip to content

fix(jvm): support async-profiler for non-root JVMs - #166

Merged
josepdcs merged 3 commits into
josepdcs:mainfrom
mifisignal:fix/160-nonroot-output
Oct 7, 2026
Merged

josepdcs merged 3 commits into
josepdcs:mainfrom
mifisignal:fix/160-nonroot-output

Conversation

@mifisignal

Copy link
Copy Markdown
Contributor

Why

Async-profiler cannot create its output when the target JVM runs as a non-root user because the shared output directory is root-owned. This causes profiling to finish without producing a usable result.

Fixes #160.

What changed

Pre-create each result file with the target JVM's filesystem identity inside a root-owned, unpredictable directory under the target's /tmp. The agent retains an open descriptor for publishing, preventing the workload from redirecting the privileged read.

Run asprof from the agent image and stage only libasyncProfiler.so inside the target container. This keeps agent-executed code outside the workload's control and supports targets with read-only root filesystems when /tmp is writable.

Add integration coverage using a real non-root JVM for:

  • Default and read-only root filesystems
  • Flamegraph and JFR output
  • Library and output-directory permissions
  • The failure mode when the result file is not pre-created

Validation

  • go test ./internal/agent/profiler/jvm/...
  • git diff --check main...HEAD

Pre-create each output with the JVM filesystem identity inside a root-owned, unpredictable directory, then publish through the held descriptor.

Run asprof from the agent image and stage only its library in the target so workloads cannot replace code executed by the agent.
Run the integration binary from the agent image with the host PID namespace against a non-root JVM using default and read-only root filesystems.

Verify library staging permissions, flamegraph and JFR output, and the failure mode when the output file is not pre-created.
@mifisignal
mifisignal force-pushed the fix/160-nonroot-output branch from b5b9ae0 to 0a74b2b Compare September 15, 2026 15:36
@sonarqubecloud

Copy link
Copy Markdown

@josepdcs

josepdcs commented Oct 7, 2026

Copy link
Copy Markdown
Owner

Hi @mifisignal

Thanks for your contribution!

@josepdcs
josepdcs merged commit cf50d91 into josepdcs:main Oct 7, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[JVM] Profiling fails for containers running as non-root

2 participants