Repository navigation
Merged
Conversation
This was referenced Oct 15, 2026
Make the stranded Spot replacement alarm actionable; record why the reaper cannot end it (#984)
#996
Merged
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
…ScanSelf drift (#985) The SAM template's ScanSelf branch kept its own copy of the scan-self policy and no gate read it. It had drifted: no #685 network-resource grants (DescribeSecurityGroups/DescribePlacementGroups/DeleteSecurityGroup/ DeletePlacementGroup/CreateTags), and ssm:SendCommand on '*' with no condition, i.e. root shell on any SSM-managed instance in the account. - template.yaml: add the network-resource grants and split SSM the way reaperiam does (SendCommand on instances under ssm:resourceTag/spawn:managed, SendCommand on the AWS-RunShellScript document, GetCommandInvocation on *). - pkg/reaperiam/template_drift_test.go: parse template.yaml and the cross-account role with yaml.v3 (CFN intrinsics kept as long-form maps), explode every statement per action, and require set equality with ScanSelfStatements in effect, action, resources and condition. The ScanSelf branch is discovered from the Condition testing ScanSelf=true; ec2/fsx/ssm actions anywhere else on the function fail; empty parses fail. - Cross-account role: drop the unused ec2:DescribeTags and a no-op !Sub. One recorded, narrower-only exception: fsx:DeleteFileSystem keeps its aws:ResourceTag condition there (#613). Watched the gate fail against: the old template, the old cross-account role, a changed ssm condition key, reaperiam's SendCommand condition set to nil, a SendCommand statement moved outside the branch, and a renamed condition. (#985)
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.
Fixes #985
Stacked on #981 (fix/950 → #961 → #951). Review and merge after those.
What was wrong
lambda/ttl-reaper/template.yamlattaches its own copy of the scan-self policy whenScanSelf=true, and nothing compared it withpkg/reaperiam. It had drifted in two ways:ec2:DescribeSecurityGroups,DescribePlacementGroups,DeleteSecurityGroup,DeletePlacementGroup,CreateTags), so a SAM-deployedScanSelf=truereaper got AccessDenied on every sweep cycle.ssm:SendCommandon'*'with no condition. That is root shell on any SSM-managed instance in the account, the gap Scope the in-account reaper's SSM grant the way the cross-account template already does #818 closed in reaperiam.Change
SendCommandonarn:aws:ec2:*:*:instance/*underssm:resourceTag/spawn:managed=true,SendCommandondocument/AWS-RunShellScript, andGetCommandInvocationon*.pkg/reaperiam/template_drift_test.go:!Subcannot silently compare equal to a literal.ScanSelfStatementsin effect, action, resources and condition. Grouping actions into fewer or more statements does not count as drift.ScanSelf=true, without relying on its name. Fails if any ec2/fsx/ssm action appears anywhere else in the function's policies.NotAction), and on any intrinsic other than${AWS::AccountId}, which it normalises to*.ec2:DescribeTags. The reaper never calls it;TestPolicyGrantsNothingTheReaperDoesNotCallalready establishes that from source.!Subthatsam validate --lintflagged (W1020).fsx:DeleteFileSystemkeeps itsaws:ResourceTagcondition here. reaperiam does not adopt that condition until --fsx-lifecycle ephemeral did not reap the filesystem when the instance terminated (1.2 TiB left AVAILABLE and billing) #613 proves FSx populates the key. The exception fails if it ever goes stale.I chose a gate over generating the template. The template is hand-commented SAM with intrinsics, and a generator would add a build step and a committed artefact that would itself need a drift gate.
Evidence
The new tests pass on the change. I watched them fail against each of these reverts, all of which compile:
ssm:SendCommand on [*])ec2:DescribeTagsextra)ssm:resourceTagkey in the cross-account roleCondition: nil(both YAML copies fail)ssm:SendCommandstatement moved outside the ScanSelf branchOther checks:
sam validate --lintpasses on both templates.golangci-lintis clean onpkg/reaperiam.make check-nestedpasses.make check: the only failure isTestGenerateWrapper_ChownFixesCrossUIDStickyUnlink_Docker, because no Docker daemon is running here. It is unrelated.Deploy (not done; no AWS touched)
ScanSelf=false, so the ScanSelf branch is not attached and its role does not change. A normalmake deployinlambda/ttl-reaper(which reads the live parameters first) is enough to keep the template in step.spawn-ttl-reaper-ec2in each member account, e.g. 435415984226): an optional stack update. It only removes the unusedec2:DescribeTags; the rendered policy is otherwise identical.ScanSelf=true: redeploy to drop the unconditioned SendCommand and gain the Nothing reaps managed MPI security groups or placement groups (19 + 9 orphans found); --mpi creates an SG before validating its own flags #685 grants.