Skip to content

feat(launch): opt-in --nested-spawn role for spawn-on-a-spore (#39) - #1348

Merged
scttfrdmn merged 1 commit into
mainfrom
feat/39-nested-spawn-role
Oct 27, 2026
Merged

scttfrdmn merged 1 commit into
mainfrom
feat/39-nested-spawn-role

Conversation

@scttfrdmn

Copy link
Copy Markdown
Contributor

Fixes #39

Implements the owner decision on #39: an opt-in role, spawn launch --nested-spawn. The default spored-instance-role is not widened.

What it does

  • --nested-spawn creates or reuses spawn-instance-nested-<hash of the grant document> (role + profile, tagged spawn:managed=true) and attaches it. Before that it calls SetupSporedIAMRole (unchanged) so the children's default identity exists, because a nested spore cannot create it.
  • Deleter: the prefix is in the spawn-instance-* family on purpose. pkg/instancerole (Leave no trace: reap per-task spawn-instance-<hash> IAM roles and instance profiles once no instance uses them #1300: the reaper's REAPER_INSTANCE_ROLES sweep and spawn cleanup --instance-roles) deletes it under the same rules as any per-task role. No reaper or template change. A test asserts instancerole.IsCandidate(NestedSpawnRoleName()).
  • Grant document (pkg/aws/nested_spawn.go), derived from the SDK calls that launch/list/status/extend/connect/terminate make:
    • reads (ec2:Describe* as used, EFS describes, ssm:DescribeInstanceInformation/GetCommandInvocation) on *, because AWS has no resource-level permissions for them;
    • ssm:GetParameter on arn:aws:ssm:*::parameter/aws/service/* only;
    • ec2:RunInstances on instance/volume only with aws:RequestTag/spawn:managed=true;
    • ec2:RunInstances on the resource types it references (image, snapshot, subnet, capacity-reservation, network-interface, security-group, key-pair, placement-group, spot-instances-request). AWS authorizes RunInstances against each of these. They are pre-existing, or EC2 creates them untagged (the primary ENI, a one-time Spot request), so a tag condition would refuse every launch. The grant is scoped by resource type, never *;
    • ImportKeyPair/CreateSecurityGroup/CreatePlacementGroup with aws:RequestTag/spawn:managed=true (plus CreateSecurityGroup on vpc/*);
    • ec2:CreateTags only for tag-on-create (ec2:CreateAction ∈ those creates and aws:RequestTag/spawn:managed=true);
    • Start/Stop/Terminate/CancelSpot/GetPasswordData/AuthorizeSG/DeletePlacementGroup with ec2:ResourceTag/spawn:managed=true;
    • ssm:SendCommand/ssm:StartSession on instances with ssm:resourceTag/spawn:managed=true (the SSM condition key for an SSM action), plus the AWS-RunShellScript/AWS-RunPowerShellScript/SSM-SessionManagerRunShell documents;
    • iam:PassRole only on role/spored-instance-role and role/spawn-instance-* (account-bound), with iam:PassedToService=ec2.amazonaws.com.
  • The nested role's baseline differs from the default in one condition. The reaper-control-tag Deny (GHSA-8q3p, GHSA-c93q) blocks ec2:CreateTags carrying spawn:managed/spawn:launch-time/…. IAM evaluates a RunInstances request's tags as CreateTags, so the unchanged Deny would refuse every child launch. The nested variant adds Null: {ec2:CreateAction: true}, so the Deny still covers every existing resource and only tag-on-create is exempt. The default baseline is untouched (createOrGetInstanceProfile now takes the baseline doc as a parameter, and CreateOrGetInstanceProfile passes the same doc as before).
  • On a nested spore (the caller's STS ARN is assumed-role/spawn-instance-nested-*), the CLI writes no IAM. A child gets spored-instance-profile, or the parent's own nested profile with --nested-spawn. --instance-profile works as before (PassRole limits it to spawn roles). --iam-*/--s3-*, a custom DNS updater and --no-timeout are refused with a message explaining why. A spore that could CreateRole/PutRolePolicy could grant itself anything, so the role has no IAM write.
  • TTL / cost: --nested-spawn requires --ttl (checked on the resolved config, so a config-default TTL counts). It is refused with --no-timeout, --instance-profile, IAM flags, sweeps and batch queues. Children get their own TTL (or the existing 1h idle default, applyIdleTimeoutDefault, verified) and their own spored, as any launch does. They are tagged spawn:managed=true by condition, so they are in the reaper's scan from the start.
  • Not granted, each listed with its reason in nestedSpawnNotGranted: IAM writes, FSx create/delete, staging/results bucket management, sweep DynamoDB/Lambda/S3/AssumeRole, multi-card EFA Elastic IPs (AssociateAddress can't be tag-scoped: the ENI is untagged), account:GetAccountInformation (best effort, falls back).
  • Launch paths: only spawn launch (single and job-array, which share ensureIAMProfile). Batch queue and sweeps are refused with the flag. spawn task run is not wired: it always mints a scoped S3 role, which a nested spore can't create.
  • --dry-run predicts the nested profile name. Windows rule: honoured (IAM only). Sweep classification: N/A (refused).

Gates (each watched failing against a revert that compiles)

Gate Revert Result
TestNestedSpawnPolicyCoversTheChildLaunchCalls: discovers SDK *Input literals reachable from cmd launch_single/list/status/extend/connect/terminate (import-aware AST walk through the module). Every action must be granted (nested doc or baseline) or listed not-granted with a reason. Stale exclusions fail, and so does a discovery that finds nothing. drop ec2:ImportKeyPair FAIL
TestNestedSpawnPolicyScopesEveryMutatingGrant: no mutating action on * without a condition, no wildcard actions, no IAM action but PassRole remove the Condition from ManageManaged FAIL
TestNestedSpawnChildrenMustBeTaggedManaged drop RequestTag from RunInstances instance/volume FAIL
TestNestedSpawnPassRoleIsScopedToSpawnRolesAndEC2 role/*; PassedToService: * FAIL / FAIL
TestNestedSpawnBaselineDiffersOnlyAtTagOnCreate drop the Null condition FAIL
TestNestedSpawnLeavesTheDefaultRoleUnchanged (substrate): snapshot of spored-instance-role's inline docs and managed attachments before and after SetupNestedSpawnProfile; stored nested grant and baseline equal the bound docs; role tagged managed; profile holds role add a policy write to spored-instance-role; nested role given the default baseline FAIL / FAIL
TestNestedSpawnLaunchAttachesTheNestedRole (ensureIAMProfile against the fake IAM) hook removed; flag ignored FAIL / FAIL
TestDefaultLaunchIsUnchangedByNestedSpawn nested setup on every launch FAIL
TestLaunchFromANestedSporeWritesNoIAM: zero PutRolePolicy/roles/profiles/setup calls detection disabled; --nested-spawn child ignored FAIL / FAIL
TestNestedSpawnFlagValidation / TestNestedSpawnRequiresATTL --no-timeout case removed; TTL check disabled FAIL / FAIL

IAM statements to simulate (allow + deny) before release

Policy simulation and a real PutRolePolicy are not done here (no AWS). Statements to check on a throwaway role:

  • Allow: RunInstances with instance+volume TagSpecifications carrying spawn:managed=true and spawn:launch-time (this exercises the Null-CreateAction Deny exemption); ImportKeyPair tagged; CreateSecurityGroup tagged in a VPC; CreateTags (spawn:ttl-deadline) on an existing managed instance; TerminateInstances on a managed instance; SendCommand to a managed instance with AWS-RunShellScript; PassRole spored-instance-role to ec2.
  • Deny: RunInstances without spawn:managed; CreateTags spawn:launch-time on an EXISTING managed instance (the Deny must still fire); TerminateInstances on an unmanaged instance; PassRole to any role outside spored-instance-role/spawn-instance-*; PassRole to a non-EC2 service; iam:CreateRole / PutRolePolicy; SendCommand to an unmanaged instance.
  • Real PutRolePolicy of the bound grant document (the Every spawn launch fails on v0.129.0/v0.130.0: spored role policy rejected (MalformedPolicyDocument) #1069 lesson). It carries no ${aws:PrincipalAccount}; the account is bound via bindPolicyAccount.

Checks

  • make check: stages 1–6 pass. check-build-tags fails on /private/tmp paths, the known local-only failure; this PR doesn't touch build tags or test/e2e.
  • make lint: 0 issues in all 10 modules. semgrep scan --config=auto --error .: clean. make check-docs: clean (docs-gen/launch.md regenerated). make api-snapshot: additions only (NestedSpawnRolePrefix, NestedSpawnRoleName, IsNestedSpawnRole, NestedSpawnRoleFromCallerARN, (*Client).SetupNestedSpawnProfile).
  • No reaper/template files touched.

@codecov

codecov Bot commented Oct 26, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 95.38462% with 12 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
cmd/launch_single.go 63.63% 4 Missing ⚠️
pkg/aws/nested_spawn.go 98.01% 4 Missing ⚠️
cmd/launch_nested.go 92.68% 3 Missing ⚠️
cmd/launch_dryrun.go 50.00% 1 Missing ⚠️

📢 Thoughts on this report? Let us know!

spawn launch --nested-spawn attaches a dedicated role,
spawn-instance-nested-<hash>, granting what spawn launch/list/status/
extend/connect/terminate call (discovered from source by a test), scoped
by spawn:managed tag conditions and resource type, with iam:PassRole
limited to spored-instance-role and spawn-instance-* passed to EC2. No IAM
write: a CLI running as the role picks an existing profile instead of
calling the role-setup paths. spored-instance-role is unchanged.

The role is in the spawn-instance-* family, so pkg/instancerole (#1300)
deletes it once unused.
@scttfrdmn
scttfrdmn force-pushed the feat/39-nested-spawn-role branch from 54ffc1d to 827ddba Compare October 27, 2026 01:49
@scttfrdmn
scttfrdmn merged commit ae3de8c into main Oct 27, 2026
9 checks passed
@scttfrdmn
scttfrdmn deleted the feat/39-nested-spawn-role branch October 27, 2026 02:05
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.

spored-instance-role needs ec2:ImportKeyPair + full set of EC2 permissions for nested spawn usage

1 participant