Repository navigation
fix(reaper): grant ssm: on the cross-account role so REAPER_GRACEFUL works there - #657
Merged
Merged
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
…works there The graceful path asks spored to shut down cleanly over SSM before the external terminate. In cross-account mode — the PRODUCTION configuration (ScanSelf=false, RoleArns pointing at spawn-ttl-reaper-ec2) — those calls run under the assumed role, and that role granted no ssm: actions at all. So the asymmetry did not close, it inverted: scan-self got the grants and the mode actually deployed did not. Checked the consequence before fixing, because a missing grant can mask a worse bug. It does not here: tryGracefulPreStop is best-effort and `r.terminate(...)` after it ALWAYS runs, so #72's hard-deadline guarantee held throughout. Graceful mode silently became an immediate hard kill — degraded, not dangerous. The #625 drift gate only ever read the scan-self policy, which is precisely why this survived it. Both roles are now checked against the same discovered call set, plus a second test that fails if either role grants something the other does not — the two do the same per-account work, one natively and one assumed, so a one-sided grant means a feature that works in one deployment mode and silently no-ops in the other. Confirmed by removing the new grants: both gates fail, naming ssm:SendCommand and ssm:GetCommandInvocation. Scoping: SendCommand is limited to spawn:managed instances (the same tag rail as TerminateInstances) plus the single AWS-RunShellScript document; GetCommandInvocation has no resource-level ARN and only reads the result of a command this role issued. Also corrects a misleading comment that read as a contradiction. pkg/reaperiam said fsx:DeleteFileSystem "cannot be tag-conditioned", while the cross-account role tag-conditions it. Both are true — they are DIFFERENT keys. FSx exposes no service key fsx:ResourceTag for the action; the global aws:ResourceTag/${TagKey} does work. Verified by IAM policy simulation: tag present and "true" -> allowed tag absent -> implicitDeny tag present and "false" -> implicitDeny Deliberately NOT adopting the condition in scan-self yet. The simulation proves IAM evaluates the key; it cannot prove FSx populates it at request time, because the simulator takes that context from the caller. If FSx does not supply it the condition fails closed — deletes denied, filesystems leak — which is the safe direction but still a regression. Cross-account already carries that dependency; extending it to the path #625 exists to make work should wait for a real ephemeral-FSx reap (#613). CloudFormation validate-template passes. gofmt, vet, full short tests and semgrep (0 findings) clean. Fixes #652
scttfrdmn
force-pushed
the
fix/652-crossaccount-ssm-grants
branch
from
October 4, 2026 02:22
460ea9a to
9b989d1
Compare
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 #652.
The gap
REAPER_GRACEFULaskssporedto shut down cleanly over SSM before the external terminate. In cross-account mode — the production configuration (ScanSelf=false,RoleArns→spawn-ttl-reaper-ec2) those calls run under the assumed role, which granted nossm:actions at all.#625 added them to the Lambda's own execution role, which covers scan-self only. So the asymmetry didn't close — it inverted: scan-self got the grants, and the mode actually deployed didn't.
Checked the consequence before fixing
A missing grant can mask a worse bug, so that came first. It doesn't here:
tryGracefulPreStopis best-effort andr.terminate(...)after it always runs, so #72's hard-deadline guarantee held throughout. Graceful mode silently became an immediate hard kill — degraded, not dangerous. Good to know before adding a grant that changes behaviour.Why it survived #625's drift gate
That gate only ever read the scan-self policy. Both roles are now checked against the same discovered call set, plus a second test that fails if either role grants something the other doesn't — they do the same per-account work, one natively and one assumed, so a one-sided grant means a feature that works in one deployment mode and silently no-ops in the other.
Confirmed by removing the new grants: both gates fail, naming
ssm:SendCommandandssm:GetCommandInvocation.Scoping
SendCommandis limited tospawn:managedinstances — the same tag rail asTerminateInstances— plus the singleAWS-RunShellScriptdocument.GetCommandInvocationhas no resource-level ARN and only reads the result of a command this role issued.A contradiction that wasn't
pkg/reaperiamread as thoughfsx:DeleteFileSystemcouldn't be tag-conditioned, while the cross-account role tag-conditions it. I flagged that as a discrepancy on #613. Both are true — they're different keys. FSx exposes no service keyfsx:ResourceTagfor the action; the globalaws:ResourceTag/${TagKey}does work. Verified by IAM policy simulation:Deliberately not adopting the condition in scan-self yet. The simulation proves IAM evaluates the key; it cannot prove FSx populates it at request time, because the simulator takes that context from the caller. If FSx doesn't supply it, the condition fails closed — deletes denied, filesystems leak. That's the safe direction but still a regression. Cross-account already carries that dependency; extending it to the path #625 exists to make work should wait for a real ephemeral-FSx reap (#613). The comment now says all of this instead of implying the IAM rail covers something it doesn't.
Verification
aws cloudformation validate-templatepasses;gofmt,go vet, fullgo test -short ./..., andsemgrep scan --config=auto --error .(0 findings) all clean. No deploy — the cross-account role lives in other accounts and rolling it out is a separate, explicit action.