Skip to content

Reaper account-idle sweep (report mode), lease marks on every creator, --if-idle-for from the lifecycle verdict; keep the boundary (#1654, #1664) - #1665

Merged
scttfrdmn merged 2 commits into
mainfrom
feat/1654-account-idle
Nov 20, 2026

Conversation

@scttfrdmn

@scttfrdmn scttfrdmn commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

Part of #1654. Fixes #1664.

Report mode only. Nothing in this PR deletes anything. The reap flip is #1657.

#1664: the boundary is never swept

instancerole.SweepSporedPolicies (run by spawn cleanup --instance-roles) used to delete spore-host/spawn-instance-boundary. Now:

  • The boundary is caught first, by name or by ARN, and always kept (KeepBoundaryPermanent, pointing at spawn setup-account --remove + docs for the permanent boundary #1656). This applies whether it is in use, unused, old or young.
  • A spored policy tagged spore-host:permanent=true is kept. So is one whose tags can't be read (fail closed). The sweep reads tags only for delete candidates, and so needs iam:ListPolicyTags.
  • The boundary-only version-deletion code is gone. PolicyAPI no longer has ListPolicyVersions/DeletePolicyVersion.
  • No reaper role grants iam:DeletePolicy, so no Deny was needed. TestReaperCannotDeleteAPolicy (pkg/reaperiam) fails if any of the three policy copies ever grants iam:DeletePolicy, DeletePolicyVersion or an iam wildcard.

Lease marks on every creator (pkg/lifecyclemark)

Mark(ctx, cfg, scopes...) calls lifecycle.MarkActive(spawn, scope) before a create. The scope is the region, or global (us-east-1) for IAM.

A denied or failed mark never fails the create, and prints nothing the user sees.

  • It goes only to spawn's diagnostic log: ~/.spawn/spawn.log, or stderr with --verbose.
  • After a refusal it stops trying for the rest of the process.
  • The account then counts as "lease unavailable", and the reaper never idle-tears it down.
  • The only user-visible line left is a wait of more than 30 s, which means a teardown really holds the lease.
  • Nothing is marked in the infra account.
  • Nothing spore.host provisions grants a CLI user these actions: setup-account creates only the boundary, and every role spawn creates is a machine role. That gap is filed as Provision the user-side lifecycle-lease IAM (spore-host-lifecycle) instead of documenting it #1666.

spawn doctor "idle teardown" check.

Where marks are called:

  • Launch and zone fallback, ImportKeyPair, instance profiles and roles, security groups, FSx, image-import infra, placement groups, buckets, snapshot volumes.
  • Pool queues, spawn reaper deploy, bot and onboard roles, setup-account, the sweep role, the egress proxy, schedule create, and detached sweep submit.
  • The orchestrator Lambdas don't mark. The reaper's verdict counts their records as activity instead.

Gate TestEveryCreatorMarksTheLease:

  • It discovers every function that calls Mark, then walks each command with those functions as cuts. Any creating action still reachable fails the gate.
  • The creating actions are derived from footprintspawn.DeletableTypes() plus FSx. There is one exemption, the doctor's DryRun probe.
  • It also checks that the failure path makes no fmt or log call, names no os.Stdout/os.Stderr, and does call the diagnostic logger.

Behavioural test TestADeniedLeaseMarkIsSilentAndTheCreateProceeds (pkg/aws). It runs a real creator through a DynamoDB client that answers AccessDenied, and checks:

  • stdout and stderr are empty;
  • one diagnostic line is written;
  • the mark happens before the create;
  • the create proceeds.

TestLeaseRequiredActionsAreWhatMarkCalls holds the action list that the log line and doctor name to what Mark can call.

Reaper account-idle sweep (lambda/ttl-reaper/accountidle.go)

  • Mode is REAPER_ACCOUNT_IDLE = off|report|reap, default report. reap also reports. The grace is REAPER_ACCOUNT_IDLE_GRACE, default 24h.
  • SAM parameters: AccountIdle, AccountIdleGrace. Deploy flags: spawn reaper deploy --account-idle / --account-idle-grace.
  • GuardTeardown(account) runs first. The infra account, and an unidentified account, are refused before any read.
  • The verdict is computed per scanned region plus global. Any read failure counts as active.
signal source
spawn instances pending through stopped (spawn:managed=true) member, DescribeInstances
egress proxy instances (spawn:egress-proxy) member, DescribeInstances
FSx creating/updating, or younger than 30 min member, DescribeFileSystems
spawn-pool-* queues in use (pkg/poolqueue keep reasons, workers over every enabled region) member, SQS + DescribeInstances
calque resources classed active, or failed listings (read only when spawn's own signals are idle) member, calquefootprint.Inventory
sweeps not finished, pipelines not finished, schedules that will still fire, for that account infra (base creds), Scan of spawn-sweep-orchestration, spawn-pipeline-orchestration, spawn-schedules
global scope also: a spawn instance in any enabled region member
  • Each scope then goes through these steps:
    1. Get. If there is no item, or Epoch is 0, the lease is unavailable: skip, and never create the table. If the read fails, skip with a warning.
    2. Observe(active).
    3. Once the scope has been idle past the grace: Claim.
    4. Re-read every signal. If anything is active, Release.
    5. Build the plan with pkg/aws.AccountFootprint (the spawn footprint -o json scan) and pkg/footprintspawn.
    6. Run footprint.Execute in ModeReport with the real lease and teardown.NewReportOnly. That deleter has no delete reachable, so the reaper role is never asked to grant one.
    7. Log every row and the summary.
    8. Log calque's verdicts once, under global.
    9. Release. It never calls Finish.
  • Release restarts the grace, so an idle account is reported once per grace period.

Log lines:

account-idle REPORT account=<id> region=<scope> outcome=<would-delete|kept|refused|skipped|gone|failed> type=<cfn type> name=<name> arn=<arn> reason="<why>"
account-idle REPORT account=<id> region=<scope> would_delete=N kept=M
account-idle REPORT tool=calque account=<id> region=<r> deletable=<bool> class=<c> type=<t> name=<n> arn=<a> reason="<why>"
account-idle REPORT tool=calque account=<id> would_delete=N kept=M

calque module: imported

I imported github.com/spore-host/calque/pkg/calquefootprint. The cycle check was clean:

  • go mod tidy works.
  • No version conflicts. replace spawn => ../.. wins over calque's spawn v0.131.0 pin.
  • lagotto, truffle and cohort appear only in the module graph, not the build, and aren't in go.mod.
  • go list -deps grew 502 → 523.
  • MVS bumped the reaper's SDK modules: iam 1.53 → 1.64, dynamodb 1.57 → 1.70, sqs 1.42 → 1.52, ssm 1.69 → 1.79.

Caveats:

  • calque#236 isn't in a tagged calque release yet, so the pin is a pseudo-version of calque's main (fced2c6). Bump it when calque tags a release.
  • The require spawn line reads v0.131.0. That's cosmetic: the replace wins.
  • calquefootprint.Collect can list S3 objects for Options.Buckets. The reaper passes none, but the call graph can't see that. It is ledgered as a permanent denied call in internal/iamcoverage/gaps_test.go: the member role reads no S3 objects or object tags.

spawn reaper teardown --if-idle-for

  • Idleness now comes from the lifecycle verdict (reaperdeploy.LeaseIdleness, a Get per scanned region plus global), not from log lines.
  • The existing refusals stay: undetermined, the reaper not running (still read from its logs), and the 720h bound.
  • New refusals: no verdict (lease unavailable), the sweep off, a scope active, and a wait longer than the reaper's account-idle grace. Each report restarts the grace, so a longer wait could never fire. Deploy with --account-idle-grace 30d to wait 30d.

IAM changes, for PutRolePolicy and simulation

  • Member stack (ttl-reaper-cross-account-role.yaml), mirrored in the SAM ScanSelf branch and reaperiam.AccountIdleStatements:
    • dynamodb:GetItem, UpdateItem, PutItem, DeleteItem, ConditionCheckItem, DescribeTable, CreateTable, TagResource on arn:aws:dynamodb:*:${AWS::AccountId}:table/spore-host-lifecycle.
    • Read-only on *: cloudformation:DescribeStacks, dynamodb:ListTables, dynamodb:ListTagsOfResource, ec2:DescribeImages, ec2:DescribeNetworkInterfaces, ec2:DescribeSnapshots, ec2:DescribeVolumes, events:ListEventBuses, events:ListRules, events:ListTagsForResource, lambda:ListFunctions, lambda:ListTags, logs:DescribeLogGroups, logs:ListTagsForResource, scheduler:GetSchedule, scheduler:ListSchedules, sns:ListTopics, sns:ListTagsForResource, tag:GetResources.
    • IAM metadata on *: iam:GetRole, ListRoleTags, ListAttachedRolePolicies, ListInstanceProfilesForRole, GetInstanceProfile, ListInstanceProfiles, ListInstanceProfileTags, ListPolicies, GetPolicy, ListPolicyTags.
    • iam:ListRolePolicies, GetRolePolicy on role/calque-*.
    • sqs:GetQueueAttributes, ListQueueTags on calque-*.
    • sqs:GetQueueUrl added to the spawn-pool-* statement.
    • s3:ListAllMyBuckets on * (names only).
    • Bucket tags and emptiness stay on spawn's two bucket families. No staging list was added (User data: fetch the bootstrap from S3 behind a small verifying stub, removing the 16 KiB ceiling (follow-up to #1246) #1274), so the footprint classes a staging bucket as user data.
  • Reaper role (SAM, base creds): dynamodb:Scan on spawn-sweep-orchestration and spawn-pipeline-orchestration (us-east-1). These are also in ScanSelfPolicyDocument, for spawn reaper deploy. A missing table reads as no records.
  • User baseline: docs/reference/cli-iam-actions.md is regenerated. Launch paths now list dynamodb:ConditionCheckItem, UpdateItem, PutItem, DeleteItem, DescribeTable, CreateTable, TagResource. The umbrella baseline doc is docs(iam): LifecycleLease in the user baseline (spawn#1654) spore-host#755; spore.host does not provision these for users yet (Provision the user-side lifecycle-lease IAM (spore-host-lifecycle) instead of documenting it #1666).
  • crossAccountGrantedActions now parses the role instead of regex-scraping a hand-listed set of services; the regex missed seven services. Existing scope gates were adjusted, with comments: S3, SQS, the schedule grants, and taskiam's staging list.

Tests and gates

  • New reaper tests (accountidle_test.go):
    • every signal, including read failures, makes both scopes active;
    • infra signals are per account;
    • a missing infra table is no records;
    • Observe, then Claim after the grace, with an injected clock; zero deletes and the full plan logged;
    • the post-claim re-check releases;
    • lease unavailable (no item, epoch 0, unreadable) is skipped, with no CreateTable;
    • the infra account and an unknown account are refused before any read;
    • the modes;
    • the constants agree with their sources.
  • Revert checks, each watched failing against a compiling revert:
    • report mode changed to reap: deletes;
    • the guard removed: the infra account is read;
    • an instance read failure counted idle;
    • the post-claim re-check removed;
    • the epoch-0 rule removed;
    • NewReportOnly given a real delete;
    • the --if-idle-for active and grace checks removed;
    • the boundary deletable again (spawn cleanup --instance-roles deletes the permissions boundary (owner decision: permanent) #1664);
    • the permanent-tag check removed;
    • a Mark call removed (the gate fails);
    • warn-once and stop-after-refusal removed;
    • a lease write on *, and iam:DeletePolicy, added to the member template.
  • Gates: make check passed (run from a space-free copy); make api-snapshot (two additions to pkg/aws: GatherFootprint, AccountFootprint); make cli-iam-actions; make gen-docs; reaper IAM coverage, drift and template tests; semgrep on the 54 changed files (0 findings).
  • Nothing called AWS.

Deploy notes

To deploy, redeploy the member stack (spawn-ttl-reaper-ec2) first, then the production reaper. Until the member stack is redeployed, each scope logs "lease unavailable" and nothing else changes.

Before deploying, run a real PutRolePolicy on the new statements, and simulate them both ways (allow and deny).

…reator, --if-idle-for from the lifecycle verdict; keep the boundary (#1654, #1664)

Part of #1654 (leave-no-trace, spore-host/spore-host#752). Fixes #1664.

- lambda/ttl-reaper: the account-idle sweep (REAPER_ACCOUNT_IDLE, default
  report; reap reports until #1657). Per member account and scope (each
  scanned region, and global), the verdict from every signal, a read failure
  counting as active: spawn instances pending through stopped, egress
  proxies, FSx being made or just made, pool queues in use, calque's
  footprint (pkg/calquefootprint), and the infra account's sweeps, pipelines
  and pending schedules for that account. Observe in the member's
  spore-host-lifecycle table; after REAPER_ACCOUNT_IDLE_GRACE (24h): Claim,
  re-check (activity -> Release), plan with spawn footprint's scan and rules,
  footprint.Execute in ModeReport with the real lease and a deleter that
  cannot delete, log every row and "account-idle REPORT account=... region=...
  would_delete=N kept=M", Release. Never Finish, never delete. GuardTeardown
  first. A scope no creator has marked (no item / epoch 0) is lease
  unavailable and skipped; the sweep never creates the table for it.
- IAM: the member role and ScanSelfStatements gain the lease table (exact
  name) and read-only footprint/calque reads; the SAM template gains Scan on
  the sweeps and pipelines tables. No reaper role can delete a policy (gate).
- pkg/lifecyclemark: Mark before every create a teardown could delete;
  warn once and continue when it fails (lease unavailable); a gate
  (TestEveryCreatorMarksTheLease) discovers the creators.
- spawn reaper teardown --if-idle-for: idleness from the lifecycle verdict;
  the undetermined and not-running refusals stay.
- #1664: SweepSporedPolicies never deletes spore-host/spawn-instance-boundary
  nor a policy tagged spore-host:permanent=true (or with unreadable tags).
- iamcoverage: TransactWriteItems maps to the item actions DynamoDB
  authorizes it by.
@codecov

codecov Bot commented Nov 17, 2026 •

Copy link
Copy Markdown

…ts it (#1654, #1666)

A failed or denied lifecyclemark.Mark printed a warning once per process,
which is every `spawn launch` for any user whose IAM lacks the lease
actions (most users today: nothing spore.host provisions grants them,
spawn#1666). It now writes only to spawn's diagnostic log (~/.spawn/spawn.log,
stderr with --verbose); the account just counts as lease unavailable. The one
user-visible line left is a wait past 30 s, when a teardown really holds the
lease.

- spawn doctor: an "idle teardown" check, read-only (DescribeTable, and an
  UpdateItem whose condition can never hold), Warn naming the principal.
- Gates: TestEveryCreatorMarksTheLease now also checks the failure path makes
  no fmt/log call and names no os.Stdout/os.Stderr, and does log; pkg/aws's
  TestADeniedLeaseMarkIsSilentAndTheCreateProceeds runs a real creator with a
  denied lease and asserts empty stdout/stderr, a diagnostic line, and the
  create.
@scttfrdmn

Copy link
Copy Markdown
Contributor Author

Owner decision (2026-11-20): yes, the reaper's member role must never read users' S3 object contents. The permanent-deny entry in internal/iamcoverage/gaps_test.go stands as an owner-confirmed rule.

@scttfrdmn

Copy link
Copy Markdown
Contributor Author

LIVE launch check (dev 435415984226, us-east-1, 2026-11-20, CLI built from this branch at ba22e44)

  • spawn launch of a t3.micro: rc 0, exactly one instance. The only stderr line was the usual cost estimate, with no lease noise.
  • spore-host-lifecycle was created on first mark, tagged managed-by=spore-host, component=lifecycle, scope, created, schema, owner, with no role. Items: tool#spawn#us-east-1 ACTIVE epoch 1 and tool#spawn#global ACTIVE epoch 1.
  • spawn doctor: ✓ idle teardown: spore-host-lifecycle is writable in us-east-1.
  • Terminated the instance and dropped the test lease table. Leak check: no a4-* instances, unattached EIPs or available volumes.

CI: the Tier 0 failure (TestTier0_SweepRowIAMRoleBeatsCLI, two c5.xlarge) was a flake, and passed on re-run; filed separately.

Owner decision recorded above: the member role never reads S3 objects.

Deploy (later, with owner approval): the member stack spawn-ttl-reaper-ec2 first, then the production reaper. The account-idle sweep ships in report mode.

@scttfrdmn
scttfrdmn marked this pull request as ready for review November 20, 2026 16:35
@scttfrdmn
scttfrdmn merged commit d706ae0 into main Nov 20, 2026
12 of 13 checks passed
@scttfrdmn
scttfrdmn deleted the feat/1654-account-idle branch November 20, 2026 16:36
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.

spawn cleanup --instance-roles deletes the permissions boundary (owner decision: permanent)

1 participant