Skip to content

fix(launch): a nested-spawn role named directly requires --ttl (#1375) - #1381

Merged
scttfrdmn merged 1 commit into
mainfrom
fix/1375-nested-profile-requires-ttl
Oct 28, 2026
Merged

scttfrdmn merged 1 commit into
mainfrom
fix/1375-nested-profile-requires-ttl

Conversation

@scttfrdmn

Copy link
Copy Markdown
Contributor

A spawn-instance-nested-* role may call RunInstances and iam:PassRole on spawn-instance-*. --nested-spawn gives it only to an instance with a --ttl (#39), but naming the role directly skipped that rule. With this change, a profile or role that matches aws.IsNestedSpawnRole gets the same treatment as --nested-spawn on every path that accepts one.

Paths and treatment

Path Treatment Why
spawn launch --instance-profile <nested> (single launch, plus --count job arrays and --mpi, which share its config) Requires --ttl. Refused in runLaunch before any AWS call, ahead of the audit GetCallerIdentity. Same reason text as --nested-spawn requires --ttl. Can't be combined with --no-timeout either, as with --nested-spawn. In wizard mode the TTL may come from the wizard, so requireNestedSpawnTTL checks the resolved config instead. Same capability, same rule.
spawn launch --iam-role <nested> (single, sweep, batch queue) Refused outright, before any AWS call. CreateOrGetInstanceProfile also refuses a nested RoleName. --iam-role goes through CreateOrGetInstanceProfile. For an existing nested role, that overwrites spored-baseline-policy with the default baseline, which breaks child launches because the nested variant exempts tag-on-create. With --iam-policy, it also overwrites the nested grant in spawn-scoped-policy. For a new name, it creates a role under the nested prefix with caller-chosen grants. The nested role's grants are fixed so they can be audited.
spawn launch --batch-queue/--queue-template --instance-profile <nested> Refused outright. --nested-spawn is already refused with a batch queue: a queue runner isn't a head node.
Foreground sweep (--no-detach, or --detach with no --max-concurrent), via a row's iam_role:, defaults: iam_role:, or --instance-profile A row is refused if its effective profile is nested and its effective TTL is empty. Checked under the same condition as the detached/foreground dispatch, so each sweep gets the refusal for the path it actually takes, and before the sweep creates anything. TTL resolution, per row (the launch's own precedence): the profile is the row's iam_role:, else --instance-profile (folded into defaults by applyCLIIAMToSweep), else defaults: iam_role:. The TTL is the row's ttl:, else defaults: ttl:, which already holds --ttl (applyCLISpendControlsToSweep). That's sweepRowBound, the resolution the --no-detach guard uses. An idle timeout doesn't count.
Detached sweep / spawn schedule Unchanged: refused outright whatever the TTL (#1372 / PR #1373). The orchestrator can't pass the role.
spawn resume (foreground) Same per-row rule, using the file alone. Resume rebuilds rows from the param file with no --instance-profile/--ttl, so the row needs a ttl: in the file.
spawn burst --instance-profile Same TTL rule (validateBurstParams, checked first). Burst already requires a positive --ttl, so in practice this never fires. It's there so the rule lives in one function and the discovery gate covers burst.
spawn task run, pool, app launch, image, pipeline launch, service, MPI/task cohorts Covered by the aws.Client.Launch backstop. None of these takes a user-named profile: each uses a role spawn creates (spawn-instance-<hash>, the pool worker role, or spored-instance-profile), and none of those can match the nested prefix.
aws.Client.Launch Refuses a nested IamInstanceProfile with no TTL before any AWS call. Every launch goes through it. This is the backstop for SDK callers (taskcohort, mpicohort adapters) and any future path.
launcher.Provision (lagotto, MCP) Refuses the same, right after ValidateDurations, before the AMI lookup. Checked against the code: TTL is not mandatory in Provision (ValidateDurations only parses a TTL that is set). So without this check an SDK caller could provision a nested profile with no TTL, and Client.Launch would only catch it after the AMI and IAM work.

New in pkg/aws: CheckNestedSpawnTTL, LaunchConfig.ValidateNestedSpawnTTL, NestedSpawnTTLError (the --nested-spawn refusal, now shared), NestedSpawnRoleReservedError, ErrNestedSpawnNeedsTTL, ErrNestedSpawnRoleReserved. api/public-surface.txt is regenerated. Help text: --instance-profile now says a nested-spawn role needs --ttl. docs-gen/launch.md is regenerated.

No new IAM permission for any principal. No AWS calls were made.

Gates (each watched failing against a revert that compiles)

The revert in each case was false && err != nil on the check, which compiles and vets clean.

  • TestNestedInstanceProfileWithoutTTLRefusedBeforeAnyAWSCall (runLaunch through a counting endpoint). With the runLaunch call reverted: "the refused launch made 1 AWS call(s) first".
  • TestNestedInstanceProfileWithTTLProceeds. With the revert making CheckNestedSpawnTTL ignore the TTL: "launch --instance-profile ... --ttl 8h was refused".
  • TestForegroundSweepRowWithNestedProfileAndNoTTLRefused (--no-detach, row 1 nested, idle timeout only, 0 AWS calls). With the sweep call reverted, it fails at the AMI lookup: detect AMI ... GetParameter 400.
  • TestProvisionRefusesNestedProfileWithoutTTLBeforeAnyAWSCall. With the revert, it fails at the AMI lookup (SSM GetParameter 403).
  • TestEveryProfileFlagRoutesThroughTheNestedSpawnCheck (discovery). It walks rootCmd for every command with --instance-profile or --iam-role, runs its RunE with the nested role and an empty --ttl through a counting endpoint, and requires a nested refusal and 0 AWS calls. It fails if it discovers nothing, or if it misses launch or burst. Reverts: the runLaunch check made the launch subtests fail (1 AWS call, --name is required). The burst check made the burst subtest fail (--ttl is required: burst instances must have a TTL, the wrong refusal). The --iam-role refusal made the launch --iam-role subtest fail.

Also gated, each failing against its revert: TestLaunchRefusesNestedProfileWithoutTTLBeforeAnyAWSCall (the Client.Launch backstop; the revert reached STS), TestCreateOrGetInstanceProfileRefusesANestedRoleName (the revert reached IAM GetRole), TestResumeRefusesANestedRowWithoutTTL, TestNestedSpawnRoleFlagValidation. Units: TestNestedSweepRowResolution (precedence), TestCheckNestedSpawnTTL (shared wording), and TestDetachedSweepWithNestedRowGetsTheDetachedRefusal, which checks that an auto-detached sweep still gets #1372's refusal rather than an invitation to add a --ttl it would refuse anyway.

Fixes #1375

@codecov

codecov Bot commented Oct 28, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 98.07692% with 1 line in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
cmd/launch_nested_profile.go 95.65% 1 Missing ⚠️

📢 Thoughts on this report? Let us know!

--instance-profile spawn-instance-nested-* and a foreground sweep row naming
one skipped --nested-spawn's --ttl rule. Every path that accepts a profile now
applies it (or refuses the role outright: --iam-role, batch queue), and
aws.Client.Launch and launcher.Provision enforce it for SDK callers.

Fixes #1375
@scttfrdmn
scttfrdmn force-pushed the fix/1375-nested-profile-requires-ttl branch from f691b34 to d53e874 Compare October 28, 2026 18:18
@scttfrdmn
scttfrdmn merged commit cecd005 into main Oct 28, 2026
9 checks passed
@scttfrdmn
scttfrdmn deleted the fix/1375-nested-profile-requires-ttl branch October 28, 2026 18:42
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.

A nested-spawn role named via --instance-profile (or a --no-detach sweep row) skips --nested-spawn's --ttl requirement

1 participant