Skip to content

--iam-role / --iam-policy / --iam-policy-file are silently ignored on the sweep path (0.100.4) #539

Closed

Description

@scttfrdmn

Summary

On the parameter-sweep path (spawn launch --param-file …), the CLI IAM flags are accepted, never read, and never warned about. Every sweep instance gets the shared spored-instance-role instead, so a workload whose only access problem is "this role can't read my bucket" has no CLI-level fix — and finds out by paying for a boot that dies on its first aws s3 call.

This is the same bug class as #525 (CLI spend controls dropped on the sweep path). #525's fix in 0.100.4 covered --ttl, --idle-timeout and --cost-limit; the IAM flags in the same file were not covered.

Version: spawn version → 0.100.4.

Source trace

Flags are declared and bound to package-level vars:

  • cmd/launch_flags.go:133-139 — iamRole, iamPolicy, iamPolicyFile, iamRoleTags, iamAllowFullAccess
  • cmd/launch_flags.go:323-329 — registered on launchCmd, i.e. the same command that takes --param-file

Every read of those vars, from grep -rn '\biamRole\b|\biamPolicyFile\b|\biamPolicy\b' cmd/ | grep -v _test:

  • cmd/launch_single.go:955-969 — the single-instance path (if iamRole != "" || len(iamPolicy) > 0 || … || iamPolicyFile != "")
  • cmd/launch_batchqueue.go:197-198 — the batch-queue path
  • cmd/list.go:288-298, :392-404 — display only, a different iamRole local

cmd/launch_sweep.go never reads any of them. What it does instead:

// cmd/launch_sweep.go:352-361
if firstConfig.IamInstanceProfile == "" {
    instanceProfile, err := awsClient.SetupSporedIAMRole(ctx)   // -> shared "spored-instance-role"
    …
    for i := range configs {
        if cfg.IamInstanceProfile == "" {
            cfg.IamInstanceProfile = instanceProfile
        }
    }
}

So the only IAM control that reaches a sweep row is the param-file key iam_role: (cmd/sweep_keys.go:64 → cmd/sweep.go:236-238 → config.IamInstanceProfile → pkg/aws/client.go:444-447 as IamInstanceProfileSpecification{Name: …}). That works, and it is what we now use.

Reproduction

spawn launch demo --param-file one-row.yaml --no-detach --ttl 1h \
  --iam-policy-file /tmp/scoped.json
# launch log:  "✅ Setting up IAM role (0ms)"
aws ec2 describe-instances --instance-ids <id> \
  --query 'Reservations[].Instances[].IamInstanceProfile.Arn'
# -> arn:aws:iam::…:instance-profile/spored-instance-role
# /tmp/scoped.json was never read; no warning printed; exit 0.

Substituting iam_role: my-profile in the param file's defaults: produces
instance-profile/my-profile on the instance, confirming the sweep path honours the file key and only the file key.

Why this one is worse than the #525 instance of the same class

A dropped --cost-limit wastes bounded time — the TTL still fires. A dropped IAM policy wastes 100% of the run's spend and produces no result, and the failure surfaces inside the workload (fatal error: Unable to locate credentials / AccessDenied) where it reads as a workload or script bug rather than a launch-flag bug. In our case that was a real, if small, bill: instance i-07e500313e0122891, c8g.8xlarge spot, dead 193 s in on its first aws s3 cp, diagnosed only via CloudTrail.

Two things make it hard to catch before launch:

  1. --iam-policy-file is the flag a user reaches for when the docs say "the instance needs access to your bucket", and it exits 0.
  2. The row that fails is byte-identical to the row that succeeds — the difference lives entirely in a flag that had no effect.

Suggested fix

The mechanism already exists in the same file. applyCLISpendControlsToSweep (cmd/launch_sweep.go:728-746) folds CLI flags into the sweep's Defaults, which is the one place that reaches both orchestration paths. Either:

  • (a) extend that to the IAM flags: build the role/policy once per sweep (as launch_single.go:955 does per instance) and set the resulting profile name into Defaults before the IamInstanceProfile == "" check at :352; or
  • (b) if per-sweep role creation is not wanted, reject the flags on the sweep path with a message naming the working alternative: --iam-role/--iam-policy/--iam-policy-file are not supported with --param-file; set iam_role: <instance-profile> under defaults:.

(b) alone would have saved us the launch. Silence is the expensive part; the #526 near-miss rejection is the precedent.

Worth noting for whichever fix lands: iam_role: takes an instance profile name, not a role name, despite the key name and despite --iam-role's help text saying "IAM role name (creates if doesn't exist)". If (a) is implemented, the two spellings should not disagree about which of the two they mean.

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