Repository navigation
fix(iam): no nested-spawn role in detached sweeps or pipeline stages (#1372) - #1373
Merged
Merged
Conversation
This was referenced Oct 28, 2026
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
…1372) The orchestrators' iam:PassRole on role/spawn-instance-* also matched the --nested-spawn roles (spawn-instance-nested-*). The CLI refuses such a profile on every detached path, the sweep and pipeline orchestrators refuse it before RunInstances, and both orchestrator roles carry an explicit Deny of iam:PassRole on role/spawn-instance-nested-*. Fixes #1372
scttfrdmn
force-pushed
the
fix/1372-no-nested-role-in-orchestrators
branch
from
October 28, 2026 03:39
e852ec6 to
a5cf357
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 #1372
Detached sweeps and pipeline stages could launch with a
--nested-spawnrole (spawn-instance-nested-*,aws.NestedSpawnRolePrefix). The CLI check and both orchestrators'iam:PassRolematched the broaderspawn-instance-*family. A nested role may itself call RunInstances and PassRole, andspawn launch --nested-spawngives it only to a single instance with a--ttl. A params writer could otherwise have had the orchestrator hand it out with no TTL requirement. Both halves are new in v0.147.0 and unreleased.Changes
CLI (
cmd/launch_sweep_detached_iam.go):orchestratorPassableProfilereturns false for the nested prefix. Every detached path goes through it:--instance-profile,--iam-role(with--iam-*/--s3-*),defaults: iam_role, a row'siam_role(refuseUnpassableDetachedProfiles, called byspawn launchdetached andspawn schedule), and the per-member rendered config (launch_sweep_detached_bootstrap.go). For a nested profile the refusal says: "nested spawn isn't available for detached sweeps (#1372). Use --nested-spawn on a single launch, which requires --ttl". It does not suggest--no-detach.Pipeline CLI path: it has no equivalent user input.
spawn pipeline launchalways records the profileCreateOrGetInstanceProfile(pipelineStageIAMConfig(p))returns, which has noRoleName, so the profile is always the hashedspawn-instance-<hex>. A pipeline definition cannot name a profile. So the CLI needs no check there. The record is written with the caller's credentials, though, so the orchestrator checks it (below).Sweep orchestrator (
lambda/sweep-orchestrator/spored.go):buildRunInstancesInput, shared by the single- and multi-region launch paths, refuses a request whoseIamInstanceProfile(Name, or the last segment of an ARN) has the nested prefix. It checks after the request is fully composed, so it covers CLI-rendered params, legacy params and #1368's rendered path. RunInstances is never called.Pipeline orchestrator (
lambda/pipeline-orchestrator/main.go):launchStageInstancerefuses a stage whosestate.InstanceProfilehas the nested prefix, before RunInstances.Both use
spawnaws.IsNestedSpawnRole/NestedSpawnRolePrefix, not a literal.IAM: an explicit, unconditional Deny of
iam:PassRoleonrole/spawn-instance-nested-*. The existing Allow is kept.SpawnSweepCrossAccountRole(scripts/setup-sweep-cross-account-role.sh):{ "Sid": "DenyPassNestedSpawnRoles", "Effect": "Deny", "Action": ["iam:PassRole"], "Resource": ["arn:aws:iam::${CURRENT_ACCOUNT_ID}:role/spawn-instance-nested-*"] }PipelineOrchestratorFunctionrole (lambda/pipeline-orchestrator/template.yaml), rendered:{ "Sid": "DenyPassNestedSpawnRoles", "Effect": "Deny", "Action": ["iam:PassRole"], "Resource": ["arn:aws:iam::*:role/spawn-instance-nested-*"] }The template's Allow uses
arn:aws:iam::*:role/..., so the Deny uses*as the account too. A Deny scoped to${AWS::AccountId}would leave the nested roles of other accounts passable. Neither Deny has a condition, so it cannot be sidestepped throughiam:PassedToService.Other principals. A repository-wide search finds only one other principal whose PassRole matches
spawn-instance-*: the--nested-spawnrole itself (pkg/aws/nested_spawn.go,NestedSpawnPassSpawnRoles). Decision: it gets no Deny.nestedChildProfilegives a--nested-spawnchild the parent's own role, so the role must be able to pass a role with the nested prefix.cmd/onboard.gogrants PassRole only on the single spored role, and the reaper roles have no PassRole. The new IAM gate rediscovers this set on every run.Gates (each watched failing against a compiling revert)
cmd TestUnpassableDetachedProfileIsRefusedUpFront(extended): a nested profile in--instance-profile, in--iam-role+--iam-policy, indefaults, in a row, plus a row with only the nested prefix. Each is refused, with the nested message. Revert (drop theIsNestedSpawnRoleearly return inorchestratorPassableProfile): all 5 nested cases fail witherr = <nil>, want refused=true.cmd TestDetachedPassableProfilesMatchTheGrant(updated): it now reads the script's Allow and Deny separately. Whatever the script denies, the CLI must refuse, and the grant must not passaws.NestedSpawnRoleName(). Revert of the CLI fails with "the script denies PassRole on spawn-instance-nested-*, but the CLI lets a detached member use ...". Revert of the script Deny fails with "the cross-account role may pass the nested-spawn role spawn-instance-nested-f3113497".lambda/sweep-orchestrator TestNestedSpawnProfileMemberIsNeverLaunched: drivestryLaunchInstanceSingleRegionandtryLaunchInstancethrough a real*ec2.Clientwhose HTTP transport countsAction=RunInstances(and fails everything). The cases are rendered and legacy params ×NestedSpawnRoleName()and a prefix-only name. Each must make 0 RunInstances calls and return the refusal. A control withspawn-instance-abc12345must reach the transport exactly once. Revert (drop therefuseNestedSpawnProfilecall): all 8 nested cases fail with "1 RunInstances call(s) ..., want 0".TestNestedSpawnProfileIsRefusedByARNcovers the ARN form.lambda/pipeline-orchestrator TestNestedSpawnStageProfileIsNeverLaunched:launchStagewith a counting fake launcher. A nested record profile gets 0 launches and the refusal; thespawn-instance-*control launches. Revert (false &&on the check): both nested cases fail with "1 RunInstances call(s) ..., want 0" anderr = <nil>.internal/iamcoverage TestNoOrchestratorMayPassANestedSpawnRole(new): walks every.shand YAML template in the repository. Any principal whose Allow can passspawn-instance-nested-*to EC2 must have exactly one unconditional Deny (no Condition, NotAction or NotResource) on exactlyarn:aws:iam::<the Allow's account>:role/spawn-instance-nested-*, with the prefix taken frompkg/aws. It then simulates the verdict, with Deny beating Allow: the nested roles are denied, whilespored-instance-roleandspawn-instance-abc12345stay passable. It also asserts that discovery still sees both Detached sweeps and pipeline stages can launch with a nested-spawn role (spawn-instance-nested-*) #1372 principals. Reverts:spawn-instance-*fails: "the Deny is wider than the nested roles".The existing iamcoverage action-coverage gate models Allows only (a Deny grants nothing), so it needs no change and still passes.
scripts TestSweepCrossAccountRoleMayPassSporedsRolealready skips non-Allow statements and passes unchanged.Deploy steps (none of this reaches AWS until done)
scripts/setup-sweep-cross-account-role.shin each member account. It usesput-role-policy, which replaces the inline policy and adds the Deny.scripts/deploy-sweep-orchestrator.sh) to get the server-side refusal.lambda/pipeline-orchestrator,make deploy/sam deploy) to get the role's Deny and the refusal.Per the IAM verification rule, after deploying, simulate the PassRole of
role/spawn-instance-nested-<hash>(expect an explicit deny) and ofrole/spawn-instance-<hash>androle/spored-instance-role(expect allowed) against each role, and diff the stack parameters for zero drift. That was not done here: no AWS calls were made.Checks:
make check,make lint(0 issues, 10 modules),semgrep scan --config=auto --error .clean.