Skip to content

sec(iam): cap every spawn-created role with a permissions boundary - #1609

Merged
scttfrdmn merged 2 commits into
mainfrom
fix/sec-role-permissions-boundary
Nov 12, 2026
Merged

scttfrdmn merged 2 commits into
mainfrom
fix/sec-role-permissions-boundary

Conversation

@scttfrdmn

Copy link
Copy Markdown
Contributor

Summary

Caps every IAM role spawn creates with a customer-managed permissions
boundary
, so that whatever is written onto an instance role — including a
caller's own --iam-policy-file or --iam-managed-policies — the role cannot
be used to administer IAM or reach another account.

Stacks on #1606 (fix/sec-instance-roles, the spored self-scoping +
sporedPolicySchema 2). This PR's base is main so CI runs and it carries
#1606's commit; merge #1606 first and review the last commit.

The boundary

  • A customer-managed policy arn:aws:iam::<account>:policy/spore-host/spawn-instance-boundary.
  • Shape: a broad Allow * ceiling, then explicit Deny of IAM
    administration (create/modify users, roles, groups, policies, access keys,
    assume-role trust, permissions boundaries), organizations:*, account:*,
    and sts:AssumeRole into another account
    (aws:ResourceAccount != ${aws:PrincipalAccount}). iam:PassRole and
    iam:CreateServiceLinkedRole are not denied (the nested and sweep roles
    need them). A * boundary is no containment; an enumerated one breaks broad
    --iam-policy-file workloads, so this denies only the escalation surface.
  • Residual: within the boundary a caller can still give an instance
    data-plane access they do not hold themselves; IAM cannot express
    "role ⊆ caller". An account that needs tighter narrows the boundary's
    resources or launches with --instance-profile.
  • Versioned in place (CreatePolicyVersion + SetAsDefault, pruning the
    oldest non-default version to stay under IAM's five-version cap); the name is
    fixed because the documented baseline names it literally.

Provisioning and roles

  • New roles get the boundary at CreateRole; existing roles get
    PutRolePermissionsBoundary before any policy write, so a role is never
    left with weaker containment mid-launch.
  • The documented user baseline cannot create the boundary. spawn setup-account
    (new, admin) provisions it; the first admin-run launch also creates it. A
    non-admin whose account has no boundary gets an error naming spawn setup-account.
  • spawn cleanup --instance-roles deletes the boundary once no role uses it.

#1607's app role

spawn-instance-app is in the spawn-instance-* family and is created through
the same createOrGetInstanceProfile path, so this change covers it
automatically when #1607 merges. No rebase onto #1607 is needed; nothing
extra is required for the app role.

Onboard (#694)

spawn onboard's portal role drops ec2:StopInstances/StartInstances/
TerminateInstances/CancelSpotInstanceRequests, matching the live portal role
and the BYOA template, and adds an ownership-tag Deny.

What an existing account's admin must run once

spawn setup-account

with credentials allowed to create IAM policies. Re-running upgrades the
boundary when the document changes and is otherwise a no-op.

Until an admin runs it: launches that must create or update an instance
role are refused, with an error naming the command. An admin's own first launch
provisions the boundary as a side effect.

Not yet verified against AWS

No AWS calls were made. Before merging, prove the boundary document with a real
PutRolePolicy/CreatePolicy, run simulate-custom-policy for the allow/deny
cases under the baseline, and confirm a live launch still brings spored up under
the boundary.

Tests

  • pkg/aws/iam_boundary_test.go: new account, existing-boundary, non-admin
    (names the command), retrofit, create/no-op, schema bump, five-version cap, a
    golden for the boundary document (valid JSON, no policy variable in a
    Resource, condition keys belong to their action's service), and the full
    createOrGetInstanceProfile pipeline against the IAM emulator.
  • pkg/instancerole: the boundary deleter (in use → kept; unused+old →
    deleted, versions first; young → kept).
  • cmd: spawn setup-account hermetic test; onboard and sweep gates updated.
  • make check clean except the three checks that fail locally only because the
    worktree path contains a space; the hermetic suite passes; semgrep scan --config=auto --error on the changed paths is clean. GOTOOLCHAIN=go1.27.4.

Refs #694.

@codecov

codecov Bot commented Nov 12, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 78.53659% with 44 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
pkg/aws/iam_boundary.go 86.08% 16 Missing ⚠️
cmd/setup_account.go 59.25% 10 Missing and 1 partial ⚠️
pkg/instancerole/sporedpolicies.go 72.41% 8 Missing ⚠️
pkg/aws/iam.go 66.66% 7 Missing ⚠️
pkg/aws/sweep_role.go 66.66% 2 Missing ⚠️

📢 Thoughts on this report? Let us know!

@scttfrdmn

Copy link
Copy Markdown
Contributor Author

Live verification (spore-host-dev, 2026-11-12):

  • Real policy proofs: CreatePolicy accepted the boundary document, and PutRolePolicy accepted fix(launch): give the job-array id real entropy (#710) #711's documented baseline (no `${aws:PrincipalAccount}` in any Resource).
  • The fix(launch): give the job-array id real entropy (#710) #711 baseline, simulated (13/13 as expected):
    • CreateRole and PutRolePolicy are allowed only with `iam:PermissionsBoundary` set to the spore-host boundary; without it, or with another boundary, they are denied.
    • AttachRolePolicy of AdministratorAccess is denied; AmazonSSMManagedInstanceCore is allowed.
    • CreatePolicyVersion and SetDefaultPolicyVersion on the boundary, and DeleteRolePermissionsBoundary, are explicitly denied.
    • CreateTags `spawn:managed` on an existing instance is explicitly denied; with `ec2:CreateAction=RunInstances` it is allowed.
  • *The boundary as a ceiling over `Allow `: iam:CreateUser, AttachRolePolicy, PutRolePolicy, CreateAccessKey, `organizations:*` and cross-account `sts:AssumeRole` are explicitly denied. S3, EC2, PassRole and same-account AssumeRole are allowed. This matches the documented residual.
  • Live:
    • `spawn setup-account` created `spore-host/spawn-instance-boundary` (v1); a re-run was a no-op.
    • The boundary was retrofitted onto the shared `spored-instance-role` and set on the new nested and task roles.
    • spored under the boundary: tag writes, idle-stop and TTL terminate (including Spot) all work.
    • Nested, task and teardown results are on Scope spored instance permissions to the calling instance #1606.

Account state: the dev account now carries the boundary. Released CLIs keep working there; the boundary only caps what they create.

@scttfrdmn

Copy link
Copy Markdown
Contributor Author

Rebased onto #1606 aaf18a20 (no conflicts). New head 0abc5c5b; local build and pkg/aws tests pass. CI is rerunning.

New roles get the spore-host/spawn-instance-boundary at CreateRole; existing
roles get it via PutRolePermissionsBoundary before any policy write. The
boundary allows a broad data-plane ceiling and denies IAM administration,
organizations/account actions and cross-account AssumeRole, so a role cannot be
used to escalate IAM however its policies are written.

Provisioned by 'spawn setup-account' (admin) or the first admin-run launch; the
documented user baseline cannot create it, and a non-admin is told the command.
'spawn cleanup --instance-roles' deletes it once no role uses it.

Align spawn onboard's portal policy with the live role and the BYOA template
(#694): drop Stop/Start/Terminate, deny ownership-tag writes.

Stacks on #1606.
@scttfrdmn
scttfrdmn marked this pull request as ready for review November 12, 2026 18:44
@scttfrdmn
scttfrdmn force-pushed the fix/sec-role-permissions-boundary branch from 0abc5c5 to 91ec9a0 Compare November 12, 2026 18:45
@scttfrdmn
scttfrdmn merged commit b1fd28f into main Nov 12, 2026
9 checks passed
@scttfrdmn
scttfrdmn deleted the fix/sec-role-permissions-boundary branch November 12, 2026 19:00
@scttfrdmn scttfrdmn mentioned this pull request Nov 12, 2026
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.

1 participant