buzz icon indicating copy to clipboard operation
buzz copied to clipboard

macOS pgrep/ps can read every managed agent's BUZZ_PRIVATE_KEY (nsec in KERN_PROCARGS2 environ)

Open lamcode9 opened this issue 3 months ago • 2 comments

Summary

On macOS, pgrep -fl / ps can read every managed agent's BUZZ_PRIVATE_KEY (nsec) because Desktop injects it into the buzz-acp child environment and Darwin KERN_PROCARGS2 concatenates environ after argv. Grandchildren (npm, node, vite preview, etc.) inherit the key. Any same-UID process on the machine can impersonate any other managed agent.

This is inherited environment, not argv. argv does not contain the nsec; pgrep -fl still prints it because it dumps the full KERN_PROCARGS2 buffer.

Why NIP-GS's current wording is not enough

NIP-GS "Key Exposure via Environment Variables" documents Linux /proc/<pid>/environ and calls the model acceptable for "agent processes running in a controlled environment (e.g., spawned by a desktop app with process-scoped env vars)."

A Desktop nest with many managed agents on one Mac is not a controlled environment in that sense: every seat runs as the same OS user. One agent (or any npm script, postinstall, or leftover vite preview) can pgrep -fl buzz-acp and obtain every other seat's signing key.

macOS is not mentioned. pgrep -fl is the accidental disclosure path people actually hit — it looks like the secret was passed on the command line even when it was not.

Reproduction (no secret in the report)

  1. Run a managed agent on macOS Desktop.
  2. From another same-user shell: pgrep -fl buzz-acp (or pgrep -fl vite if an agent left a preview server running).
  3. Observe BUZZ_PRIVATE_KEY=nsec1… in the listed "command" text.
  4. Confirm with KERN_PROCARGS2 that the nsec is in environ, not argv (argc strings do not contain it; the env block after the NUL padding does).

Do not paste the nsec. Redact before sharing ps output.

Expected

  • Agent identity should not be readable from the process table of sibling same-UID processes.
  • At minimum, long-lived grandchildren should not inherit BUZZ_PRIVATE_KEY.
  • Docs should name Darwin KERN_PROCARGS2 / pgrep -fl alongside /proc/<pid>/environ.

Observed spawn site

desktop/src-tauri/src/managed_agents/runtime.rs — command.env("BUZZ_PRIVATE_KEY", &record.private_key_nsec); on the buzz-acp child. Reserved-env stripping correctly blocks user env from setting that key; Desktop still injects it itself, which is the leak.

Suggested direction (not a patch)

  • Prefer a fd / unix-socket / one-shot helper for identity so the nsec is not in environ of the ACP process or its grandchildren.
  • If env injection stays: drop BUZZ_PRIVATE_KEY from the environment before the inner agent runtime execs tools, or document a required env -u BUZZ_PRIVATE_KEY around long-lived children.
  • Treat sibling managed agents on the same UID as the threat model, not only "the process itself and its children."

lamcode9 avatar Aug 28 '26 05:08 lamcode9

Adding a measured data point that refines the "not argv" framing in this report.

On the ACP path the nsec does reach argv. buzz-acp puts it in the MCP server env, and @zed-industries/claude-code-acp then serialises that whole map into a --mcp-config <JSON> command-line argument for the Claude Code CLI. So on Linux it is readable from /proc/<pid>/cmdline, not only from environ.

I captured this by replacing CLAUDE_CODE_EXECUTABLE with a wrapper that logs its own argv before execing the real binary (redacted here):

--permission-prompt-tool stdio
--disallowedTools AskUserQuestion
--mcp-config {"mcpServers":{"<name>":{"type":"stdio","command":"<cmd>","args":[],
  "env":{"BUZZ_RELAY_URL":"ws://…","BUZZ_PRIVATE_KEY":"nsec1<REDACTED>"}},"acp":{"type":"sdk","name":"acp"}}}
--setting-sources user,project,local
--permission-mode default
--allow-dangerously-skip-permissions

Environment: buzz-acp (image ghcr.io/block/buzz-sprig:main), @zed-industries/claude-code-acp 0.16.2, Claude Code 2.1.247, Linux container, non-root uid 1000.

Origin in this repo (at b49675894b39f87215e4dfc8c1ad4a3c28c6097e): crates/buzz-acp/src/lib.rs:5088 — build_mcp_servers() inserts EnvVar { name: "BUZZ_PRIVATE_KEY", value: <bech32 nsec> }, which crates/buzz-acp/src/acp.rs serialises into the session/new mcpServers payload. The adapter only moves it to a flag.

Two consequences worth separating from the environ path:

  1. Different reader set. Anything that reads command lines — crash reporters, process audit logs, ps-scraping supervisors, container tooling — captures it, on Linux as well as macOS.
  2. It survives environment scrubbing. A mitigation that strips BUZZ_* from the agent environment (as suggested elsewhere) does not remove it from argv.

Mitigation we are using meanwhile is only an operational invariant — one seat per container, so a process can read no key but its own. That is a deployment convention, not something the interface enforces, and it does not help a host that runs several seats under one UID.

Gforce10-design avatar Aug 28 '26 10:08 Gforce10-design

Another data point: this also reproduces with claude-agent-acp (the Claude Agent SDK adapter), not only @zed-industries/claude-code-acp.

Setup: buzz-acp running claude-agent-acp as a systemd service on Linux, one agent identity under its own dedicated user, key supplied through EnvironmentFile.

While a session was active, the command line of the SDK's bundled claude binary (@anthropic-ai/claude-agent-sdk-linux-x64/claude) contained

--mcp-config {"mcpServers":{"buzz-dev-mcp":{"type":"stdio","command":".../buzz-dev-mcp","args":[],"env":{..., "BUZZ_PRIVATE_KEY":"<REDACTED>", ...}}, ...}}

so the key is readable from /proc/<pid>/cmdline by any local user unless /proc is mounted with hidepid. Same origin as described above: build_mcp_servers() puts the key in the MCP server env and the adapter serialises it into argv.

On a host with a dedicated agent user this mostly matters for two reasons: the argv copy is visible to other local accounts and to anything that collects process command lines, and the agent itself can read it (as can buzz-dev-mcp shell children, per #2883). So the fix proposed above, keeping the key in the harness and out of mcpServers.env, would cover both.

lh1022 avatar Oct 29 '26 18:10 lh1022