Repository navigation
security: scope the portal onboarding role, and give cmd/onboard.go its first test (#817) - #826
Merged
Merged
Conversation
…ts first test (#817) `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).
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
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.
Closes #817
Detail in private advisory GHSA-w7wx-6439-wff7, to be published when this
merges.
spawn onboardbuilds the role the hosted portal assumes inside a customer'sBYOA 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.
1.
ssm:StartSessionon every instance, unconditionedGranted on
arn:aws:ec2:*:*:instance/*with no tag condition, while everydestructive action beside it was gated on
spawn:managed. A portal compromisemeant an interactive root shell on arbitrary non-spawn production instances
in every onboarded account.
Now conditioned on
ssm:resourceTag/spawn:managed— thessm:key, notec2:. A condition key belongs to the service of the action, and anec2:keyis absent from an
ssm:request context, so aStringEqualson it can nevermatch and the statement becomes a silent implicit deny (#665). This repo has
shipped that trap before.
Split from the SSM document grant:
StartSessionauthorises against theinstance and the document separately, and a document carries no
spawn:managedtag — one statement covering both would condition the documenttoo and deny everything.
2.
ec2:CreateTagsunconditioned — the #174 defect, never propagated herepkg/aws/iam.go:912documents it: "a compromised spore could tag ANY instancespawn:managed=trueand then terminate it". That fix landed in the sporedpolicies 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
RunInstancestime cannot satisfy a resource-tag condition, since the tag iswhat is being created. So it is split:
ec2:CreateAction = RunInstancesec2:ResourceTag/spawn:managed = trueNeither lets the holder tag a stranger's instance.
3.
iam:PassRolecould never matchThe 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'sRunInstanceswas 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-profileis kept as a deprecated alias bound to the same variable, soexisting invocations keep working — and now actually work, since the value is
finally used as a role name.
4.
cmd/onboard_test.go— the file's first testFour gates, each verified against a compiling revert that restores the
original defect:
CreateTagsgranted with NO condition on [*]StartSessiontag conditionec2:ResourceTagon anssm:actioncan never match and is a silent implicit DENY (#665)PassRolegate failsThey parse the policy JSON and assert on structure, not substrings. A
Contains(policy, "spawn:managed")would have passed on the original — thestatements carrying 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
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
PassRolefinding: a grant that can never match meansonboarding was broken, consistent with nobody having used it.
Verification
make checkgreen across all 9 nested modules,check-docs, the changelog gate,semgrep(0 findings), and the full Tier 0 e2e with-count=1(68s).