Repository navigation
fix(reaper): ssm:SendCommand needs ssm:resourceTag, not ec2:ResourceTag - #665
Merged
Merged
Conversation
Follow-up to #652, found by simulating the DEPLOYED role rather than trusting that a granted action means an authorized one. #652 scoped ssm:SendCommand with ec2:ResourceTag/spawn:managed. A condition key belongs to the service of the ACTION, not of the resource: ec2:ResourceTag is an EC2 key and is absent from the request context of an ssm:* call, so the StringEquals can never match and the statement is an implicit DENY. Simulated against the live role in 435415984226: ssm:SendCommand on a spawn:managed instance, ec2:ResourceTag -> implicitDeny ssm:SendCommand on the same instance, ssm:resourceTag -> allowed ssm:SendCommand on AWS-RunShellScript -> allowed So the action was granted, #652's drift gate passed, and REAPER_GRACEFUL still could not send a command — the exact failure #652 set out to fix, one layer deeper. My own #652 changelog entry described this trap for fsx:ResourceTag vs aws:ResourceTag and I then walked into it for ssm. The TerminateInstances statement keeps ec2:ResourceTag, which is correct there — that IS an ec2: action. Added TestConditionKeysBelongToTheirActionsService, which fails any statement whose service-prefixed condition key does not match its action's service (aws: being the global namespace and valid anywhere). #652's gate checked which actions were granted; it could not see whether a grant could authorize, which is precisely the gap. Confirmed to fail when the ec2:ResourceTag form is restored. Also ruled out a false alarm on the way: simulate-principal-policy with BOTH the instance and document ARNs in one call returns a single unresolved result and reads as a deny. Evaluating each resource separately is what isolated the real cause — the document grant (arn:aws:ssm:*:*:document/AWS-RunShellScript) was fine all along.
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
This was referenced Oct 4, 2026
scttfrdmn
added a commit
that referenced
this pull request
Oct 11, 2026
…ts first test (#817) (#826) `spawn onboard` builds the role the hosted portal assumes INSIDE a customer's BYOA account, so every grant is against someone else's infrastructure. Four defects in ~25 lines of a file with no test at all — which is most of why they survived. ## ssm:StartSession on every instance, unconditioned Granted on arn:aws:ec2:*:*:instance/* with NO tag condition, while every destructive action beside it was gated on spawn:managed. A portal compromise meant an interactive root shell on arbitrary NON-spawn production instances in every onboarded account. Now conditioned on ssm:resourceTag/spawn:managed — the ssm: key, NOT ec2:. A condition key belongs to the service of the ACTION, and an ec2: key is simply absent from an ssm: request context, so a StringEquals on it can never match and the statement becomes a silent implicit DENY (#665). The repo has shipped that trap before. Split from the SSM document grant: StartSession authorizes against the instance AND the document separately, and a document carries no spawn:managed tag, so one statement covering both would condition the document too and deny everything. ## ec2:CreateTags unconditioned — the #174 defect, never propagated here pkg/aws/iam.go:912 documents it: "a compromised spore could tag ANY instance spawn:managed=true and then terminate it". That fix landed in the spored policies and never reached this file, so two API calls terminated any instance in an onboarded account. It needed adapting rather than copying, because this role LAUNCHES: tagging at RunInstances time cannot satisfy a resource-tag condition — the tag is what is being created. So it is split in two: ec2:CreateAction = RunInstances tag at launch ec2:ResourceTag/spawn:managed = true retag an already-managed instance Neither lets the holder tag a stranger's instance. ## iam:PassRole could never match The resource was built from a variable defaulting to "spored-instance-profile" — an instance PROFILE name in a ROLE ARN slot. The role is aws.SporedRoleName. So the grant matched nothing and the portal's RunInstances was denied. An IAM grant that cannot match is not a safe failure: it reads as working while the feature it enables is simply broken, which is why this went unnoticed. --spored-profile is kept as a deprecated alias bound to the same variable, so existing invocations keep working — and now actually work, since the value is finally used as a role name. ## cmd/onboard_test.go — the file's first test Four gates, each verified against a compiling revert that restores the original defect: un-condition CreateTags -> "granted with NO condition on [*]" drop the StartSession tag -> two gates fail ec2:ResourceTag on an ssm: -> "can never match and is a silent action (#665) implicit DENY" profile name in the role ARN -> PassRole gate fails They parse the policy JSON and assert on STRUCTURE, not substrings. A `Contains(policy, "spawn:managed")` would have passed on the original — the statements that carried the condition were always there; the defect was that the ones that mattered did not. And the requirement is a list of instance-mutating ACTIONS rather than of statements, so a future statement inherits it. ## No existing role needs remediation spore-portal-accounts Count=0 spore-portal-onboard (compute) NoSuchEntity No account has ever been onboarded, so unlike #797 and #812 there is no deploy gap — the fix applies to every future onboard. That also independently corroborates the PassRole finding: a grant that can never match means onboarding was broken, consistent with nobody having used it. make check green across all 9 nested modules, check-docs, changelog, semgrep 0 findings, Tier 0 e2e with -count=1 (68s).
scttfrdmn
added a commit
that referenced
this pull request
Oct 11, 2026
pkg/reaperiam.ScanSelfPolicyDocument — the inline policy `spawn reaper deploy` writes — granted ssm:SendCommand on Resource "*" with no condition, and the reaper invokes DocumentName "AWS-RunShellScript". That is arbitrary shell as root on anything SSM-managed in the account, which strictly dominates the ec2:TerminateInstances the same document tag-gates with considerable care. The correct shape already existed in the cross-account template; the scan-self copy never got it. SendCommand is now split three ways: scoped to arn:aws:ec2:*:*:instance/* with ssm:resourceTag/spawn:managed, a separate unconditioned grant on the one document the reaper names (a document carries no tag, so conditioning it would deny every call), and GetCommandInvocation left on "*" because it takes no resource ARN. ManagedSSMTagCondition is new and deliberately separate from the ec2: one: a condition key belongs to the service of the ACTION, so reusing ManagedTagCondition here yields a statement IAM accepts and never authorizes (#652/#665). Two gates, both watched failing against compiling reverts: TestEveryDestructiveActionIsContained (the existing gates assert that what the reaper calls is granted, which is blind to a grant being too broad) and TestSSMActionsUseSSMConditionKeys. The first caught a mistake while being written — it listed ec2:DeleteTags, which the reaper does not hold, and refused to let the list claim coverage it lacked. Also drops a stale comment claiming neither the template nor the cross-account role granted these actions. Refs GHSA-2hfh-q6jv-qgjp Closes #818
This was referenced Oct 15, 2026
Closed
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.
Follow-up to #652 — the grant I added there could not actually authorize. Found by simulating the deployed role rather than trusting that a granted action means an authorized one.
The bug
#652 scoped
ssm:SendCommandwithec2:ResourceTag/spawn:managed.A condition key belongs to the service of the ACTION, not of the resource.
ec2:ResourceTagis an EC2 key and is simply absent from the request context of anssm:*call — so theStringEqualscan never match and the statement is an implicit deny.Simulated against the live role in 435415984226:
SendCommandon aspawn:managedinstance,ec2:ResourceTagssm:resourceTagSendCommandonAWS-RunShellScriptSo the action was granted, #652's drift gate passed, and
REAPER_GRACEFULstill could not send a command — the exact failure #652 set out to fix, one layer deeper.Galling detail: #652's own changelog entry described this trap for
fsx:ResourceTagvsaws:ResourceTag, and I then walked straight into it forssm.TerminateInstanceskeepsec2:ResourceTag, which is correct there — that is anec2:action.Why a gate, not just a fix
#652's gate checks which actions are granted. It cannot see whether a grant can authorize, which is exactly the gap.
TestConditionKeysBelongToTheirActionsServicenow fails any statement whose service-prefixed condition key doesn't match its action's service (aws:being the global namespace, valid anywhere).Confirmed to fail when the
ec2:ResourceTagform is restored, naming the action and the mismatched key.A false alarm ruled out on the way
simulate-principal-policywith both the instance and document ARNs in one call returns a single unresolved result (arn:aws:ssm:${Region}:${Account}:${RelativeId}) and reads as a deny. Evaluating each resource separately is what isolated the real cause — the document grant (arn:aws:ssm:*:*:document/AWS-RunShellScript) was fine all along, including against the empty-account ARN that AWS-owned documents use.Deployment
The stack in 435415984226 was updated with the broken form minutes ago (one in-place
Modify, no replacement). I'll redeploy with this fix and re-verify by simulation; the role ARN and trust policy are unaffected either way.