Repository navigation
Description
Summary
spawn launch --iam-policy-file FILE creates an instance role containing only the caller's policy. The spored-baseline-policy is not attached, so spored gets 403 UnauthorizedOperation on ec2:DescribeTags, logs it as a Warning, and proceeds with an empty config:
2026/08/17 22:40:32 spored v0.100.0 starting...
2026/08/17 22:40:32 Warning: Could not load config from tags: operation error EC2: DescribeTags,
StatusCode: 403, UnauthorizedOperation: ... assumed-role/spawn-instance-d1029e0a/i-03c73299d8b91b416
is not authorized to perform: ec2:DescribeTags
2026/08/17 22:40:32 Config: TTL=0s, IdleTimeout=0s, Hibernate=false <-- every lifetime control is now zero
2026/08/17 22:40:32 DNS registration skipped: no DNS name configured (no spawn:dns-name tag on the instance)
2026/08/17 22:40:32 Monitoring started
TTL=0s while the instance carries spawn:ttl=8h and spawn:ttl-deadline=2026-08-18T06:39:51Z. The monitor loop then ran 283 healthy ticks over 4h43m and enforced nothing. This is exactly #65/#66/#406 territory, arrived at through a different door: the daemon is active, the unit file is correct, PrivateTmp=no, and spored can read the sentinel — it just never looks, because it does not know it was asked to.
This is the failure mode that "everything dies" is supposed to make impossible. Nothing was going to reap these instances: no TTL, no idle timeout, no completion file, and no ec2:TerminateInstances in the role even if the config had loaded. 7 × c8g.48xlarge = 1344 vCPU at $53.60/h, indefinitely. It was caught by a human looking at describe-instances.
Root cause: the #406 fix was applied to 2 of 3 sibling paths in createIAMRole
pkg/aws/iam.go has three independent ways to attach a caller policy. Two include the spored grants; the one reachable from spawn launch does not.
| path | set by | spored self-management grants? |
|---|---|---|
config.Policies (shorthand templates) |
--iam-policies |
✅ buildInlinePolicy() starts from c.sporedSelfManagementStatements() (iam.go:690) |
config.InlinePolicyJSON |
spawn task, spawn pool |
✅ explicitly attaches spored-baseline-policy — this is the #406 fix (iam.go:565-582) |
config.PolicyFile |
spawn launch --iam-policy-file (cmd/launch_single.go:967) |
❌ attaches spawn-custom-policy and nothing else (iam.go:546-561) |
The #406 fix even documents the hazard in a comment 8 lines below the hole:
// Attach custom policy from file
if config.PolicyFile != "" {
policyDoc, err := os.ReadFile(config.PolicyFile)
...
_, err = iamClient.PutRolePolicy(ctx, &iam.PutRolePolicyInput{
RoleName: aws.String(roleName),
PolicyName: aws.String("spawn-custom-policy"),
PolicyDocument: aws.String(string(policyDoc)),
})
// <-- no spored baseline, no ensure, no warning
}
// Attach a caller-supplied scoped policy passed as a string (no file). This
// path bypasses buildInlinePolicy, so also attach the spored self-management
// baseline -- otherwise spored can't read its own tags and TTL/on-complete
// silently never fire (spawn#406).
if config.InlinePolicyJSON != "" { ... attaches spored-baseline-policy ... }Resulting role, verified with aws iam get-role-policy / list-attached-role-policies:
role spawn-instance-d1029e0a
inline: spawn-custom-policy (my 3 S3 statements, exactly as supplied)
managed: AmazonSSMManagedInstanceCore
No ec2:* action of any kind. Not DescribeTags, not TerminateInstances.
Reproduce
cat > p.json <<'EOF'
{"Version":"2012-10-17","Statement":[{"Effect":"Allow","Action":["s3:PutObject"],
"Resource":"arn:aws:s3:::SOME-BUCKET/prefix/*"}]}
EOF
spawn launch c8g.large --iam-policy-file p.json --ttl 30m \
--on-complete terminate --completion-file /tmp/SPAWN_COMPLETE
# on the instance
sudo head -6 /var/log/spored.log # => "Config: TTL=0s, IdleTimeout=0s" + DescribeTags 403
touch /tmp/SPAWN_COMPLETE # never honored
# instance outlives its 30m TTL indefinitelyObserved consequences on the affected fleet
All from spawn: tags that were correctly written by spawn and never read back by spored:
spawn:ttl=8h,spawn:ttl-deadline=...T06:39:51Z→ not enforced (TTL=0s).spawn:completion-file=/tmp/SPAWN_COMPLETE,spawn:on-complete=terminate,spawn:completion-delay=30s→ sentinel written at 02:06:24, instance stillrunningat 03:23 (77 min later).grep -i 'complet\|SPAWN_COMPLETE' /var/log/spored.log→ zero matches for the entire run; spored never enters the completion path.spawn:pre-stop=bash /home/ec2-user/flush.sh→ never ran. A workflow relying on--pre-stopto flush results to S3 at teardown would have lost them with no error. (Ours survived only because we upload artifacts as they are produced.)spawn:dns-name=biosurf-dipfix-s3is present, yet the log says "no DNS name configured (no spawn:dns-name tag on the instance)". Useful signal: the message asserts the tag's absence when the truth is that the tag is unreadable.ec2:CreateTags403 →spawn:spored-versionnever written. (Relatedly,spawn:versionreads0.1.0while the binary isspored version 0.100.0; happy to file separately.)
Suggested fix
1. Close the hole (the actual bug). Attach sporedBaselinePolicyDoc() in the PolicyFile branch too. Better: hoist it out of all three branches and attach it unconditionally in createIAMRole — the grants are static, self-scoped (ec2:ResourceTag/spawn:managed=true), and required by every spawn-managed instance, so there is no configuration in which omitting them is correct. That also removes the possibility of a fourth caller path reintroducing this. updateInlinePolicy needs the same treatment, or a cached role from before the fix stays broken across relaunches.
2. Make the class of bug non-silent (why it cost 5 hours of a 1344-vCPU fleet). A lifecycle daemon that cannot read its lifecycle config should not degrade to "no lifecycle." Options, roughly in order of preference:
- Do not require the round trip at all.
spawnwrote those tags; it already had TTL, on-complete, completion-file and pre-stop at launch time. Seeding them into user-data //etc/spawn/spored.jsonand treatingDescribeTagsas a refresh mechanism makes teardown independent of instance-role IAM. This also fixes spored: short task can signal completion before on-complete tag is visible → no prompt self-terminate (TTL backstop) #270 (short task signals completion before the tag is visible) for free, and narrows ttl-reaper: no alarm detects the reaper NOT RUNNING — all four #469 alarms are notBreaching, so absence is silent #475's blast radius. - Fail closed on first config load. If
DescribeTagsfails at startup and no seeded config exists, exit non-zero.Restart=on-failurewill retry; a role that is genuinely missing grants then shows up as a crash-looping unit instead of a silent 283-tick no-op. - Preflight in
spawn launch. After creating the profile, simulateec2:DescribeTags+ec2:TerminateInstancesfor the role (iam:SimulatePrincipalPolicy) and refuse to launch — or loudly warn — when the instance could not reap itself. A 30-second check before committing to an instance that cannot die. - At minimum, log the 403 at ERROR with the consequence spelled out (
"TTL/on-complete/pre-stop are DISABLED") rather thanWarning: Could not load config from tags, and surface it inspawn list/spawn statusas a per-instance health flag. ttl-reaper: no alarm detects the reaper NOT RUNNING — all four #469 alarms are notBreaching, so absence is silent #475 already establishes that absence of reaping is the thing no alarm catches; this is the same lesson one layer down.
Environment
spored version 0.100.0, Amazon Linux 2023, aarch64,c8g.48xlarge, us-east-1- launched via
spawn launch --iam-policy-file ... spored.service:active (running),enabled,PrivateTmp=no,User=(root),MainPIDstable 4h43m,%CPU 0.0- spored can see the sentinel —
sudo ls /proc/$MAINPID/root/tmp/SPAWN_COMPLETEresolves — so this is not CRITICAL: PrivateTmp=true hides /tmp/SPAWN_COMPLETE from spored — completion-based on-complete/pre-stop never fire #66 - the monitor loop is running (
monitor tick 283) — so this is not CRITICAL: spored monitor loop never runs after startup — TTL/idle/on-complete/pre-stop all silently dead #65 - note for anyone diagnosing this:
journalctl -u sporedshows only theStartedline despiteStandardOutput=journal; spored writes to/var/log/spored.log(fd 4). The empty journal reads like a hung daemon and is a red herring.
Activity
fix: status no longer presents an unread TTL as a resolved "none"
fix: status no longer presents an unread TTL as a resolved "none"
fix: status no longer presents an unread TTL as a resolved "none"
fix: status no longer presents an unread TTL as a resolved "none" (#522)