Skip to content

CRITICAL: launch --iam-policy-file omits the spored baseline policy — TTL, --on-complete and --pre-stop all silently dead (the #406 fix covers 2 of 3 role paths) #502

Closed

Description

@scttfrdmn

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 indefinitely

Observed 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 still running at 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-stop to 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-s3 is 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:CreateTags 403 → spawn:spored-version never written. (Relatedly, spawn:version reads 0.1.0 while the binary is spored 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:

Environment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions