Skip to content

Stop leaking PIMONITOR_API_KEY into vcgencmd's environment - #120

Merged
LarsLaskowski merged 1 commit into
mainfrom
claude/issue-104-bg02uy
Aug 22, 2026
Merged

Stop leaking PIMONITOR_API_KEY into vcgencmd's environment#120
LarsLaskowski merged 1 commit into
mainfrom
claude/issue-104-bg02uy

Conversation

@LarsLaskowski

@LarsLaskowski LarsLaskowski commented Aug 22, 2026

Copy link
Copy Markdown
Owner

📖 Description

vcgencmdRunner.run() left cmd.Env nil, so vcgencmd inherited the full service environment — including PIMONITOR_API_KEY when it's configured via the environment, as SECURITY.md itself recommends. That copies the secret into vcgencmd's /proc/<pid>/environ for no reason, the same class of exposure the -api-key flag's warning already exists to avoid.

internal/collector/updates.go was already fixed for the same underlying issue by #117 (which built an explicit cmd.Env while pinning apt's locale), so that half of the originally reported issue no longer applies — verified by re-reading the current source before starting, per the note on the issue. This PR applies the same approach to vcgencmd.go: since it's invoked by the absolute path resolved by exec.LookPath at detection time, it needs no PATH at all, so its child environment is set to an explicit empty slice (cmd.Env = []string{}, not nil, which would inherit).

Also updates SECURITY.md's "Threat Model / Design Notes" section with a bullet describing this explicit-minimal-environment approach for subprocesses.

🎫 Issues

Closes #104

👩‍💻 Reviewer Notes

The interesting bit is internal/collector/vcgencmd_test.go: vcgencmdRunner already separates detection (path field) from execution, so the test injects a fake vcgencmd script directly via the path field (no new seam needed) and asserts the captured child environment neither contains PIMONITOR_API_KEY nor PATH.

📑 Test Plan

  • Added TestVcgencmdRunner_Run_DoesNotLeakParentEnvironment in internal/collector/vcgencmd_test.go: sets PIMONITOR_API_KEY via t.Setenv, runs a fake vcgencmd script that dumps its own environment to a file, and asserts the secret (and PATH) are absent from the captured output.
  • go build ./..., go vet ./..., go test ./... -race -cover, and golangci-lint run all pass locally.

✅ Checklist

General

  • I have added/updated tests for my changes (go test ./... -race -cover passes locally).
  • go vet ./... and golangci-lint run are clean.
  • I have tested my changes.
  • I have read the CONTRIBUTING documentation and followed the project's code style guidelines.
  • I have updated ARCHITECTURE.md if this changes a documented design decision. (Not applicable — no documented design decision changes, just hardens an existing one.)

REST API / configuration / packaging

Not applicable — no REST API, configuration, or packaging changes.

⏭ Next Steps

The issue's optional follow-up (config.Load calling os.Unsetenv("PIMONITOR_API_KEY") after reading it, to remove the key from /proc/self/environ entirely) is intentionally out of scope here, as noted in the original issue.

vcgencmdRunner.run() left cmd.Env nil, so vcgencmd inherited the full
service environment, including PIMONITOR_API_KEY when it is configured
via the environment as SECURITY.md recommends. That put the secret in
vcgencmd's /proc/<pid>/environ for no reason, the same class of
exposure the -api-key flag warning already exists to avoid.

updates.go was already fixed for the same issue by #117, which built
an explicit cmd.Env while pinning apt's locale. Apply the same
approach to vcgencmd: since it is invoked by the absolute path
resolved at detection time, it needs no PATH at all, so its child
environment can be empty.
@sonarqubecloud

Copy link
Copy Markdown

@LarsLaskowski
LarsLaskowski merged commit 3a2cf26 into main Aug 22, 2026
5 checks passed
@LarsLaskowski
LarsLaskowski deleted the claude/issue-104-bg02uy branch August 22, 2026 09:09
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.

PIMONITOR_API_KEY is passed into every child process environment (apt, vcgencmd)

2 participants