You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
--pre-stop runs as root, should run as the instance user #63
The --pre-stop hook runs as root (spored is a root systemd service, and runPreStop does exec.Command("sh", "-c", a.config.PreStop) — pkg/agent/agent.go:1351). It should run as the instance's primary user, matching how --command runs (su - $LOCAL_USERNAME after #61).
Why it matters
A pre-stop hook is the user's workload cleanup (the flag's own example is aws s3 sync /results s3://bucket/). Running it as root means:
Wrong $HOME / environment vs. how the workload ran.
Files it creates/copies are owned by root, not the user.
Privilege mismatch — it can touch things the workload couldn't, and may use different credential resolution than the user's session.
For consistency and least-surprise, pre-stop should execute in the same user context as --command and the interactive shell.
Fix sketch
spored doesn't currently know the instance's local username (no spawn:user tag / config field). So:
Write a spawn:local-username tag at launch (the bootstrap already has $LOCAL_USERNAME).
Read it into the agent config (pkg/provider/ec2.go tag→config mapping, alongside pre-stop/on-complete).
runPreStop runs su - <user> -c '<pre-stop>' when the username is known, falling back to the current behavior if not (older instances without the tag).
Context
Surfaced during #61 Tier 2 work — --command was fixed to run as $LOCAL_USERNAME (it had been hardcoded to a nonexistent local user); pre-stop has the inverse problem (runs as root). Keep them consistent.
Severity escalation: this causes silent DATA LOSS, not just ownership/consistency
Hit this in production (BuckAI/fieldwork SAM inference). A long GPU job wrote ~110k detections to instance-store scratch, with --pre-stop 'aws s3 sync ~/output s3://bucket/...' as the durability safety net. At TTL-terminate, pre-stop ran as root, so ~/output resolved to /root/output (empty) instead of the workload's /home/ec2-user/output. The sync 'succeeded' copying nothing; the instance-store data was wiped on terminate. 48h of g5.12xlarge ($270) and all results lost.
The flag's own documented example is aws s3 sync /results s3://bucket/ — the canonical use is flushing the workload's output before teardown. Running as root breaks exactly that, silently, whenever the hook uses ~, $HOME, or a relative/login-shell-dependent path. So this isn't just least-surprise — it's a data-durability bug for the flag's primary purpose.
Suggest re-labeling beyond consistency: pre-stop running in the wrong user context can silently lose the data it exists to save. The fix sketched above (run pre-stop as $LOCAL_USERNAME via the spawn:local-username tag, same as #61 did for --command) is the correct one.
Severity bump — this is silent data loss, not just consistency/ownership. Confirmed via #184 (closed as a dup): a real 48h g5.12xlarge SAM run lost 110k detections ($270 compute) because --pre-stop 'aws s3 sync ~/output s3://…' ran as root, so ~ → /root, and it synced the empty /root/output instead of the workload's /home/ec2-user/output. The sync "succeeded" copying nothing — no error, no warning, and the data was on instance-store NVMe (wiped on terminate). That's the worst failure shape: a hook that exists specifically to flush results silently flushes the wrong (empty) directory.
It hits the flag's own documented example (aws s3 sync ~/results … / /results), so the canonical use case is the broken one.
Verified the root cause in code matches the fix sketch exactly: sysShellCommand (pkg/agent/sys_linux.go:208) is a bare sh -c <command> with no uid/HOME switch, and spored is a root systemd service → root $HOME=/root. The --command path already solved the inverse problem in #61 with su - $LOCAL_USERNAME, so there's a known-good pattern to mirror.
(spawn has no priority:* labels, so I can't bump a label — flagging in-thread instead. Adding area:storage since the impact is data persistence.)
Recommend prioritizing. I can implement the 3-step fix as sketched (write spawn:local-username at launch → read into agent config → su - <user> -c in runPreStop, falling back to current behavior when the tag is absent for older instances). Want me to take it? It pairs naturally with the #184 follow-ups I'd flagged there (a loud "pre-stop synced 0 bytes / is best-effort" signal, and the reaper-bypass gap) — though those are separable.
Activity
fix: --command as instance user, idempotent IAM, Tier 2 fixes (#61, #64…
scttfrdmn commentedon Jun 16, 2026
Severity escalation: this causes silent DATA LOSS, not just ownership/consistency
Hit this in production (BuckAI/fieldwork SAM inference). A long GPU job wrote ~110k detections to instance-store scratch, with
--pre-stop 'aws s3 sync ~/output s3://bucket/...'as the durability safety net. At TTL-terminate, pre-stop ran as root, so~/outputresolved to/root/output(empty) instead of the workload's/home/ec2-user/output. The sync 'succeeded' copying nothing; the instance-store data was wiped on terminate.48h of g5.12xlarge ($270) and all results lost.The flag's own documented example is
aws s3 sync /results s3://bucket/— the canonical use is flushing the workload's output before teardown. Running as root breaks exactly that, silently, whenever the hook uses~,$HOME, or a relative/login-shell-dependent path. So this isn't just least-surprise — it's a data-durability bug for the flag's primary purpose.Suggest re-labeling beyond consistency: pre-stop running in the wrong user context can silently lose the data it exists to save. The fix sketched above (run pre-stop as
$LOCAL_USERNAMEvia thespawn:local-usernametag, same as #61 did for --command) is the correct one.scttfrdmn commentedon Jun 16, 2026
Severity bump — this is silent data loss, not just consistency/ownership. Confirmed via #184 (closed as a dup): a real 48h g5.12xlarge SAM run lost
110k detections ($270 compute) because--pre-stop 'aws s3 sync ~/output s3://…'ran as root, so~→/root, and it synced the empty/root/outputinstead of the workload's/home/ec2-user/output. The sync "succeeded" copying nothing — no error, no warning, and the data was on instance-store NVMe (wiped on terminate). That's the worst failure shape: a hook that exists specifically to flush results silently flushes the wrong (empty) directory.It hits the flag's own documented example (
aws s3 sync ~/results …//results), so the canonical use case is the broken one.Verified the root cause in code matches the fix sketch exactly:
sysShellCommand(pkg/agent/sys_linux.go:208) is a baresh -c <command>with no uid/HOME switch, and spored is a root systemd service → root$HOME=/root. The--commandpath already solved the inverse problem in #61 withsu - $LOCAL_USERNAME, so there's a known-good pattern to mirror.(spawn has no
priority:*labels, so I can't bump a label — flagging in-thread instead. Addingarea:storagesince the impact is data persistence.)Recommend prioritizing. I can implement the 3-step fix as sketched (write
spawn:local-usernameat launch → read into agent config →su - <user> -cinrunPreStop, falling back to current behavior when the tag is absent for older instances). Want me to take it? It pairs naturally with the #184 follow-ups I'd flagged there (a loud "pre-stop synced 0 bytes / is best-effort" signal, and the reaper-bypass gap) — though those are separable.chore(release): v0.54.0 (#188)
feat(ttl-reaper): graceful pre-stop flush via SSM before terminate (#187
plugin: add as_user for remote steps (unblocks Globus, verified live)
plugin: make registry plugins work end-to-end (verified live) (#347)
Stop the reaper running instance-writable tags as root (#832)