Repository navigation
feat(reaper): self-hosted reaper plans its own removal when the account is idle (report mode) (#1655) - #1668
Merged
Conversation
…ccount is idle (report mode) (#1655) Part of #1655 (leave-no-trace, spore-host/spore-host#752). Report mode only: nothing is created or deleted; reap reports until #1657. - lambda/ttl-reaper: when `spawn reaper deploy`'s reaper (spawn-ttl-reaper- selfscan, scanning only its own account) has, in one run, reported every account-idle scope and its artifact bucket holds only ttl-reaper/ objects, it plans its removal under the global lease and logs every step (`reaper-selfremoval REPORT step=... offset=... target=... resource=...`) and a summary. REAPER_SELF_REMOVAL=off|report|reap, default report; effectiveSelfRemovalMode maps reap to report (pinned). A due scope is held while another is inside its grace and nothing is active, so every scope comes due in one run (each report restarts its own grace). - pkg/reaperdeploy: the plan (one-shot jobs in spawn-reaper-teardown: the function at +2m, role policies at +4m, the role at +5m unless another region's reaper shares it, the log group at +15m; then the bucket, only when tagged spawn:managed; then the rules, targets and permissions), the one-shot builder (fixed names, ConflictException resumes), the spawn-reaper-teardown-invoke role created at deploy (Scheduler trust for this account only; may delete only the reaper's function, log group and role; Denies on role=service and the boundary), the reaper role's added grants, and teardown removing the group and the invoke role. - IAM gates: a self-removal principal in internal/iamcoverage, cut from the shared reaper inventory; SAR implied rules for CreateScheduleGroup tags and DeleteScheduleGroup; a policy evaluator test for both roles' reach. - spawn reaper deploy --self-removal.
Contributor
Author
IAM verification (dev 435415984226, 2026-11-20)The documents were generated from this branch ( Teardown invoke role
Reaper role
The test roles were deleted. |
scttfrdmn
marked this pull request as ready for review
November 20, 2026 17:21
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
scttfrdmn
added a commit
that referenced
this pull request
Nov 20, 2026
After a command succeeds, the root command's post-run hook runs libs/lastmile (v0.55.0) for spawn: it reports a stale teardown lease (with its plan re-checked by pkg/teardown's report-only deleter), the self-hosted reaper's teardown residue (the spawn-reaper-teardown-invoke role and each region's spawn-reaper-teardown schedule group, #1668) once no spawn lifecycle item is left, and an empty spore-host-lifecycle table. Report only and never in the way: nothing on stdout, nothing at all without --verbose (then debug: lines on stderr), the exit status is untouched, the hook stops waiting after the 30 s budget, between 6-hourly checks it makes no AWS call, and a cut-off check waits an hour. The account comes from the command's own GetCallerIdentity, observed passively through an inert pkg/config seam that only cmd.Execute sets. The lifecycle client refuses every write and the Deleter every delete. Skipped after completion, help, version, footprint, teardown, doctor, cleanup, every reaper subcommand and hidden plumbing commands, and in the infra account; SPORE_LASTMILE=off turns it off. FullVisibility is false: the account-idle verdict is package main of lambda/ttl-reaper and not reusable from cmd. The decision (an activity reader AND readable infra-account tables) is encoded and tested both ways. The wiring is in cmd/lastmile.go; the AWS-touching pieces are in the new pkg/lastmilespawn (cmd may not import SDK services, #326/#327). libs is bumped to v0.55.0 in the root, ttl-reaper and sweep-orchestrator modules. Part of spore-host/libs#78.
scttfrdmn
added a commit
that referenced
this pull request
Nov 20, 2026
After a command succeeds, the root command's post-run hook runs libs/lastmile (v0.55.0) for spawn: it reports a stale teardown lease (with its plan re-checked by pkg/teardown's report-only deleter), the self-hosted reaper's teardown residue (the spawn-reaper-teardown-invoke role and each region's spawn-reaper-teardown schedule group, #1668) once no spawn lifecycle item is left, and an empty spore-host-lifecycle table. Report only and never in the way: nothing on stdout, nothing at all without --verbose (then debug: lines on stderr), the exit status is untouched, the hook stops waiting after the 30 s budget, between 6-hourly checks it makes no AWS call, and a cut-off check waits an hour. The account comes from the command's own GetCallerIdentity, observed passively through an inert pkg/config seam that only cmd.Execute sets. The lifecycle client refuses every write and the Deleter every delete. Skipped after completion, help, version, footprint, teardown, doctor, cleanup, every reaper subcommand and hidden plumbing commands, and in the infra account; SPORE_LASTMILE=off turns it off. FullVisibility is false: the account-idle verdict is package main of lambda/ttl-reaper and not reusable from cmd. The decision (an activity reader AND readable infra-account tables) is encoded and tested both ways. The wiring is in cmd/lastmile.go; the AWS-touching pieces are in the new pkg/lastmilespawn (cmd may not import SDK services, #326/#327). libs is bumped to v0.55.0 in the root, ttl-reaper and sweep-orchestrator modules. Part of spore-host/libs#78.
scttfrdmn
added a commit
that referenced
this pull request
Nov 20, 2026
* feat: the lazy CLI last mile, report mode (libs#78) After a command succeeds, the root command's post-run hook runs libs/lastmile (v0.55.0) for spawn: it reports a stale teardown lease (with its plan re-checked by pkg/teardown's report-only deleter), the self-hosted reaper's teardown residue (the spawn-reaper-teardown-invoke role and each region's spawn-reaper-teardown schedule group, #1668) once no spawn lifecycle item is left, and an empty spore-host-lifecycle table. Report only and never in the way: nothing on stdout, nothing at all without --verbose (then debug: lines on stderr), the exit status is untouched, the hook stops waiting after the 30 s budget, between 6-hourly checks it makes no AWS call, and a cut-off check waits an hour. The account comes from the command's own GetCallerIdentity, observed passively through an inert pkg/config seam that only cmd.Execute sets. The lifecycle client refuses every write and the Deleter every delete. Skipped after completion, help, version, footprint, teardown, doctor, cleanup, every reaper subcommand and hidden plumbing commands, and in the infra account; SPORE_LASTMILE=off turns it off. FullVisibility is false: the account-idle verdict is package main of lambda/ttl-reaper and not reusable from cmd. The decision (an activity reader AND readable infra-account tables) is encoded and tested both ways. The wiring is in cmd/lastmile.go; the AWS-touching pieces are in the new pkg/lastmilespawn (cmd may not import SDK services, #326/#327). libs is bumped to v0.55.0 in the root, ttl-reaper and sweep-orchestrator modules. Part of spore-host/libs#78. * test: the no-budget-left case is already past its deadline (Windows clock) A 1 ns budget can still read as positive under Windows' coarse clock, so lastmile.Run ran. A negative budget is past its deadline everywhere. Part of spore-host/libs#78. * CHANGELOG: keep [0.168.0] as tagged; last-mile entries under [Unreleased] --------- Co-authored-by: spore-host release <[email protected]>
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.
Part of #1655 (leave-no-trace, spore-host/spore-host#752). Draft, report mode only: nothing is created or deleted. The reap flip is #1657.
What it does
The reaper
spawn reaper deploymade (spawn-ttl-reaper-selfscan, scanning only its own account) now plans its own removal once the account-idle sweep (#1665) has, in one run, claimed, re-checked and reported every scope it judges (each scanned region andglobal), and its artifact bucket holds onlyttl-reaper/objects. The plan is made under the global scope's lease and logged; nothing is executed.The plan, in execution order (offsets from the plan)
spawn-reaper-teardown(taggedspore-host:managed-by=spawn)scheduler:CreateScheduleGroupspawn-reaper-teardown-functionaws-sdk:lambda:deleteFunctionspawn-reaper-teardown-role-inlinespawn-ttl-reaper-selfscan-policyaws-sdk:iam:deleteRolePolicyspawn-reaper-teardown-role-managedAWSLambdaBasicExecutionRoleaws-sdk:iam:detachRolePolicyspawn-reaper-teardown-rolespawn-ttl-reaper-selfscan-roleaws-sdk:iam:deleteRolespawn-reaper-teardown-log-group/aws/lambda/spawn-ttl-reaper-selfscanaws-sdk:cloudwatchlogs:deleteLogGroupspawn:managed=trueand holding onlyttl-reaper/(untagged: kept; anything else: no plan at all)s3:DeleteBucketevents:RemoveTargets,events:DeleteRule,lambda:RemovePermissionJobs: fixed names,
ActionAfterCompletion=DELETE,FlexibleTimeWindow=OFF, run asspawn-reaper-teardown-invoke(never the reaper's own role);ConflictExceptionon the group or a job counts as success, so a crashed run resumes. Steps 3-5 are dropped (role kept, logged) when another enabled region has aspawn-ttl-reaper-selfscanfunction (the role is account-wide) or that can't be checked.Order differs from the issue's listing on purpose: jobs first, triggers last, as in lagotto#335. If the jobs can't be created the rules still fire and the next run retries with the same names; deleting the rules first would leave a reaper that never runs again. Role policies at +4m and role at +5m (not both at +5m), because
DeleteRolerefuses a role that still has policies.Log lines:
reaper-selfremoval REPORT step=<i>/<n> action=<what> how=<direct|one-shot|kept> offset=+<d> target=<api> resource=<arn> [name= group= at= input=] [reason=], thenreaper-selfremoval REPORT account=… region=… steps=13 one_shots=5 direct=8 kept=0 group=spawn-reaper-teardown invoke_role=… role_kept=….Mode
REAPER_SELF_REMOVAL=off|report|reap(defaultreport;spawn reaper deploy --self-removal).effectiveSelfRemovalModemapsreaptoreportuntil #1657, pinned byTestSelfRemovalReapStillReports. TheCreateOneShotscall is already in the code behind that mapping, so the IAM coverage gate checks the scheduler grants against a real call site.Keeping scopes in phase
Each report releases its lease, which restarts that scope's grace, so scopes reported in different runs would never be reported in the same run again. A regional-only lease mark (most launches) causes exactly that. So, for the self-hosted reaper only, when nothing is active or unreadable and some scope is still inside its grace, a scope that is already past the grace is held (logged,
account_idle_held) until every scope is past it. If anything is active, the per-scope reports run as in #1665. A scope no creator has marked doesn't block, as long as nothing in it is active.The invoke role (created at
spawn reaper deploy, never at idle time)spawn-reaper-teardown-invoke, tagged like the rest of the reaper (spore-host:managed-by=spawn,spore-host:component=ttl-reaper, nospore-host:role).Trust:
{"Effect":"Allow","Principal":{"Service":"scheduler.amazonaws.com"},"Action":"sts:AssumeRole","Condition":{"StringEquals":{"aws:SourceAccount":"<acct>"}}}Inline
spawn-reaper-teardown-invoke-policy:lambda:DeleteFunctiononarn:aws:lambda:*:<acct>:function:spawn-ttl-reaper-selfscanlogs:DeleteLogGrouponarn:aws:logs:*:<acct>:log-group:/aws/lambda/spawn-ttl-reaper-selfscanand…:*iam:DeleteRolePolicy,iam:DeleteRoleonarn:aws:iam::<acct>:role/spawn-ttl-reaper-selfscan-roleiam:DetachRolePolicyon that role, ifArnEquals iam:PolicyARN = arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole*on*ifaws:ResourceTag/spore-host:role = serviceiam:Create*|Delete*|Put*|Set*|Tag*|Untag*|Update*|Attach*|Detach*onarn:aws:iam::<acct>:policy/spore-host/spawn-instance-boundaryThe reaper's own role (one inline policy,
reaperdeploy.PolicyDocument= reaperiam scan-self + own-account + these) gains:lambda:GetFunctiononarn:aws:lambda:*:<acct>:function:spawn-ttl-reaper-selfscan(its own tags, other regions)s3:ListBucket,s3:GetBucketTaggingonarn:aws:s3:::spawn-reaper-artifacts-<acct>-*(+ the--bucketone if custom)scheduler:CreateScheduleonarn:aws:scheduler:*:<acct>:schedule/spawn-reaper-teardown/*scheduler:CreateScheduleGroup,scheduler:TagResourceonarn:aws:scheduler:*:<acct>:schedule-group/spawn-reaper-teardowniam:PassRoleonarn:aws:iam::<acct>:role/spawn-reaper-teardown-invokeifStringEquals iam:PassedToService = scheduler.amazonaws.comThese are not in
reaperiam.ScanSelfStatements, so the cross-account member role and the SAM template are unchanged. The operated reaper never removes itself.Not yet verified against real IAM. There's no AWS access here. Both documents need a real
PutRolePolicyon a throwaway role, and simulation, before this merges.Human path
spawn reaper teardownworks as before, and now also deletes thespawn-reaper-teardowngroup and the invoke role (needsscheduler:DeleteScheduleGroupandscheduler:DeleteSchedule; seedocs/reference/cli-iam-actions.md).--if-idle-foris unchanged (#1665).Gates / tests
internal/iamcoverage: new principalttl-reaper self-removal(root(*reaper).removeSelf, variant =PolicyDocument, passes the invoke role to Scheduler); thettl-reaperprincipal cuts it. Implied rules added from the SAR:CreateScheduleGroup+ Tags →scheduler:TagResource;DeleteScheduleGroup→scheduler:DeleteSchedule.pkg/reaperiamdrift gates cut the same entry;pkg/reaperdeployTestSelfRemovalCallsAreGrantedholds that subtree to the self-hosted policy in both directions.TestTheTeardownInvokeRoleCanDeleteOnlyTheReaper,TestTheReaperCannotDeleteItself,TestSelfRemovalStatementsReach; sizeTestThePolicyFitsAnInlinePolicy.