Repository navigation
reaper: spawn reaper deploy/arm/status/teardown — run the reaper in your own account - #636
Merged
Merged
Conversation
…r in your own account The reaper's normal shape is a Lambda in spore.host's infra account assuming a role in each launching account. That requires the launching account to trust an EXTERNAL principal, which many organizations forbid outright — attempting it in one produced an automated security finding in 12 minutes and the org's tooling flipped the trust policy to Deny. Least privilege did not help; the objection was the external principal itself. So those accounts had no backstop at all. spored enforces TTL from INSIDE each instance, so nothing reclaimed a stopped instance past its deadline or a filesystem that outlived its instance. One sat stopped for 13 days, still billing EBS. #624 made that detectable; this makes it fixable. 'spawn reaper deploy' converges role -> artifact -> function -> EventBridge rule with direct API calls, no CloudFormation. An EventBridge RULE rather than Scheduler because a rule needs no separate invoke role — one fewer principal for a lagotto#170-style authorization bug to hide in. It deploys UNARMED (REAPER_DRY_RUN=true). Arming is a separate confirmed step, because this terminates instances and a single command should not start doing that in an account whose tagging it has never been seen to evaluate. Re-deploying an ARMED reaper preserves that state: silently reverting it to dry-run would remove protection the operator deliberately enabled. cmd/ constructs no SDK clients — TestNoNewAWSSDKImportsInCmd caught the first attempt, and writing reaperdeploy.New(cfg) was the right answer to that gate rather than adding four services to its allowlist. Verified end to end on a real account (the one with no coverage): doctor '!! not covered' -> deploy -> doctor 'OK in-account reaper spawn-ttl-reaper-selfscan' -> dry-run invoke: FSxScanned:3 Errors:0, reaped nothing (the fsx grants from #635 are what make that scan succeed rather than AccessDeny) -> arm -> 1-minute-TTL instance -> 'REAPED i-0befb34f37c81fbe4 — ttl-deadline', dry-run=false -> teardown removed all 7 resources -> doctor back to '!! not covered' Account left exactly as found; leak-checked (no instances, no function, no role, 0 available volumes, test bucket removed). Two defects found and fixed in my own code along the way: - Teardown claimed 'removed rule X' on a second run when the rule was already gone: EventBridge's DeleteRule is idempotent and returns success for a missing rule, so err==nil proved nothing. It now checks DescribeRule first. Claiming work that did not happen is the same defect class as the rest of this work, just smaller. - The IAM-propagation wait made the unit suite take 40s; it is now injectable and the suite runs in 0.18s. Also: adding the eventbridge SDK to the root module required 'go mod tidy' in lambda/ttl-reaper (own go.mod + replace ../..), which would otherwise have failed govulncheck CI with 'updates to go.mod needed'. Refs #625
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
… and classify 'reaper' for the Tier 0 gate Two CI failures, both my doing. 1. 'go: updates to go.mod needed' in lambda/sweep-orchestrator (and alert-handler, autoscale-orchestrator), failing both govulncheck and the lambda build job. I had identified these three as already untidy on main and reasoned they were pre-existing and out of scope — correct until I added the eventbridge SDK to the root module. They carry 'replace ../..', so changing the root's requirements changed what they resolve, pushing them from untidy-but-resolvable to needs-tidy-to-build. Changing the root module makes them my problem; tidied. Every module in the repo is now tidy, which it was not before. 2. TestTier0_CommandCoverageGate: a new top-level command must be classified as Tier 0-covered or explicitly deferred with a reason, so coverage decisions can't be skipped silently. 'reaper' is deferred: Substrate doesn't route Lambda tag ops (substrate#1142), and the value of the command is a scheduled function that actually terminates things, which no emulator can demonstrate. The reason records the real-account verification that was done instead, and where the pure logic is unit-tested. Refs #625
A compiled 22 MiB binary is checked into the repo at lambda/autoscale-orchestrator/autoscale-orchestrator and is NOT in .gitignore, so running 'go build ./...' in that module to verify the tidy rewrote it and the previous commit carried a 23 MB binary diff. Restored to main's bytes. The tracked binary is a pre-existing problem — a build artifact in version control, unlike every other lambda whose binary is gitignored — but removing it is someone's deliberate-or-not decision about deploy tooling, not something to fold into this PR. Noted on the issue instead.
scttfrdmn
added a commit
that referenced
this pull request
Oct 3, 2026
Third attempt at the presence half, and the first that actually runs. Attempt 1: 'git diff base...HEAD' at fetch depth 1 — died with 'no merge base' (exit 128) before reaching any logic, which would have failed EVERY pull request. Attempt 2: deepen main to 100 commits — still no merge base, because the PR branch is itself fetched at depth 1, so no shared object exists locally. The gate then took its warn-and-skip fail-safe on every run. That is the worse outcome: it reads as enforcement while enforcing nothing, which is exactly the defect #624 fixed in the reaper-coverage check. Attempt 3: 'gh api repos/{repo}/pulls/{n}/files'. GitHub already knows what the PR changed; no history needed, nothing to go shallow. All context still arrives via env, so there is no '${{ }}' in the script body and Semgrep's run-shell-injection rule stays satisfied. Validated against three real PRs rather than reasoned about: #638 (this one: test + CI + docs) -> SKIP, correct #636 (4 non-test .go + CHANGELOG.md) -> PASS #627 (2 non-test .go, no changelog) -> FAIL, the PR that prompted all of this The API-failure and empty-result paths still warn and pass: a gate must fail on a known violation, not on its own inability to measure one.
scttfrdmn
added a commit
that referenced
this pull request
Oct 3, 2026
* ci: enforce the changelog policy instead of trusting habit CLAUDE.md requires a CHANGELOG entry under [Unreleased] in the SAME PR as any user-facing change, and the release ritual promotes that section verbatim. Nothing checked either half, and both broke within a week. #627 merged with no entry at all. It surfaced at the next release, which hit an EMPTY [Unreleased] and had to reconstruct the entries from the diff at tag time — precisely when you least want to be reverse-engineering what a change did. Separately, three PRs each inserted their own '### Added' at the top of [Unreleased]. That merges cleanly for git and badly for Keep a Changelog: the section ended up with duplicate '### Added' and '### Fixed' headings, consolidated by hand at release time. Then it happened a second time. Two halves, because they need different things: - changelog_test.go (plain Go test, runs on push and locally): [Unreleased] has no duplicate groups, no unknown group names, no entries outside a group; and every single-version release heading has a compare link. - A CI step (PR-only, since it needs the base branch): a PR that changes non-test Go source must touch CHANGELOG.md. Test-only, CI-only and docs-gen-only changes are exempt — there is nothing user-facing to describe — and the failure message says what to write and why the gate exists. Format checks are scoped to [Unreleased] deliberately. Run over the whole file they report duplicate groups in roughly a dozen SHIPPED releases and two invented group names ('### CI', '### Changed (internal refactors — no behavior change)'). Gating frozen history would force either a mass rewrite of released notes or a permanently red test, and a permanently red test gets disabled — worse than no test. The job is to stop new occurrences in the one section still being edited, which is also the only place the problem creates work. The compare-link check skips range headings like '[0.36.0 – 0.36.13]', which summarise a span and have no single diff to point at; demanding a link there would be a false positive that teaches people to ignore the test. Each check was verified to fail on the real mistake it describes, and CLAUDE.md now says the policy is enforced rather than advisory. * fix(ci): the changelog gate had two bugs of its own 1. Shell injection. '${{ github.base_ref }}' interpolated into a run: block is a script-injection vector, and Semgrep's run-shell-injection rule blocked the PR — correctly. It is now passed via env: and referenced as $BASE_REF, with nothing from the github context in the script body. 2. It would have failed EVERY pull request. 'git diff base...HEAD' needs a merge base, the checkout is shallow, and a depth-1 fetch has no common ancestor — so the step died with 'fatal: origin/main...HEAD: no merge base' (exit 128) before any of the logic ran. Not a false positive: a total block on all work, shipped in CI. Caught on this PR's own first run. Now it deepens the fetch, resolves the merge base explicitly, and diffs from it, so the unresolvable case is detectable rather than fatal. When the merge base cannot be found (long-lived branch, force-pushed base) it WARNS and passes: a gate must fail on a known violation, not on its own inability to measure one. Both paths verified locally — the normal case computes the right file list and verdict, and a disconnected history warns and exits 0. * fix(ci): ask the API what the PR changed, not a shallow clone Third attempt at the presence half, and the first that actually runs. Attempt 1: 'git diff base...HEAD' at fetch depth 1 — died with 'no merge base' (exit 128) before reaching any logic, which would have failed EVERY pull request. Attempt 2: deepen main to 100 commits — still no merge base, because the PR branch is itself fetched at depth 1, so no shared object exists locally. The gate then took its warn-and-skip fail-safe on every run. That is the worse outcome: it reads as enforcement while enforcing nothing, which is exactly the defect #624 fixed in the reaper-coverage check. Attempt 3: 'gh api repos/{repo}/pulls/{n}/files'. GitHub already knows what the PR changed; no history needed, nothing to go shallow. All context still arrives via env, so there is no '${{ }}' in the script body and Semgrep's run-shell-injection rule stays satisfied. Validated against three real PRs rather than reasoned about: #638 (this one: test + CI + docs) -> SKIP, correct #636 (4 non-test .go + CHANGELOG.md) -> PASS #627 (2 non-test .go, no changelog) -> FAIL, the PR that prompted all of this The API-failure and empty-result paths still warn and pass: a gate must fail on a known violation, not on its own inability to measure one.
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.
Refs #625. PR 2 of 2 — the commands. PR #635 (merged) publishes the artifact and fixed the permission set.
What this unblocks
The reaper's normal shape is a Lambda in spore.host's infra account assuming a role in each launching account. That requires the launching account to trust an external principal, which many organizations forbid outright — attempting it in one produced an automated security finding in 12 minutes, and the org's tooling flipped the role's trust policy to Deny. Least privilege didn't help; the objection was the external principal itself.
So those accounts had no backstop at all.
sporedenforces TTL from inside each instance, so nothing reclaimed a stopped instance past its deadline or a filesystem that outlived its instance. One sat stopped for 13 days, still billing EBS. #624 made that detectable; this makes it fixable.Design points worth reviewing
REAPER_DRY_RUN=true; arming is a separate confirmed step. This terminates instances, and one command should not start doing that in an account whose tagging it has never been seen to evaluate. spawn's own reaper was rolled out in dry-run first.cmd/constructs no SDK clients.TestNoNewAWSSDKImportsInCmdcaught my first attempt, which built four clients inline. Writingreaperdeploy.New(cfg)was the right answer to that gate; adding four services to its allowlist would have been the wrong one.spawn-ttl-reaperprefix or Nothing warns when an account has no TTL-reaper coverage, so the 'everything dies eventually' invariant silently doesn't hold #624'sDetectReaperCoveragewon't see it — a working reaper thatdoctorreports as absent is no better than the bug Nothing warns when an account has no TTL-reaper coverage, so the 'everything dies eventually' invariant silently doesn't hold #624 fixed. A test pins it.Verified end to end on the account that actually needs it
FSxScanned: 3withErrors: 0is the specific proof that #635's FSx grants matter — without them that scan is anAccessDenied, and the orphan net silently does nothing. The reap is attributed to the reaper by its own log line rather than inferred, sincesporedalso enforces TTL.Account left exactly as found: no instances, no function, no role, 0 available volumes, and the test artifact bucket removed by hand (teardown deliberately leaves it and says so — emptying someone's S3 bucket is a bigger liberty than this command should take).
Two defects I found in my own code
teardownclaimed to remove a rule that was already gone. EventBridge'sDeleteRuleis idempotent — it returns success for a missing rule — soerr == nilproved nothing, and a second teardown printed- removed rule spawn-ttl-reaper-selfscan-schedule. Found by running teardown twice against real AWS. It now checksDescribeRulefirst. Claiming work that didn't happen is the same defect class as the rest of this session's fixes, just smaller.make checkruns short tests; a 10s sleep per role-creating test is not acceptable. Now injectable; the suite runs in 0.18s.Also
Adding the
eventbridgeSDK to the root module requiredgo mod tidyinlambda/ttl-reaper(owngo.mod+replace ../..), which would otherwise have failed govulncheck CI with "updates to go.mod needed". The three pre-existing untidy lambda modules (alert-handler,autoscale-orchestrator,sweep-orchestrator) are unchanged — they fail on cleanmaintoo.spawn doctor's uncovered message now namesspawn reaper deployas the remedy, anddocs/durable-storage-fsx.mddocuments the self-hosted path.Gates
gofmt·go vet ./...·go build ./...·go test ./...all green ·make check-docsclean withdocs-gen/reaper.mdcommitted ·go mod tidyclean in root andlambda/ttl-reaper·staticcheckzero added (by-message diff).Suggested bump: MINOR (new commands). Note the download-by-version path still can't be exercised until a release carries the asset —
--artifactis how this was tested, and is also the answer for mirrored/air-gapped setups.