Skip to content

security: scope the portal onboarding role, and give cmd/onboard.go its first test (#817) - #826

Merged
scttfrdmn merged 1 commit into
mainfrom
fix/817-onboard-iam
Oct 11, 2026
Merged

scttfrdmn merged 1 commit into
mainfrom
fix/817-onboard-iam

Conversation

@scttfrdmn

Copy link
Copy Markdown
Contributor

Closes #817

Detail in private advisory GHSA-w7wx-6439-wff7, to be published when this
merges.

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.

1. 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 absent from an ssm: request context, so a StringEquals on it can never
match and the statement becomes a silent implicit deny (#665). This repo has
shipped that trap before.

Split from the SSM document grant: StartSession authorises against the
instance and the document separately, and a document carries no
spawn:managed tag — one statement covering both would condition the document
too and deny everything.

2. 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, since the tag is
what is being created. So it is split:

condition covers
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.

3. 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.

4. cmd/onboard_test.go — the file's first test

Four gates, each verified against a compiling revert that restores the
original defect:

revert diagnostic
un-condition CreateTags granted with NO condition on [*]
drop the StartSession tag condition two gates fail
ec2:ResourceTag on an ssm: action can never match and is a silent implicit DENY (#665)
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 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

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.

Verification

make check green across all 9 nested modules, check-docs, the changelog gate,
semgrep (0 findings), and the full Tier 0 e2e with -count=1 (68s).

…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).
@scttfrdmn scttfrdmn added this to the Security audit 2026-10 milestone Oct 11, 2026
@codecov

codecov Bot commented Oct 11, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 13.33333% with 13 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
cmd/onboard.go 13.33% 12 Missing and 1 partial ⚠️

📢 Thoughts on this report? Let us know!

@scttfrdmn
scttfrdmn merged commit a813c11 into main Oct 11, 2026
7 checks passed
@scttfrdmn
scttfrdmn deleted the fix/817-onboard-iam branch October 11, 2026 17:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Harden the portal onboarding role, and add cmd/onboard.go its first test

1 participant