Repository navigation
fix(spored): run --pre-stop as the instance user, not root (#63) - #185
Merged
Merged
Conversation
spored is a root systemd service, so the pre-stop hook ran with root's environment: ~/$HOME resolved to /root. A hook like `aws s3 sync ~/output s3://…` synced the empty /root/output and "succeeded" copying nothing — silent data loss on ephemeral storage (surfaced by #184, a real 48h GPU run that lost ~110k detections). Fix mirrors the #61 --command pattern (su - $LOCAL_USERNAME): - LaunchConfig gains Username; the launcher tags spawn:local-username (CLI Linux path + pkg/launcher provision path). Windows is left unset (single user, no su). - provider.Config gains LocalUsername; ec2.go maps the spawn:local-username tag. - runPreStop validates the username (security.ValidateUsername — never interpolate an untrusted tag into a shell user) and runs the hook via `su - <user> -c` when set; empty/invalid/absent (older instances) falls back to the legacy root shell. sysShellCommand gains the user arg on linux/other; Windows ignores it. Tests: buildTags writes spawn:local-username (and omits it when unset); linux sysShellCommand wraps in `su - <user> -c` vs bare `sh -c`. Builds on linux/darwin/windows; vet clean. Fixes #63
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
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.
Fixes #63 — silent data loss (confirmed by #184: a real 48h g5.12xlarge run lost ~110k detections / ~$270 because
--pre-stop 'aws s3 sync ~/output …'ran as root →~=/root→ synced an empty dir and "succeeded" copying nothing; the NVMe was then wiped on terminate).Root cause
spored is a root systemd service, and
sysShellCommandwas a baresh -c <hook>— so the hook inherited root's$HOME=/root. Any hook using~,$HOME, or a relative path silently targeted the wrong location. It hits the flag's own documented example (aws s3 sync ~/results …).Fix (mirrors the #61
--commandpattern,su - $LOCAL_USERNAME)LaunchConfiggainsUsername; the launcher tagsspawn:local-username— CLI Linux path (cmd/launch.go, only whenTargetOS != windows) and the headlesspkg/launcherprovision path. Windows left unset (single user, nosu).provider.ConfiggainsLocalUsername;pkg/provider/ec2.gomaps thespawn:local-usernametag.runPreStopvalidates the username (security.ValidateUsername— never interpolate an untrusted tag into a shell user) and runs the hook viasu - <user> -cwhen set. Empty / invalid / absent (older instances) → falls back to the legacy rootsh -c, so this is non-breaking.sysShellCommandgains theuserarg onsys_linux.go+sys_other.go;sys_windows.goignores it.Tests
TestBuildTags_LocalUsername— tag written whenUsernameset, omitted otherwise.TestSysShellCommand_RunAsUser/_NoUserFallsBackToRoot(linux build tag) — argv issu - <user> -c <hook>vs baresh -c.go vetclean all three; fullpkg/agent ./pkg/aws ./pkg/provider ./pkg/launcher ./cmdgreen.Note: the linux-only
sysShellCommandtest executes on the orion linux runners (can't run a//go:build linuxtest binary on the darwin dev box, but it compiles underGOOS=linux go vet).Fixes #63. (Related #184 follow-ups — a "pre-stop synced 0 bytes" loud signal and the reaper-bypass gap — are separable and not in this PR.)