Skip to content

fix(iam): no nested-spawn role in detached sweeps or pipeline stages (#1372) - #1373

Merged
scttfrdmn merged 1 commit into
mainfrom
fix/1372-no-nested-role-in-orchestrators
Oct 28, 2026
Merged

scttfrdmn merged 1 commit into
mainfrom
fix/1372-no-nested-role-in-orchestrators

Conversation

@scttfrdmn

Copy link
Copy Markdown
Contributor

Fixes #1372

Detached sweeps and pipeline stages could launch with a --nested-spawn role (spawn-instance-nested-*, aws.NestedSpawnRolePrefix). The CLI check and both orchestrators' iam:PassRole matched the broader spawn-instance-* family. A nested role may itself call RunInstances and PassRole, and spawn launch --nested-spawn gives 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): orchestratorPassableProfile returns false for the nested prefix. Every detached path goes through it: --instance-profile, --iam-role (with --iam-*/--s3-*), defaults: iam_role, a row's iam_role (refuseUnpassableDetachedProfiles, called by spawn launch detached and spawn 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 launch always records the profile CreateOrGetInstanceProfile(pipelineStageIAMConfig(p)) returns, which has no RoleName, so the profile is always the hashed spawn-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 whose IamInstanceProfile (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): launchStageInstance refuses a stage whose state.InstanceProfile has the nested prefix, before RunInstances.

Both use spawnaws.IsNestedSpawnRole / NestedSpawnRolePrefix, not a literal.

IAM: an explicit, unconditional Deny of iam:PassRole on role/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-*"]
}

PipelineOrchestratorFunction role (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 through iam:PassedToService.

Other principals. A repository-wide search finds only one other principal whose PassRole matches spawn-instance-*: the --nested-spawn role itself (pkg/aws/nested_spawn.go, NestedSpawnPassSpawnRoles). Decision: it gets no Deny.

  • Nested-of-nested is a designed feature. nestedChildProfile gives a --nested-spawn child the parent's own role, so the role must be able to pass a role with the nested prefix.
  • It cannot be narrowed to "only my own role". The role's name is a hash of its policy document, so the document cannot name it.
  • Another nested role is a peer with the same spawn-authored grant shape (it differs only by CLI version), so passing one escalates nothing the holder doesn't already have.
  • Changing the document would also rename the role.

cmd/onboard.go grants 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, in defaults, in a row, plus a row with only the nested prefix. Each is refused, with the nested message. Revert (drop the IsNestedSpawnRole early return in orchestratorPassableProfile): all 5 nested cases fail with err = <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 pass aws.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: drives tryLaunchInstanceSingleRegion and tryLaunchInstance through a real *ec2.Client whose HTTP transport counts Action=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 with spawn-instance-abc12345 must reach the transport exactly once. Revert (drop the refuseNestedSpawnProfile call): all 8 nested cases fail with "1 RunInstances call(s) ..., want 0". TestNestedSpawnProfileIsRefusedByARN covers the ARN form.
  • lambda/pipeline-orchestrator TestNestedSpawnStageProfileIsNeverLaunched: launchStage with a counting fake launcher. A nested record profile gets 0 launches and the refusal; the spawn-instance-* control launches. Revert (false && on the check): both nested cases fail with "1 RunInstances call(s) ..., want 0" and err = <nil>.
  • internal/iamcoverage TestNoOrchestratorMayPassANestedSpawnRole (new): walks every .sh and YAML template in the repository. Any principal whose Allow can pass spawn-instance-nested-* to EC2 must have exactly one unconditional Deny (no Condition, NotAction or NotResource) on exactly arn:aws:iam::<the Allow's account>:role/spawn-instance-nested-*, with the prefix taken from pkg/aws. It then simulates the verdict, with Deny beating Allow: the nested roles are denied, while spored-instance-role and spawn-instance-abc12345 stay 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:
    • Deleting the script's Deny and making the template's Deny conditional fails both principals: "has 0 unconditional Deny ..." and "simulated PassRole of role/spawn-instance-nested-... is allowed".
    • Widening the template Deny to 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 TestSweepCrossAccountRoleMayPassSporedsRole already skips non-Allow statements and passes unchanged.

Deploy steps (none of this reaches AWS until done)

  1. Re-run scripts/setup-sweep-cross-account-role.sh in each member account. It uses put-role-policy, which replaces the inline policy and adds the Deny.
  2. Redeploy the sweep orchestrator Lambda (scripts/deploy-sweep-orchestrator.sh) to get the server-side refusal.
  3. Redeploy the pipeline orchestrator stack (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 of role/spawn-instance-<hash> and role/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.

@codecov

codecov Bot commented Oct 28, 2026

Copy link
Copy Markdown

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
scttfrdmn force-pushed the fix/1372-no-nested-role-in-orchestrators branch from e852ec6 to a5cf357 Compare October 28, 2026 03:39
@scttfrdmn
scttfrdmn merged commit 1074013 into main Oct 28, 2026
9 checks passed
@scttfrdmn
scttfrdmn deleted the fix/1372-no-nested-role-in-orchestrators branch October 28, 2026 04:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

component:spawn type:bug type:security Security-relevant change or dependency

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Detached sweeps and pipeline stages can launch with a nested-spawn role (spawn-instance-nested-*)

1 participant