Skip to content

fix(reaper): make the max-age ceiling apply inside a live deadline, as its own docs say (#76) - #824

Merged
scttfrdmn merged 2 commits into
mainfrom
fix/76-maxage-ceiling
Oct 11, 2026
Merged

scttfrdmn merged 2 commits into
mainfrom
fix/76-maxage-ceiling

Conversation

@scttfrdmn

Copy link
Copy Markdown
Contributor

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

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 template.yaml'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. 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 --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 one hole must not open another.

Three gates, each verified against a compiling revert

revert gate that fails
restore the early return TestEvaluate_MaxAgeCeilingAppliesEvenWithinDeadline
narrow the parameter description TestReaperDocsAgreeThatTheCeilingBeatsAFarFutureDeadline
drift the CLI's ceiling constant TestDefaultReaperMaxAgeMatchesTheReaper — "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 — 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_Spared used a 30-day-old instance with a
two-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 check green 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-overrides reset DryRun to its template
default and disarmed production.

…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).
@scttfrdmn scttfrdmn added this to the Security audit 2026-10 milestone Oct 11, 2026
…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.
@scttfrdmn

Copy link
Copy Markdown
Contributor Author

Pushed 869ff76, adding gate rule 5 to CLAUDE.md.

It belongs on this branch rather than in a separate PR because this change is
its worked example — and because I got that wrong first and the check caught it.

I initially committed the rule on a branch off main, then verified its claims
and found it cited pkg/ttl/ceiling_test.go and both replacement tests, none of
which exist on main yet. Merging that would have been a docs-vs-code
contradiction inside the paragraph telling people not to create docs-vs-code
contradictions. Moved it here; all four claims re-verified against this branch.

Rule 5 — assert the documented intent, not the behaviour you observed. A test
written by reading the code can only confirm the code. If the behaviour is wrong,
the test certifies it and makes the bug permanent, because it will fail on the
fix.

The guidance is to write the assertion from the comment, the parameter
description or the issue, then run it — and if it fails, resolve which is wrong
before writing anything down. Codifying whichever you read first is how three
documents end up disagreeing with each other. Where two sources of intent
conflict, gate their agreement too, because the drift is the root cause and the
behaviour is only the symptom.

That last clause is why TestReaperDocsAgreeThatTheCeilingBeatsAFarFutureDeadline
is in this PR at all: fixing the behaviour without gating the agreement would
have left the next edit free to drift the two apart again.

@codecov

codecov Bot commented Oct 11, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 80.00000% with 3 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
cmd/launch_config.go 0.00% 3 Missing ⚠️

📢 Thoughts on this report? Let us know!

@scttfrdmn
scttfrdmn merged commit e167ed4 into main Oct 11, 2026
7 checks passed
@scttfrdmn
scttfrdmn deleted the fix/76-maxage-ceiling branch October 11, 2026 06:02
scttfrdmn added a commit that referenced this pull request Nov 6, 2026
…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]>
scttfrdmn added a commit that referenced this pull request Nov 6, 2026
…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]>
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