Skip to content

fix: attach spored baseline policy unconditionally on every instance role - #503

Merged
scttfrdmn merged 1 commit into
mainfrom
fix/502-policyfile-baseline-policy
Aug 18, 2026
Merged

scttfrdmn merged 1 commit into
mainfrom
fix/502-policyfile-baseline-policy

Conversation

@scttfrdmn

Copy link
Copy Markdown
Contributor

Summary

CRITICAL — spawn launch --iam-policy-file created an instance role missing the spored-baseline-policy grants entirely. createIAMRole had three independent branches for attaching a caller policy:

path set by spored self-management grants?
config.Policies --iam-policies ✅ folded in via buildInlinePolicy
config.InlinePolicyJSON spawn task/spawn pool ✅ explicitly attached (spawn#406)
config.PolicyFile spawn launch --iam-policy-file ❌ nothing

Without ec2:DescribeTags, spored logs the resulting 403 as a Warning and falls back to TTL=0s, IdleTimeout=0s — a lifetime correctly written to instance tags is silently never read back or enforced. This was caught on a real fleet: 7× c8g.48xlarge ran 4h43m past an 8h TTL with zero lifecycle controls active, only noticed by a human looking at describe-instances.

Fix: CreateOrGetInstanceProfile now calls a new ensureSporedBaselinePolicy unconditionally on every role it returns — new or cached, regardless of which policy source the caller used — mirroring the existing ensureSSMManagedPolicy guarantee, rather than attaching it inside individual branches of createIAMRole/updateInlinePolicy. This also heals any previously-cached role that predates the fix, and means a future fourth policy source can't reopen the same gap.

Fixes #502.

Test plan

  • New regression test TestCreateOrGetInstanceProfile_PolicyFileGetsSporedBaseline — creates a role via PolicyFile only, asserts spored-baseline-policy is present with the expected grants, and that the caller's own custom policy is still attached unchanged. Verified it fails without the fix (reverted iam.go, confirmed NoSuchEntity: spored-baseline-policy) and passes with it.
  • go build ./..., go vet ./..., make check (fmt/vet/lint/short tests) all clean
  • go test ./pkg/aws/... — full package suite green, including the existing TestCreateOrGetInstanceProfile_Concurrent, TestBuildInlinePolicyIncludesBaseline, TestSporedBaselinePolicyDoc
  • golangci-lint run ./pkg/aws/... — no new findings in touched files
  • CHANGELOG.md updated under ## [Unreleased]

…role (#502)

createIAMRole attached the spored-baseline-policy grants per policy-source
branch: buildInlinePolicy folded them in for the Policies path, and
InlinePolicyJSON attached them explicitly (spawn#406). PolicyFile -- the
path reachable from `spawn launch --iam-policy-file` -- never received that
fix, so a role created that way lacked ec2:DescribeTags entirely. spored
logged the resulting 403 as a Warning and fell back to TTL=0s, silently
disabling TTL, --on-complete and --pre-stop.

CreateOrGetInstanceProfile now calls ensureSporedBaselinePolicy
unconditionally on every role it returns -- new or cached, regardless of
policy source -- mirroring the existing ensureSSMManagedPolicy guarantee,
instead of attaching it inside individual branches of createIAMRole/
updateInlinePolicy. A future fourth policy source can't reopen this gap.

Fixes #502
@codecov

codecov Bot commented Aug 18, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 41.66667% with 14 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
pkg/aws/iam.go 41.66% 12 Missing and 2 partials ⚠️

📢 Thoughts on this report? Let us know!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant