Skip to content

fix: launch attaches an instance profile with no access to the workload's bucket (#550) - #559

Merged
scttfrdmn merged 1 commit into
mainfrom
fix/550-iam-profile-bucket-access
Sep 2, 2026
Merged

scttfrdmn merged 1 commit into
mainfrom
fix/550-iam-profile-bucket-access

Conversation

@scttfrdmn

Copy link
Copy Markdown
Contributor

Summary

Fixes #550. spawn launch has two independent IAM instance-profile resolution paths, and which one a given invocation lands on is decided entirely by whether that call passed any IAM configuration — not by any property of the workload or account:

  • Callers that pass IAM config (any --iam-role/--iam-policy/--iam-policy-file, or spawn task run's built-in scoped S3 policy, or a pool worker's SQS+S3 policy) call CreateOrGetInstanceProfile, which creates/reuses a profile scoped to exactly what was asked for.
  • Callers that pass no IAM config (a bare spawn launch, spawn resume, a batch queue with no --iam-role, a sweep row with no iam_role:) call SetupSporedIAMRole, which always returns the same fixed shared spored-instance-profile — no data-bucket access beyond whatever was separately attached to that exact role name.

Two outwardly-identical spawn launch invocations can therefore silently diverge, and the one that lands on the shared profile 403s on its first S3 call minutes into a paid run, deep inside a detached provisioning script — reading as a missing object rather than a missing permission.

What's in this PR (issue's suggested fixes, in order)

  1. Bucket preflight — scoped down, with reasoning. Outside spawn task run (which already knows its buckets from TaskSpec.Inputs/Outputs/S3ReadWrite and already scopes its own profile correctly), spawn has no signal today for which bucket a plain spawn launch invocation's workload needs. There's no existing --s3/bucket flag to preflight against, and inventing one as a side effect of this fix would be exactly the kind of scope creep the issue asks to avoid. Not implemented in this pass — flagged here as a narrower follow-up if it's wanted (it would need its own flag design).
  2. Explicit, visible profile selection — done.
    • --instance-profile NAME attaches an existing profile verbatim, bypassing all --iam-role/--iam-policy/--iam-policy-file resolution and the spored-instance-profile default — wired into the single-instance, sweep, and batch-queue launch paths.
    • spawn launch's own output (TUI success box + -o json) now prints the resolved iam_instance_profile — previously invisible anywhere except ec2:DescribeInstances. spawn task diagnose also gained an IAM profile: line (spawn list/spawn status already showed it).
  3. Fallback heuristic documented — done. pkg/aws/iam.go now states the exact mechanism (which callers hit which function, and why) directly on CreateOrGetInstanceProfile and SetupSporedIAMRole, plus a CHANGELOG entry.
  4. Orphaned spawn-instance-<hash> profiles — noted, not implemented. A comment on generateRoleName documents that these are a deliberate safe-reuse default, not an oversight, and that garbage-collecting them is a different (IAM-deletion) risk class deserving its own issue — per the task's explicit instruction not to implement GC here.

Test plan

  • New Tier 0 tests (test/e2e/tier0_iam_profile_test.go), run against Substrate:
    • TestTier0_IAMProfileResolution_ConsistentAcrossIdenticalLaunches — two bare launches with no IAM flags resolve to the same profile.
    • TestTier0_IAMProfileResolution_SameIAMFlagsConsistent — two launches with the same --iam-policy-file (fresh emulator accounts) resolve to the same profile name.
    • TestTier0_InstanceProfileFlag_AttachesVerbatim — --instance-profile attaches the named profile with no resolution.
    • TestTier0_InstanceProfileFlag_BeatsIAMRoleFlags — --instance-profile wins over --iam-role when both are given.
  • Fail-without/pass-with verified: reverted the fix (git stash), confirmed the two --instance-profile tests fail with unknown flag: --instance-profile; restored the fix, all 4 pass.
  • Existing Tier 0 IAM/sweep suite (TestTier0_Sweep*, TestTier0_IAM*) still green — 30/30 tests pass.
  • Full Tier 0 e2e suite green (go test -tags e2e_tier0 ./test/e2e/...).
  • make check clean (fmt, vet, staticcheck warnings pre-existing/unrelated, short tests).
  • make gen-docs / make check-docs — docs-gen/launch.md regenerated and committed with the new flag.
  • Nested lambda modules (lambda/*/) all build cleanly with no go.mod drift.
  • CHANGELOG.md ## [Unreleased] updated with ### Added/### Fixed entries referencing launch attaches an instance profile with no access to the workload's bucket, and the failure surfaces minutes later as a 403 on a paid instance #550.

🤖 Generated with Claude Code

@codecov

codecov Bot commented Sep 2, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 3.44828% with 28 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
cmd/launch_single.go 0.00% 15 Missing ⚠️
cmd/launch_sweep.go 0.00% 8 Missing ⚠️
cmd/launch_batchqueue.go 0.00% 3 Missing ⚠️
cmd/task.go 0.00% 2 Missing ⚠️

📢 Thoughts on this report? Let us know!

…ad's bucket (#550)

spawn has two independent IAM instance-profile resolution paths that a given
`spawn launch` invocation lands on based solely on whether it passed any IAM
configuration: CreateOrGetInstanceProfile (scoped to what was asked for) when
any --iam-role/--iam-policy/--iam-policy-file flag (or a task/pool-worker's
built-in policy) is present, or SetupSporedIAMRole (a fixed shared
spored-instance-profile with no data-bucket access) when none is. Two
outwardly identical launches can therefore silently diverge, and the wrong
one 403s on its first S3 call minutes into a paid run.

This documents the mechanism at both call sites in pkg/aws/iam.go, adds
`--instance-profile NAME` to bypass all resolution (single-instance, sweep,
and batch-queue launch paths), and surfaces the resolved profile in `spawn
launch`'s own output and `spawn task diagnose` (list/status already showed
it). A full launch-time bucket-reachability preflight (the issue's #1
suggestion) is not included: outside `spawn task run` (which already scopes
its own profile from TaskSpec Inputs/Outputs), spawn has no signal today for
which bucket a plain `spawn launch` invocation's workload needs, so there is
nothing to preflight against without inventing new required input this fix
intentionally does not add.
@scttfrdmn
scttfrdmn force-pushed the fix/550-iam-profile-bucket-access branch from 7f08f8e to a9cf129 Compare September 2, 2026 23:26
@scttfrdmn
scttfrdmn merged commit 78e2480 into main Sep 2, 2026
7 checks passed
@scttfrdmn
scttfrdmn deleted the fix/550-iam-profile-bucket-access branch September 2, 2026 23:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

launch attaches an instance profile with no access to the workload's bucket, and the failure surfaces minutes later as a 403 on a paid instance

1 participant