Stop leaking PIMONITOR_API_KEY into vcgencmd's environment - #120
Merged
Conversation
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.
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



📖 Description
vcgencmdRunner.run()leftcmd.Envnil, sovcgencmdinherited the full service environment — includingPIMONITOR_API_KEYwhen it's configured via the environment, asSECURITY.mditself recommends. That copies the secret intovcgencmd's/proc/<pid>/environfor no reason, the same class of exposure the-api-keyflag's warning already exists to avoid.internal/collector/updates.gowas already fixed for the same underlying issue by #117 (which built an explicitcmd.Envwhile 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 tovcgencmd.go: since it's invoked by the absolute path resolved byexec.LookPathat detection time, it needs noPATHat all, so its child environment is set to an explicit empty slice (cmd.Env = []string{}, notnil, 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:vcgencmdRunneralready separates detection (pathfield) from execution, so the test injects a fakevcgencmdscript directly via thepathfield (no new seam needed) and asserts the captured child environment neither containsPIMONITOR_API_KEYnorPATH.📑 Test Plan
TestVcgencmdRunner_Run_DoesNotLeakParentEnvironmentininternal/collector/vcgencmd_test.go: setsPIMONITOR_API_KEYviat.Setenv, runs a fake vcgencmd script that dumps its own environment to a file, and asserts the secret (andPATH) are absent from the captured output.go build ./...,go vet ./...,go test ./... -race -cover, andgolangci-lint runall pass locally.✅ Checklist
General
go test ./... -race -coverpasses locally).go vet ./...andgolangci-lint runare clean.ARCHITECTURE.mdif 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.Loadcallingos.Unsetenv("PIMONITOR_API_KEY")after reading it, to remove the key from/proc/self/environentirely) is intentionally out of scope here, as noted in the original issue.