Skip to content

Scope spored instance permissions to the calling instance - #1606

Merged
scttfrdmn merged 2 commits into
mainfrom
fix/sec-instance-roles
Nov 12, 2026
Merged

scttfrdmn merged 2 commits into
mainfrom
fix/sec-instance-roles

Conversation

@scttfrdmn

Copy link
Copy Markdown
Contributor

Summary

Narrows the instance-mutating grants on the spawn-created instance roles.

  • spored roles (spored-instance-role and every spawn-instance-* role's spored baseline): ec2:CreateTags, ec2:DeleteTags and ec2:StopInstances are allowed only when aws:ARN equals ${ec2:SourceInstanceARN}, the form TerminateOnlySelf has used since Spot replacement self-retirement (#1008) STOPS the replacement instead of ending it: untagged, request cancelled, EBS bills forever #1080. Explicit Denies (DenyTagOthers, DenyStopTerminateOthers) retire the earlier spawn:managed-scoped grants, which CLIs up to v0.161.0 still rewrite on each launch. spawn:config, spawn:iam-user and spawn:nested-parent join the keys no instance may write. ec2:CancelSpotInstanceRequests stays scoped to spawn:managed=true, because a Spot request's ARN is not the instance's. Spored grant schema 2.
  • --nested-spawn role: a child launched from a nested head is tagged spawn:nested-parent = the head's aws:userid, and the nested RunInstances requires that tag. SSM SendCommand/StartSession, start, stop, terminate, GetPasswordData, Spot cancel and retagging of existing instances are conditioned on it. iam:PassRole covers only spored-instance-role and the nested role itself, not the spawn-instance-* family. The role name is a hash of the document, so heads launched by this CLI get a new role. The old one is reaped as before (pkg/instancerole) once unused. Security- and placement-group grants keep their spawn:managed=true scope: those groups are found or created by name and shared with workstation launches.
  • Task roles (spawn task run): the results-bucket write is scoped to the results prefix (tasks/ by default, or the spec's results_prefix), not the whole bucket. A per-task-id grant would give each task its own role, because roles are named by policy hash, and that would exceed IAM's role quota on fan-outs. See the comment on taskiam.ResultsWriteTarget.

The calls spored and the TTL reaper make were checked. spored stops, terminates and tags only identity.InstanceID. The reaper, the dashboard and the orchestrators use their own roles.

Account-wide grants that remain (no resource-level permissions in IAM)

ec2:DescribeTags, ec2:DescribeInstances (spored's own state and block devices, plus job-array peer discovery), ec2:DescribeVolumes (EBS cost footprint), ec2:DescribeSpotPriceHistory (Spot cost), ec2:DescribeAddresses (own launch EIP), and fsx:DescribeFileSystems/fsx:DescribeDataRepositoryAssociations (async FSx mount).

Deploy checklist impact

Tests

  • New gates, each watched failing against a revert that compiles: TestSporedRolesMutateOnlyTheirOwnInstance (an evaluator over both spored documents, alone and together with the legacy grants), TestSporedRolesCarryTheRetiringDenies, TestNestedSpawnRoleReachesOnlyItsOwnChildren, TestNestedSpawnPolicyNamesItsOwnRole, TestNestedHeadTagsItsChildren, TestTaskResultsWriteIsScopedToTheResultsPrefix, and the extended TestStagedGrantKeepsTheRoleShared.
  • go test -short -exec hermetic-exec ./... passes. make check is clean except the three checks that fail locally only because the worktree path contains a space.

The spored roles may stop, terminate and tag only their own instance
(aws:ARN == ${ec2:SourceInstanceARN}), with explicit Denies retiring the
account-wide forms that older CLIs still write. spawn:config, spawn:iam-user
and spawn:nested-parent join the keys no instance may write. Spored grant
schema 2.

A --nested-spawn head's grants on existing instances (SSM, start/stop/
terminate, retag) now reach only the children it launched, which carry
spawn:nested-parent = its own aws:userid from RunInstances, and it may pass
only spored-instance-role and its own role.

A task role's results-bucket write is scoped to the results prefix.
@codecov

codecov Bot commented Nov 12, 2026 •

Copy link
Copy Markdown

Codecov Report

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

Files with missing lines Patch % Lines
pkg/aws/launch_tags.go 63.63% 8 Missing ⚠️
pkg/aws/nested_spawn.go 91.48% 4 Missing ⚠️
pkg/aws/iam_instance_scope.go 98.41% 1 Missing ⚠️

📢 Thoughts on this report? Let us know!

@scttfrdmn

Copy link
Copy Markdown
Contributor Author

Live check, spore-host-dev us-east-1, 2026-11-12. The CLI was built from #1607's head, which includes this PR.

  • PutRolePolicy: every new or changed document (spored v2/v3, baseline v3, nested baseline v3, nested grants, app inline, task sample) was accepted inline on a throwaway role. The four spored documents were also accepted as managed policies (CreatePolicy). Everything was deleted afterwards and nothing remains.

  • Self-scope, from the instance's own credentials (EC2 DryRun answers):

    call on itself on another spawn instance
    CreateTags / DeleteTags DryRunOperation UnauthorizedOperation
    StopInstances DryRunOperation UnauthorizedOperation
    TerminateInstances DryRunOperation UnauthorizedOperation
    CreateTags spawn:config UnauthorizedOperation —

    This confirms that aws:ARN == ${ec2:SourceInstanceARN} is evaluated for Stop, CreateTags and DeleteTags as well as Terminate.

  • Older CLI in the same account: after a launch with v0.161.0, which re-adds the legacy inline spored-policy, the cross-instance calls from both the new-launched and the legacy-launched instance are still UnauthorizedOperation. The explicit Deny wins.

  • Lifecycle:

    • Heartbeat and compute tag writes work.
    • Idle-stop: the instance stopped itself via its own role (CloudTrail).
    • TTL: two instances terminated themselves via their own roles at their deadlines (CloudTrail).
    • A stopped instance past its TTL was reaped by the backstop (REAPED … ttl-deadline, 8 minutes after the deadline).
  • Leak check: no instances in us-east-1 or us-west-2, no available volumes or ENIs, no EIPs, non-default SGs, open Spot requests or leftover DNS records.

  • Account state: the dev account's spored-instance-role now carries spored-policy-v3 (managed) plus the legacy inline policy from the v0.161.0 launch. A v0.163.2 CLI will see schema v3 and defer.

Not yet run live: nested spawn (child scoping), the task results prefix, and Spot persistent cancel-then-terminate.

The nested baseline exempted its tag Denies from tag-on-create with
Null ec2:CreateAction, which does not hold for a direct CreateTags. Name the
creates instead (StringNotLike RunInstances/ImportKeyPair/Create*Group), so
spawn:nested-parent and the other instance-unwritable keys can be set only
when a resource is created, never on an existing one, the head included.
@scttfrdmn

Copy link
Copy Markdown
Contributor Author

Second live round (spore-host-dev, 2026-11-12). The CLI was built from #1609, which stacks on this PR.

  • Nested spawn:
    • The child gets `spawn:nested-parent=`.
    • From the head: SSM and terminate on its own child are allowed.
    • SSM, terminate, stop and CreateTags on a non-child are denied.
    • `iam:CreateRole` is denied, and passing another `spawn-instance-*` profile to a child is refused (UnauthorizedOperation).
    • `spawn terminate child` works.
    • Gap, sent back for a fix: the head could still write `spawn:nested-parent` on its own child and on itself (DryRunOperation).
  • Task role: `PutObject` to `staging/pool-specs/` returned AccessDenied and the object does not exist. The task wrote its completion under `tasks/` and terminated itself through its own role.
  • Spot (one-time): self-terminated at its TTL through its own `spored-instance-role` session; the request is `closed / instance-terminated-by-user`.
  • Idle-stop: the instance stopped itself through its own role.
  • Teardown: all instances terminated; scratch bucket deleted. The leak check is clean: no instances, open Spot requests, volumes, ENIs, EIPs, extra SGs or DNS records. The `spawn-instance-*` roles remain for `cleanup --instance-roles`'s 24h grace.

scttfrdmn added a commit that referenced this pull request Nov 12, 2026
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

Copy link
Copy Markdown
Contributor Author

Re-verified at aaf18a20 (dev, 2026-11-12, with #1609 rebased on top). From a fixed nested head, writing or deleting ownership tags (spawn:nested-parent, spawn:managed) on its own child or on itself is now UnauthorizedOperation. Ownership tags are still set at launch, ordinary tags on its own child still work, and reaper-control tags on a non-child are denied. A head launched by the released CLI did not get these protections; that is tracked privately. Teardown and leak check are clean.

@scttfrdmn
scttfrdmn marked this pull request as ready for review November 12, 2026 18:18
@scttfrdmn
scttfrdmn merged commit cbd6cc5 into main Nov 12, 2026
9 checks passed
scttfrdmn added a commit that referenced this pull request Nov 12, 2026
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 added a commit that referenced this pull request Nov 12, 2026
…1609)

* Cap every spawn-created IAM role with a permissions boundary

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.

* e2e: record Tier 0 coverage decision for spawn setup-account
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