Skip to content

Sweep role: tag only at create, terminate only spawn:managed (#1586) - #1612

Merged
scttfrdmn merged 1 commit into
mainfrom
fix/1586-sweep-role-tags
Nov 13, 2026
Merged

scttfrdmn merged 1 commit into
mainfrom
fix/1586-sweep-role-tags

Conversation

@scttfrdmn

Copy link
Copy Markdown
Contributor

Fixes #1586

What

SpawnSweepCrossAccountRole (schema 1) allowed ec2:CreateTags and ec2:TerminateInstances on * with no condition. The role could therefore write spawn:managed=true and spawn:egress-proxy=vpc-* onto any instance, and those two tags are the whole gate on its ssm:SendCommand (AWS-RunShellScript) grant.

Schema 2 (SweepCrossAccountEC2Policy-v2) makes these changes:

  • TagOnlyAtCreate: ec2:CreateTags is allowed only with StringEquals ec2:CreateAction ∈ {RunInstances, CreateSecurityGroup}. These are the only creates the orchestrator tags at: members and egress proxies at RunInstances, and the proxy's groups at CreateSecurityGroup. The orchestrator never calls CreateTags directly.
  • DenyTagExistingResources: Deny ec2:CreateTags/DeleteTags with StringNotLike ec2:CreateAction over the same list. This is the form spawn#1606 proved live; Null was not enough there. It retires the unconditioned grant in any older copy (v1, or the script's unversioned policy).
  • TerminateManagedInstances plus DenyTerminateUnmanaged: terminate is allowed only where ec2:ResourceTag/spawn:managed=true. Every member (tags.go) and every egress proxy carries that tag from RunInstances.
  • CancelSpotInstanceRequests stays unconditioned because the members' requests are untagged, and cancelling a request terminates nothing. PassRole is unchanged.

Gates

  • internal/iamcoverage TestSweepRoleTagsOnlyAtTheCreatesTheOrchestratorMakes discovers every create the orchestrator tags at and requires the CreateAction list to equal that set. I watched it fail against a compiling revert that dropped CreateSecurityGroup.
  • pkg/aws TestSweepPolicyCannotRetagOrTerminateForeignInstances checks that no CreateTags Allow lacks a CreateAction, that no Terminate Allow lacks spawn:managed, that both Denies exist, and that the tag Deny does not use Null.
  • Golden file, schema pin and hash were updated. sporedPolicySchema is unchanged because no spored document changed.

Live checks needed before merge (owner)

No AWS calls were made writing this. Run these in 435415984226 (spore-host-dev), with an explicit --region on every call:

  1. PutRolePolicy proof: go test ./pkg/aws -run TestSweepPolicyGolden -v (or render SweepCrossAccountPolicyDocument("435415984226")), then on a throwaway role run aws iam put-role-policy --role-name <tmp> --policy-name SweepCrossAccountEC2Policy-v2 --policy-document file://doc.json. It must succeed. Delete the role afterwards.
  2. simulate-custom-policy, with the v1 document passed alongside v2 so the Denies are tested against the old Allows:
    • ALLOW ec2:CreateTags on arn:aws:ec2:us-east-1:435415984226:instance/i-x with ec2:CreateAction=RunInstances
    • ALLOW ec2:CreateTags on …:security-group/sg-x with ec2:CreateAction=CreateSecurityGroup
    • DENY ec2:CreateTags on …:instance/i-x with no ec2:CreateAction
    • DENY ec2:CreateTags with ec2:CreateAction=CreateTags
    • DENY ec2:DeleteTags on …:instance/i-x
    • ALLOW ec2:TerminateInstances with ec2:ResourceTag/spawn:managed=true
    • DENY ec2:TerminateInstances with ec2:ResourceTag/spawn:managed absent, and with it set to false
    • ALLOW (unchanged) ssm:SendCommand on …:instance/i-x with ssm:resourceTag/spawn:managed=true, ssm:resourceTag/spawn:egress-proxy=vpc-1
  3. Real calls: build this branch, then run spawn launch --param-file <2 rows> --detach --ttl 15m in us-east-1.
    • The role should carry only SweepCrossAccountEC2Policy-v2.
    • Both members should launch with their spawn:sweep-* tags.
    • spawn sweep cancel <id> should terminate both.
    • Assume SpawnSweepCrossAccountRole (from the orchestrator role), then run aws ec2 create-tags --dry-run --resources <a non-spawn instance> --tags Key=spawn:managed,Value=true. Expect UnauthorizedOperation. Then run terminate-instances --dry-run on the same instance. Expect UnauthorizedOperation.
    • Optional: repeat the sweep with --no-public-ip --bootstrap-egress proxy to exercise CreateSecurityGroup tag-on-create.
  4. Leak-check afterwards: no instances tagged spawn:sweep-id=<id>, and no proxy left in creating.

@codecov

codecov Bot commented Nov 13, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@scttfrdmn

Copy link
Copy Markdown
Contributor Author

Live check (spore-host-dev, 2026-11-13). The build integrated #1612, #1613, #1614 and #1616 on main.

Not run live: Windows (#1617), the egress proxy (#1618), the release manifest (#1619), retiring a reused DCV/MPI group, and interactive spawn connect.

SpawnSweepCrossAccountRole granted ec2:CreateTags and TerminateInstances
on any resource. Writing spawn:managed and spawn:egress-proxy onto an
instance that was not spawn's passed the tag gate on its egress-proxy
ssm:SendCommand, so the orchestrator's principal could get a root shell
on any instance in a compute account.

CreateTags is now allowed only with ec2:CreateAction RunInstances or
CreateSecurityGroup (the only creates the orchestrator tags at, held to
the code by an iamcoverage discovery gate), and TerminateInstances only
on spawn:managed=true. Explicit Denies (StringNotLike ec2:CreateAction,
the form proven live on the nested role; StringNotEquals spawn:managed)
retire the unconditioned grants of older copies. Sweep role schema 2.
@scttfrdmn
scttfrdmn force-pushed the fix/1586-sweep-role-tags branch from 83fa346 to 80fbde6 Compare November 13, 2026 21:59
@scttfrdmn
scttfrdmn marked this pull request as ready for review November 13, 2026 21:59
@scttfrdmn
scttfrdmn merged commit 9efb258 into main Nov 13, 2026
9 checks passed
@scttfrdmn
scttfrdmn deleted the fix/1586-sweep-role-tags branch November 13, 2026 22:23
@scttfrdmn scttfrdmn mentioned this pull request Nov 14, 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

1 participant