Skip to content

fix(doctor): probe the lease write a mark makes; IAM gates for who runs Mark (#1672) - #1676

Draft
scttfrdmn wants to merge 5 commits into
mainfrom
fix/1672-lease-grants
Draft

scttfrdmn wants to merge 5 commits into
mainfrom
fix/1672-lease-grants

Conversation

@scttfrdmn

@scttfrdmn scttfrdmn commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

Refs #1672 (does not close it; see "The four roles"). Part of the leave-no-trace epic, spore-host/spore-host#752.

What changes

spawn doctor checks the write a mark actually makes

The "idle teardown" check (lifecyclemark.Probe) used to try an UpdateItem on its own. A mark is one TransactWriteItems: a ConditionCheck (that the closing sentinel is absent) plus an Update. DynamoDB authorizes each item action. So an identity granted UpdateItem but not ConditionCheckItem passed doctor, while every mark it made was refused. Both actions came back implicitDeny in #1672's dev simulation.

Probe now makes that transaction: a ConditionCheck and an Update on two probe keys. Their conditions can never hold.

  • A TransactionCanceledException proves both actions are allowed.
  • Nothing is written.
  • A refusal of either action is the existing Warn, which names the principal and spore-host/spawn-user-lifecycle.

In a region with no lease table yet, the check used to pass on DescribeTable alone, and any read-only DynamoDB identity holds that (AWS ReadOnlyAccess, for one). It also implied that the first mark there would succeed, though that mark needs dynamodb:CreateTable and dynamodb:TagResource, which it never checked. Now:

  • It says those two can't be checked without creating the table, and never says the first launch creates it.
  • In the aws partition it probes the mark's writes on the us-east-1 table, which holds the global scope and which spawn setup-account creates.
  • With no table there either, it reports "not checked" and points at spawn setup-account.

The seam is probeLease, tested with per-region fakes in pkg/doctor/lease_probe_test.go.

Why CreateTable/TagResource aren't probed:

  • A deliberately invalid CreateTable only proves something if DynamoDB authorizes before it validates. That isn't documented, and it can't be confirmed without an AWS call. If validation came first, the probe would pass anyone; if the input validated, it would create the table.
  • iam:SimulatePrincipalPolicy isn't something doctor has. Most users can't call it, and it doesn't evaluate session policies or SCPs.
  • So the check reports only what it checked.

Outside the aws partition (GovCloud, China, ISO, EUSC; region per the SDK's aws-partition regex):

  • Mark (before this PR): it sent the global mark to us-east-1, which those credentials can't reach. The resulting UnrecognizedClientException counts as a refusal, and a refusal stops every later mark in the process, so a launch whose IAM setup marked global first never marked its own region.
  • Mark (now): it skips the global scope there (lifecyclemark.GlobalReachable) and marks regions as before.
  • Doctor: it probes the regional table only, says the global scope isn't marked outside the aws partition, and on a refusal no longer points at spore-host/spawn-user-lifecycle, whose ARNs are aws-partition ones (pkg/aws/iam_account_setup.go hard-codes arn:aws).

Probe passes only when every cancellation reason is ConditionalCheckFailed or None, with at least one of the former. Any other reason (a throttle, a conflict) is ErrInconclusive, and doctor reports it as "not checked", not as a pass or a refusal.

docs/reference/cli-iam-actions.md is regenerated. The generator now derives a write transaction's item actions from the items the call site builds: implied rules on TransactItems.{ConditionCheck,Put,Update,Delete}, and all four when an item is built out of sight. So spawn doctor lists ConditionCheckItem, DescribeTable and UpdateItem, which is what its probe needs. MarkActive takes its condition check from a helper (sentinelAbsent), so it still counts all four, and RequiredActions, UserActions() and the user policy are unchanged.

What doctor reports:

  • Pass:
    • spore-host-lifecycle is writable in <region>.
    • In GovCloud or China, the same plus ; spawn's global scope (its table is in us-east-1) is not marked outside the aws partition.
    • With no table here: the mark's writes are allowed (checked on the us-east-1 table); no spore-host-lifecycle table in <region> yet, and the dynamodb:CreateTable and dynamodb:TagResource its first mark needs cannot be checked without creating it.
    • In infra: not used in spore.host's infra account.
  • Warn, not checked (idle teardown not checked: …):
    • no table here or in us-east-1 (or in us-east-1 itself), with run spawn setup-account, which creates the us-east-1 table, then spawn doctor again;
    • no table here outside the aws partition (the us-east-1 table is not checked outside the aws partition);
    • an inconclusive probe (… cancelled for ThrottlingError, None; try again).
  • Warn, refused:
    • In the aws partition: idle teardown unavailable: the spore-host-lifecycle lease table isn't writable by <caller ARN> (the mark's transaction (dynamodb:ConditionCheckItem, dynamodb:UpdateItem): …not authorized to perform: dynamodb:ConditionCheckItem…). Launches are unaffected, … An administrator attaches the policy spore-host/spawn-user-lifecycle (arn:aws:iam::<acct>:policy/…)….
    • Outside it, the same refusal without the policy pointer: …The policy spawn setup-account provisions (spore-host/spawn-user-lifecycle) names aws-partition ARNs, so it does not grant this here; spawn's marks here need … on the spore-host-lifecycle table.

The IAM coverage gates now see who runs a mark

  • Sweep orchestrator (internal/iamcoverage/principals_test.go). Its member-account context now claims libs/lifecycle and pkg/lifecyclemark call sites (leasePkgs). Before this, a mark added to the orchestrator would have been checked against SpawnSweepOrchestratorRole in infra 966362334030. That account has no lease, and the gate would have counted UpdateItem/PutItem as granted because it matches on name, and that role holds them on another table. With the claim, a mark is demanded of SpawnSweepCrossAccountRole.
  • Nested spawn (pkg/aws/nested_spawn_discovery_test.go). The source-following discovery couldn't see Mark's DynamoDB calls, because they live in libs, outside the module. Reaching lifecyclemark.Mark now adds lifecyclemark.RequiredActions. The nested role holds none of them on the lease table, so each is recorded in nestedSpawnNotGranted with the reason (below).

Dependency bump, so CI can pass

go.opentelemetry.io/otel, otel/sdk and otel/trace go from v1.46.0 to v1.47.0, for GO-2026-6974 and GO-2026-6975:

  • They were published 2026-11-23T20:04Z, after main's last green Security run (19:40Z the same day).
  • They made this PR's Go Vulnerability Check fail with no related change.
  • The bump covers the root module and the dashboard-api, dns-updater, sweep-orchestrator and ttl-reaper Lambdas, with every nested module re-tidied.
  • The OTLP and stdout trace exporters are at v1.47.0 too, in the root module, dashboard-api, and dns-updater (which was on v1.44.0). Their v1.47.0 pulls newer genproto, grpc-gateway, mapstructure and proto/otlp. Only these three modules use the exporters.
  • It is its own commit, so it can be split out if preferred.

CHANGELOG

The four roles in #1672: no grant added, because none of them makes a mark

I traced the code each role runs. Granting the lease to any of them would be a grant nothing uses, and it would not make a regional scope go ACTIVE:

Role What runs as it Why no grant
SpawnSweepCrossAccountRole sweep-orchestrator Lambda The orchestrator never calls Mark. That is by design: the CLI marks every sweep region and global before invoking it (cmd/launch_sweep.go:1407), and the reaper counts unfinished sweep and schedule records as activity (lambda/ttl-reaper/accountidle.go). I checked it two ways. No lifecyclemark import, and the coverage gate passes on main with no ConditionCheckItem granted to either orchestrator role. Also, TestSweepCrossAccountRoleGrantsOnlyWhatTheOrchestratorCalls fails on an uncalled grant. The role's source is pkg/aws/sweep_role.go; the setup script is gone since #1537.
spore-portal-launch the browser portal, through spawn-ts Read-only by owner decision (#645): no RunInstances, nothing created. spore-host's gate iam-policy-source.test.ts ("is read-only: only Describe and quota reads") fails on any write.
spore-portal-e2e portal e2e proofs Its policy is the portal role's, verbatim; the nightly live.test.ts drift check enforces that. The e2e test instances are launched by spore-portal-e2e-teardown through spawn-ts.
GitHubActions-spawn-ts-live-smoke scripts/live-smoke.mjs (spawn-ts EC2Provider) spawn-ts has no DynamoDB client and no lease code, so the grant would be unusable. The role is also hand-made: infra/iam/github-oidc/trusts.json says it isn't codified, so there's no source to edit.

So the dev regions show lease unavailable … skipped because nothing that marks has created there since v0.168.0. The launches there go through spawn-ts (smoke, portal e2e) or through orchestrator sweeps. The real gap is in spawn-ts, filed as spore-host/spawn-ts#143. Once spawn-ts marks, the roles it runs as (and spore-portal-launch when #686 brings launches back) need the seven actions.

Other principals that run spawn's Go create path in member accounts

  • spawn-instance-nested-* (--nested-spawn head nodes, e.g. nf-spawn). A child's spawn launch calls Mark with the nested role, which holds no lease grant, so the mark is refused silently. Not granted here, as a deliberate default for the owner to confirm.
    • The head is a live spawn:managed instance, so its region and the global scope stay active, and the teardown can't claim them while it runs.
    • Only a child launched into a different region from its head is unfenced.
    • Granting it would let an instance's workload write the account's lease. It could forge a lease or a closing sentinel that makes every spawn create in the account wait up to 10 minutes, or reset another tool's item.
    • Flipping it means one NestedSpawnLease statement in nestedSpawnStatements and deleting the seven nestedSpawnNotGranted entries. The role name, a hash of its document, changes with it.
  • The role behind spore-plugins' secrets.AWS_DEV_ROLE_ARN (dev). It runs the latest spawn release's spawn launch, so it reaches Mark today when dispatched (the nightly run is currently skipped). It isn't codified anywhere; filed as Dev integration role behind spore-plugins AWS_DEV_ROLE_ARN runs spawn launches but has no codified lifecycle-lease grant spore-host#759. The fix there is the one case where attaching the managed policy spore-host/spawn-user-lifecycle beats an inline statement: a hand-made role has no source to carry one.
  • lagotto's lagotto-capacity-poller-role already grants all seven, on table/spore-host-lifecycle, through its own lease (pkg/runtimeiam).
  • Workflow-engine hosts (nf-spawn, cwl-spawn, miniwdl-spawn, airflow-spawn, snakemake, pegasus) run the spawn CLI as a user-supplied identity. spore-host/spawn-user-lifecycle covers them, and doctor's check run on the host names the gap.
  • spore-host's lambda/rest-api pins spawn v0.36.1, so it makes no mark yet. Noted in feat(spored): copy a failed job's log tail to the serial console (#736) #759 for when it is bumped.
  • Checked and not reaching Mark: calque workers, spore-host-mcp (stdio, the user's own credentials), lagotto's instance and scheduler roles, ttl-reaper (its member role already grants the lease, in ttl-reaper-cross-account-role.yaml), pipeline-orchestrator (infra, where Mark is skipped), dashboard Lambdas, and spawn snapshot mount on an instance (it attaches to itself, so its live instance keeps the region active).

Also found: detached spawn resume re-invokes the orchestrator without marking the sweep's regions. Filed as #1675.

The action set

spawn pins libs v0.55.0. There, MarkActive is DescribeTable and CreateTable (with Tags, so TagResource), one TransactWriteItems (ConditionCheck plus Update), and DeleteItem for a stale sentinel. lifecyclemark.RequiredActions (7) matches that, and TestLeaseRequiredActionsAreWhatMarkCalls holds it to the call graph. libs v0.56.0's MarkActive makes the same calls; its new conditional writes are other entry points. Nothing is missing, and nothing was widened.

Nothing here touches 966362334030, adds anything that could reach 942542972736, or tags spore-host:role=service.

Tests and checks

  • TestProbe models IAM per item action. Each of UpdateItem and ConditionCheckItem refused must be the probe's refusal, and the same model must refuse MarkActive too, so the model is what the mark needs. Revert check: with the old Probe (it compiles), TestProbe fails with dynamodb:ConditionCheckItem refused: <nil>, want that refusal.
  • TestProbeLease (doctor) covers 11 cases. Each checks what the result must say, what it must not say (no "first launch creates it", no policy pointer outside aws), and that nothing was written. A probe of a region the case doesn't expect fails it, which is how the GovCloud cases prove us-east-1 is never touched. Revert checks (each compiles):
    • inAWS := true || … fails the three GovCloud/China cases;
    • passing the no-table-anywhere case fails it.
  • TestProbeAcceptsOnlyItsOwnCancellation covers 7 sets of reason codes. With the code check disabled (false && !ok), the four non-condition sets fail.
  • TestMarkSkipsTheGlobalScopeOutsideTheAWSPartition uses a GovCloud config, with a us-east-1 table that refuses the credentials the way the real endpoint does. With GlobalReachable forced true it fails twice: Mark called the us-east-1 table 1 times and no table was touched for us-gov-west-1. That second failure is the latch bug itself.
  • TestGlobalReachable covers 13 regions across the partitions.
  • TestImpliedActionsFollowTheCallSite has four new fixture transactions:
    • check plus update: ConditionCheckItem, UpdateItem;
    • put: PutItem;
    • an item from a helper: all four;
    • items from a parameter whose caller builds a Delete: DeleteItem.
      TestDiscoversEveryShapeOfCall includes them too.
  • Orchestrator claim. I added a temporary lifecyclemark.Mark(ctx, cfg, region) on the orchestrator's member config (not committed):
    • with the claim, TestEveryPrincipalCallIsGranted demands all seven of SpawnSweepCrossAccountRole;
    • without it, it demands five of SpawnSweepOrchestratorRole, the wrong role in the wrong account, and misses UpdateItem/PutItem.
  • Nested discovery. With the Mark visibility disabled (if false && …, which compiles), the test fails on all six new nestedSpawnNotGranted entries as stale. With it enabled and no entries, it fails naming ConditionCheckItem, CreateTable, DescribeTable and TagResource.
  • make check passes:
    • gofmt; go vet for every GOOS; staticcheck; golangci-lint 2.15.0 in all 10 modules; hermetic short tests; nested modules; tidy.
    • check-build-tags too, run from /private/tmp. Run from the /tmp symlink it reports a false "compiled by no single-tag run", a path artifact.
  • Full (non-short) go test passes for the root package, internal/iamcoverage, pkg/aws, pkg/doctor and pkg/lifecyclemark.
  • semgrep scan --config=auto --error is clean on the changed files.

No AWS calls were made.

…n Mark (#1672)

spawn doctor's "idle teardown" check tried an UpdateItem on its own, so an
identity granted dynamodb:UpdateItem but not dynamodb:ConditionCheckItem
passed while every mark it made was refused. Probe now makes the mark's
transaction (a ConditionCheck and an Update) with conditions that never
hold: a cancellation proves both item actions are authorized and nothing
is written.

iamcoverage: the sweep orchestrator's member-account context claims
libs/lifecycle, so a lease mark added to the orchestrator is demanded of
SpawnSweepCrossAccountRole, never of SpawnSweepOrchestratorRole in the
infra account. The nested-spawn coverage discovery now sees
lifecyclemark.Mark and records the lease actions as deliberately not
granted to spawn-instance-nested-* roles, with the reason.

Also removes an orphaned fragment from [Unreleased] ### Changed.

Refs #1672
…n's (#1672)

A region with no spore-host-lifecycle table passed the idle-teardown check
on DescribeTable alone, which any read-only DynamoDB identity holds. The
check now probes the us-east-1 table (the global scope's, which
spawn setup-account creates) before saying the first launch creates it.

Refs #1672
…4, GO-2026-6975)

Both were published 2026-11-23, after main's last green Security run,
and turn this PR's Go Vulnerability Check red with no related change.
Root module plus the dashboard-api, dns-updater, sweep-orchestrator and
ttl-reaper Lambdas; every nested module re-tidied.

Refs #1672
@codecov

codecov Bot commented Nov 26, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 94.31818% with 5 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
pkg/doctor/aws_prober.go 87.87% 4 Missing ⚠️
pkg/lifecyclemark/lifecyclemark.go 97.72% 1 Missing ⚠️

📢 Thoughts on this report? Let us know!

…1672 review)

otlptrace, otlptracehttp and stdouttrace move to v1.47.0 in the root module
and the dashboard-api and dns-updater Lambdas (dns-updater was on v1.44.0),
so every OTel module is on one release. Their v1.47.0 needs newer genproto,
grpc-gateway, mapstructure and proto/otlp; every nested module re-tidied.

Refs #1672
…tside the aws partition (#1672 review)

- doctor no longer says "the first launch creates it". In a region with no
  lease table the first mark needs dynamodb:CreateTable and TagResource,
  which nothing can check without creating the table (no dry run; a
  CreateTable IAM allows creates it), and the check says so. It still
  probes the mark's writes on the us-east-1 table; with no table there
  either it is "not checked", pointing at spawn setup-account.
- Outside the aws partition doctor no longer probes us-east-1 or points a
  refusal at the aws-only user policy. Mark no longer marks the global
  scope there: the mark was refused, and a refusal stopped every later
  mark in the process, so a launch's regional mark never ran.
- Probe passes only when every cancellation reason is ConditionalCheckFailed
  or None; anything else is ErrInconclusive ("not checked").
- iamcoverage: a write transaction's item actions come from implied rules on
  TransactItems.<kind>, so doctor's probe needs ConditionCheckItem and
  UpdateItem only (cli-iam-actions.md regenerated); MarkActive, whose
  condition check comes from a helper, still counts all four.
- The orchestrator's member-account context also claims pkg/lifecyclemark.
- Comment fixes: UserActions' probe uses three actions; the nested-spawn
  reason cites spawn#1672 instead of itself.

Refs #1672

This branch has not been deployed

No deployments
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.

1 participant