Repository navigation
feat(launch): opt-in --nested-spawn role for spawn-on-a-spore (#39) - #1348
Merged
Merged
Conversation
Codecov Report❌ Patch coverage is
📢 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
force-pushed
the
feat/39-nested-spawn-role
branch
from
October 27, 2026 01:49
54ffc1d to
827ddba
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #39
Implements the owner decision on #39: an opt-in role,
spawn launch --nested-spawn. The defaultspored-instance-roleis not widened.What it does
--nested-spawncreates or reusesspawn-instance-nested-<hash of the grant document>(role + profile, taggedspawn:managed=true) and attaches it. Before that it callsSetupSporedIAMRole(unchanged) so the children's default identity exists, because a nested spore cannot create it.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'sREAPER_INSTANCE_ROLESsweep andspawn cleanup --instance-roles) deletes it under the same rules as any per-task role. No reaper or template change. A test assertsinstancerole.IsCandidate(NestedSpawnRoleName()).pkg/aws/nested_spawn.go), derived from the SDK calls that launch/list/status/extend/connect/terminate make:ec2:Describe*as used, EFS describes,ssm:DescribeInstanceInformation/GetCommandInvocation) on*, because AWS has no resource-level permissions for them;ssm:GetParameteronarn:aws:ssm:*::parameter/aws/service/*only;ec2:RunInstanceson instance/volume only withaws:RequestTag/spawn:managed=true;ec2:RunInstanceson 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/CreatePlacementGroupwithaws:RequestTag/spawn:managed=true(plus CreateSecurityGroup onvpc/*);ec2:CreateTagsonly for tag-on-create (ec2:CreateAction∈ those creates andaws:RequestTag/spawn:managed=true);ec2:ResourceTag/spawn:managed=true;ssm:SendCommand/ssm:StartSessionon instances withssm:resourceTag/spawn:managed=true(the SSM condition key for an SSM action), plus the AWS-RunShellScript/AWS-RunPowerShellScript/SSM-SessionManagerRunShell documents;iam:PassRoleonly onrole/spored-instance-roleandrole/spawn-instance-*(account-bound), withiam:PassedToService=ec2.amazonaws.com.ec2:CreateTagscarryingspawn: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 addsNull: {ec2:CreateAction: true}, so the Deny still covers every existing resource and only tag-on-create is exempt. The default baseline is untouched (createOrGetInstanceProfilenow takes the baseline doc as a parameter, andCreateOrGetInstanceProfilepasses the same doc as before).assumed-role/spawn-instance-nested-*), the CLI writes no IAM. A child getsspored-instance-profile, or the parent's own nested profile with--nested-spawn.--instance-profileworks as before (PassRole limits it to spawn roles).--iam-*/--s3-*, a custom DNS updater and--no-timeoutare refused with a message explaining why. A spore that could CreateRole/PutRolePolicy could grant itself anything, so the role has no IAM write.--nested-spawnrequires--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 taggedspawn:managed=trueby condition, so they are in the reaper's scan from the start.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).spawn launch(single and job-array, which shareensureIAMProfile). Batch queue and sweeps are refused with the flag.spawn task runis not wired: it always mints a scoped S3 role, which a nested spore can't create.--dry-runpredicts the nested profile name. Windows rule: honoured (IAM only). Sweep classification: N/A (refused).Gates (each watched failing against a revert that compiles)
TestNestedSpawnPolicyCoversTheChildLaunchCalls: discovers SDK*Inputliterals 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.ec2:ImportKeyPairTestNestedSpawnPolicyScopesEveryMutatingGrant: no mutating action on*without a condition, no wildcard actions, no IAM action but PassRoleTestNestedSpawnChildrenMustBeTaggedManagedTestNestedSpawnPassRoleIsScopedToSpawnRolesAndEC2role/*;PassedToService: *TestNestedSpawnBaselineDiffersOnlyAtTagOnCreateTestNestedSpawnLeavesTheDefaultRoleUnchanged(substrate): snapshot of spored-instance-role's inline docs and managed attachments before and afterSetupNestedSpawnProfile; stored nested grant and baseline equal the bound docs; role tagged managed; profile holds roleTestNestedSpawnLaunchAttachesTheNestedRole(ensureIAMProfile against the fake IAM)TestDefaultLaunchIsUnchangedByNestedSpawnTestLaunchFromANestedSporeWritesNoIAM: zero PutRolePolicy/roles/profiles/setup calls--nested-spawnchild ignoredTestNestedSpawnFlagValidation/TestNestedSpawnRequiresATTL--no-timeoutcase removed; TTL check disabledIAM statements to simulate (allow + deny) before release
Policy simulation and a real
PutRolePolicyare not done here (no AWS). Statements to check on a throwaway role:spawn:managed=trueandspawn: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.spawn:managed; CreateTagsspawn:launch-timeon an EXISTING managed instance (the Deny must still fire); TerminateInstances on an unmanaged instance; PassRole to any role outsidespored-instance-role/spawn-instance-*; PassRole to a non-EC2 service; iam:CreateRole / PutRolePolicy; SendCommand to an unmanaged instance.PutRolePolicyof 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 viabindPolicyAccount.Checks
make check: stages 1–6 pass.check-build-tagsfails on/private/tmppaths, 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).