Repository navigation
fix(reaper): make the max-age ceiling apply inside a live deadline, as its own docs say (#76) - #824
Conversation
…s its own docs say (#76) The reaper's header has always described the ceiling as firing even for --no-timeout / missing / far-future deadlines — defense against escape hatches and tag tampering but the code returned early for ANY instance inside its spawn:ttl-deadline, and the template's MaxAge Description mentioned only missing deadlines. Three documents, two intents, and the code implemented the narrow one. ## Why the exemption defeated a security control spawn:ttl-deadline is writable FROM the instance: the instance role grants ec2:CreateTags conditioned on ec2:ResourceTag/spawn:managed=true, a condition the instance itself satisfies (the #174 fix stopped a spore tagging FOREIGN instances, not its own). So a spore could write a deadline decades out and become permanently unreapable — and forge spawn:last-heartbeat to keep SporedQuietAlarm silent while doing it, since that alarm derives from the same instance-written tag. #76 tracks signing the tag, which is the real fix. This makes the ceiling a genuine bound in the meantime: worst case REAPER_MAX_AGE, not forever. ## I nearly shipped this as a one-liner, and it would have been a bug Removing the early return alone caps every TTL at the ceiling — default 168h — and there is no cap on --ttl anywhere in the CLI. A user asking for --ttl 14d would have been terminated at 7 days with no warning. That is the same silent-surprise class this audit exists to remove. So: `spawn launch` now warns when --ttl exceeds the default ceiling, naming the threshold and saying to raise REAPER_MAX_AGE for genuinely longer-lived instances. Closing the hole must not open a new one. ## Three gates, each verified against a compiling revert restore the early return -> TestEvaluate_MaxAgeCeilingAppliesEven WithinDeadline fails narrow the description -> TestReaperDocsAgreeThatTheCeilingBeats AFarFutureDeadline fails drift the CLI's constant -> TestDefaultReaperMaxAgeMatchesTheReaper fails ("the CLI would warn at the wrong threshold") The constant gate reads BOTH the reaper's Go default and its CloudFormation parameter default, because the deployed value is the one that matters and the Go constant only applies when the env var is unset. pkg/ttl and the reaper are separate modules so the value must be duplicated; an uncompared duplicate is the #790 defect. The doc gate checks for the single word carrying the scope rather than matching sentences — asserting on prose is normally a poor gate, but the two documents drifting apart is precisely how this survived. ## A test that asserted the old behaviour, replaced not deleted TestEvaluate_WithinDeadline_Spared used a 30-day-old instance with a 2-hour-future deadline and asserted it was spared. It was right about the code and wrong about the design — and it is why the gap lasted, because a test that encodes observed behaviour cannot tell you the behaviour is wrong. Now two tests: within-deadline-and-within-ceiling still spared, and the forged far-future case reaped with reason "max-age". make check green across all 9 nested modules, check-docs, changelog, semgrep 0 findings, Tier 0 e2e with -count=1 (68s).
…d behaviour A test written by reading the code can only ever confirm the code. If the behaviour is wrong, that test certifies it and makes the bug permanent, because it will fail on the fix. This change is the worked example, which is why the rule lands on this branch rather than separately: TestEvaluate_WithinDeadline_Spared asserted that a 30-day-old instance with a 2-hour-future deadline was spared. That is exactly what the code did, and not what the reaper's header says it does. The exemption it blessed let a spore write its own far-future deadline and become permanently unreapable. The rule: write the assertion from the comment, the parameter description or the issue — then run it. If it fails you have found either a bug or a stale document, and you must resolve WHICH before writing the test down. Codifying whichever you read first is how three documents end up disagreeing. When two sources of intent conflict, gate their agreement too, because the drift is the root cause and the behaviour is the symptom. ## Why it is on this branch I first committed it on a branch off main, then checked the claims — and the rule cited tests that exist only here. Merging that would have been a docs-vs-code contradiction in the paragraph telling people not to create docs-vs-code contradictions. All four claims re-verified against this branch: the header phrase, both replacement tests, the doc-agreement gate, and the absence of the old test name. changelog + check-docs green; the public-package doc gate still passes.
|
Pushed It belongs on this branch rather than in a separate PR because this change is I initially committed the rule on a branch off Rule 5 — assert the documented intent, not the behaviour you observed. A test The guidance is to write the assertion from the comment, the parameter That last clause is why |
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
…arse (#1524) The log line sat after the parse block instead of in its else, so every instance with a valid future deadline (which falls through to the max-age ceiling since #824) logged it on every cycle. Decisions are unchanged. Co-Authored-By: Claude <[email protected]>
…arse (#1524) (#1545) The log line sat after the parse block instead of in its else, so every instance with a valid future deadline (which falls through to the max-age ceiling since #824) logged it on every cycle. Decisions are unchanged. Co-authored-by: Claude <[email protected]>
Refs #76 — this does not close it. #76 is the signed authenticity tag, which
is the real fix. This makes the ceiling a genuine bound in the meantime.
The reaper's header has always described the ceiling as firing
but the code returned early for any instance inside its
spawn:ttl-deadline, andtemplate.yaml'sMaxAgedescription mentioned onlymissing deadlines. Three documents, two intents, and the code implemented the
narrow one.
Why the exemption defeated a security control
spawn:ttl-deadlineis writable from the instance: the instance role grantsec2:CreateTagsconditioned onec2:ResourceTag/spawn:managed=true, a conditionthe instance itself satisfies. The #174 fix stopped a spore tagging foreign
instances, not its own.
So a spore could write a deadline decades out and become permanently unreapable —
and forge
spawn:last-heartbeatto keepSporedQuietAlarmsilent while doing it,since that alarm derives from the same instance-written tag. Worst case is now
REAPER_MAX_AGE, not forever.I nearly shipped this as a one-liner, and it would have been a bug
Removing the early return alone caps every TTL at the ceiling — default
168h— and there is no cap on--ttlanywhere in the CLI. A user asking for--ttl 14dwould have been terminated at 7 days with no warning. That is thesame silent-surprise class this audit exists to remove.
So
spawn launchnow warns when--ttlexceeds the default ceiling, naming thethreshold and saying to raise
REAPER_MAX_AGEfor genuinely longer-livedinstances. Closing one hole must not open another.
Three gates, each verified against a compiling revert
TestEvaluate_MaxAgeCeilingAppliesEvenWithinDeadlineTestReaperDocsAgreeThatTheCeilingBeatsAFarFutureDeadlineTestDefaultReaperMaxAgeMatchesTheReaper— "the CLI would warn at the wrong threshold"The constant gate reads both the reaper's Go default and its CloudFormation
parameter default, because the deployed value is the one that matters and the Go
constant only applies when the env var is unset.
pkg/ttland the reaper areseparate modules, so the value must be duplicated — and an uncompared duplicate
is the #790 defect.
The doc gate checks the single word carrying the scope rather than matching
sentences. Asserting on prose is normally a poor gate, but these two documents
drifting apart is precisely how this survived.
A test that asserted the old behaviour — replaced, not deleted
TestEvaluate_WithinDeadline_Sparedused a 30-day-old instance with atwo-hour-future deadline and asserted it was spared. It was right about the
code and wrong about the design — and it is why the gap lasted, because a test
that encodes observed behaviour cannot tell you the behaviour is wrong.
Now two tests: within-deadline-and-within-ceiling is still spared, and the forged
far-future case is reaped with reason
max-age.Verification
make checkgreen across all 9 nested modules,check-docs, the changelog gate,semgrep(0 findings), and the full Tier 0 e2e with-count=1(68s).Deployment note
This changes reaper behaviour, so it needs a deploy to take effect — and the
reaper stack's parameters must be read from the live stack first, per the #650
trap where an omitted
--parameter-overridesresetDryRunto its templatedefault and disarmed production.