Repository navigation
fix: attach spored baseline policy unconditionally on every instance role - #503
Merged
Merged
Conversation
…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 Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
This was referenced Aug 18, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
CRITICAL —
spawn launch --iam-policy-filecreated an instance role missing thespored-baseline-policygrants entirely.createIAMRolehad three independent branches for attaching a caller policy:config.Policies--iam-policiesbuildInlinePolicyconfig.InlinePolicyJSONspawn task/spawn poolconfig.PolicyFilespawn launch --iam-policy-fileWithout
ec2:DescribeTags, spored logs the resulting 403 as a Warning and falls back toTTL=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.48xlargeran 4h43m past an 8h TTL with zero lifecycle controls active, only noticed by a human looking atdescribe-instances.Fix:
CreateOrGetInstanceProfilenow calls a newensureSporedBaselinePolicyunconditionally on every role it returns — new or cached, regardless of which policy source the caller used — mirroring the existingensureSSMManagedPolicyguarantee, rather than attaching it inside individual branches ofcreateIAMRole/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
TestCreateOrGetInstanceProfile_PolicyFileGetsSporedBaseline— creates a role viaPolicyFileonly, assertsspored-baseline-policyis present with the expected grants, and that the caller's own custom policy is still attached unchanged. Verified it fails without the fix (revertediam.go, confirmedNoSuchEntity: spored-baseline-policy) and passes with it.go build ./...,go vet ./...,make check(fmt/vet/lint/short tests) all cleango test ./pkg/aws/...— full package suite green, including the existingTestCreateOrGetInstanceProfile_Concurrent,TestBuildInlinePolicyIncludesBaseline,TestSporedBaselinePolicyDocgolangci-lint run ./pkg/aws/...— no new findings in touched filesCHANGELOG.mdupdated under## [Unreleased]