Skip to content

feat(reaper): make failures observable and alarmable (#469) - #471

Merged
scttfrdmn merged 1 commit into
mainfrom
feat/reaper-failure-observability
Jul 31, 2026
Merged

scttfrdmn merged 1 commit into
mainfrom
feat/reaper-failure-observability

Conversation

@scttfrdmn

Copy link
Copy Markdown
Contributor

Closes #469. Addresses #457 failure mode A and #254 idea 3.

Why #469's original framing was wrong

#469 was filed as "a dead account's assume-role failures poison sum.Errors forever" — 11 regions × 6 runs/hour = 66 errors/hour per dead account. Planning that fix showed the framing was wrong, and the incremental fix would have made the reaper calmer without making it safer.

sum.Errors drives nothing. Verified before writing any code:

  • handler ended return sum, nil — always nil, so the Lambda Errors metric never moved however many scans failed.
  • Summary went to one log line and was returned to EventBridge. Nothing read it.
  • notify/notifyFSx fire only on successful reaps. No failure path notified.
  • No metric filter and no alarm existed on the reaper anywhere — not in this repo (zero AWS::CloudWatch::Alarm in all of spawn), not in spore-host's OpenTofu. portal-account-prober has two.
  • The reaper classified zero AWS error codes, so a permanent AccessDenied and a transient throttle were literally the same event.

So the noise was a symptom. The disease: the reaper's entire failure path was unobserved. Errors is the only field in Summary that says a scan did not happen — every other field counts something that did — and it was pinned permanently nonzero by any single uninstalled account. An instance running past its deadline in a region whose scan is failing looked exactly like a clean run, which is the blindness #65 created the reaper to prevent, one layer up.

What changed

Classification (failures.go, pure + table-tested): AccessDenied / AccessDeniedException / UnauthorizedOperation → failureDenied; everything else → failureOperational. Error-code set reused verbatim from portal-account-prober's isDenied rather than re-derived — two copies of a security-relevant code list drift. Unknown errors default to operational, the class that stays loud.

Per-account aggregation. Credentials are per account, so the same role either works everywhere or is refused everywhere — eleven identical denials are one observation:

Field Counts
Errors operational failures only — the "investigate this" meaning restored
AccountsDenied accounts refused in every region — 1 per account, not 11
FSxAccountsDenied accounts refusing every FSx call

FSx is separate because fsx:* is a different grant from ec2:*: an account can scan instances perfectly and never reclaim a filesystem. That is #212 exactly — an FSx AccessDenied that presented as a silent no-op. Sharing one signal would let the EC2 success mask it again, so the FSx sentinel fires even when the instance scan succeeded, and says so.

Four alarms in this function's own template.yaml (ALARMS_ENABLED, default on; optional ALARM_TOPIC_ARN):

Sentinel Alarm Window
REAPER REACHED NO ACCOUNTS reached-no-accounts 2×1h
REAPER ACCOUNT UNREACHABLE account-unreachable 1×24h
REAPER FSX UNREACHABLE fsx-unreachable 1×24h
(AWS/Lambda Errors) invocation-errors 1×1h

That last one because a run that dies before finishing emits none of the sentinels — without it the loudest failure would be the quietest signal. Alarms live here rather than in spore-host's OpenTofu (where the prober's live) so the alarm and the log line it matches ship in the same repo and the same make deploy; splitting them is how #254's class of drift starts.

The zero-accounts alarm text points at our side first. The reaper's role ARN embeds a CFN-generated physical ID, so recreating the stack breaks every customer's trust policy simultaneously (#457 trap 1) — indistinguishable, from the inside, from the entire customer base uninstalling at once. An operator who reads that line and starts emailing customers has been actively misled.

Safety

  • Nothing is deleted or terminated. This only classifies and reports, which is why it needs no opt-in flag — unlike Wire DNSExpiryEligible into the reaper: the prober can now prove what the unmanaged-subdomain report refused to guess #466, where being wrong deletes a live spore's DNS that never self-heals. Here, being wrong means an over-deadline instance goes unreaped and unnoticed, so the change can only make that more visible.
  • A denied account is still attempted every run, in every region — asserted twice over (#457 trap 1). Quiescing means not counting it as a surprise, never ceasing to look.
  • The registry is corroboration only and structurally cannot gate anything: the closure returns a string for a log line. It describes spore-portal-onboard (trusts phone-home), not the spawn-ttl-reaper-ec2 role that just refused us — either can be healthy while the other is broken, so it's a second opinion about a different door. Read at most once per run, and not at all when nothing was denied.
  • No IAM changes. No new permissions of any kind.
  • handler still returns nil — making it error would mark runs failed that did real work and change EventBridge retry behaviour.

Verification

gofmt · go vet · 76 tests pass · cfn-lint 0 · sam validate --lint 0 · make build · govulncheck 0 · trivy fs 0 · trivy config 0 · semgrep 0 findings across 11 files (new files staged first — semgrep only scans git-tracked).

Mutation testing: 17 killed, 1 confirmed equivalent. The first pass found four survivors that mattered more than any of the kills: with concrete *ec2.Client/*fsx.Client in account, deleting the reportOutcomes call entirely, dropping the per-region outcome.record, removing the FSx denial re-route, or having handler stop delegating all left every test passing. A change whose whole purpose is "notice when the reaper is broken" must not itself be undetectable when broken — so ec2For/fsxFor became interfaces and handler delegates to (*reaper).run, letting the failure paths be driven end to end. All four now die.

One survivor is a genuine equivalence, verified not assumed: recording FSx reachability on every page vs. only the first is indistinguishable when the fakes return a single page, since fsxDeniedEverywhere() requires fsxReached == 0 either way. It's a defensive guard against misreading a page-3 failure as a missing grant, not observable behaviour.

Also caught by mutation: reading rows[accountID] without an explicit presence check would have printed "the registry says this account is active" about an account the registry has never heard of — AccountStatus() maps a legacy "" to "active".

Deliberately out of scope

The reaper exists because #65 showed a dead spored monitor loop lets
instances run forever. That guarantee was only as good as our ability to
notice when the REAPER was the thing that had died — and it was not
noticeable at all:

  - handler always returned nil, so the Lambda Errors metric never moved
    however many scans failed
  - Summary went to one log line nothing read
  - the Slack webhook fires only on SUCCESSFUL reaps
  - no metric filter and no alarm existed on this function in either repo

A run whose every scan was refused looked exactly like a run with nothing
expired.

#469 was filed as "a dead account's assume-role failures poison sum.Errors
forever" (11 regions × 6 runs/hour = 66/hour). Exploring it showed the
framing was wrong: sum.Errors drives nothing, so quietening it would have
made the reaper calmer without making it safer. The noise was a symptom of
there being nothing listening.

Errors is the only field in Summary that says a scan did NOT happen; every
other field counts something that did. Failures are now classified
(AccessDenied/AccessDeniedException/UnauthorizedOperation vs everything
else, reusing portal-account-prober's isDenied code set) and aggregated per
ACCOUNT — credentials are per account, so eleven identical denials are one
observation. Errors keeps its "investigate this" meaning for operational
failures only; AccountsDenied and FSxAccountsDenied carry the standing
configuration facts.

FSx is tracked separately because fsx:* is a different grant from ec2:*: an
account can scan instances perfectly and never reclaim a filesystem, which
is #212 exactly. Sharing one signal would let the EC2 success mask it again.

Three sentinel log lines exist so they can be alarmed on, with four alarms
in the reaper's own template.yaml (ALARMS_ENABLED, default on; optional
ALARM_TOPIC_ARN): zero accounts reached, an account refused everywhere, FSx
refused everywhere, and the Lambda erroring outright — that last because a
run that dies never reaches the code emitting the others, so without it the
loudest failure would be the quietest signal. The zero-accounts text points
at OUR side first: the reaper's role ARN embeds a CFN-generated physical ID,
so recreating the stack breaks every customer's trust policy at once (#457),
indistinguishable from the whole customer base uninstalling simultaneously.

A denied account is still attempted every run — quiescing means not counting
it as a surprise, never ceasing to look. The registry annotates a denial as
corroboration only: it describes spore-portal-onboard, not the
spawn-ttl-reaper-ec2 role that refused us, so it can never gate anything.
It is read at most once per run and not at all when nothing was denied.

ec2For/fsxFor became interfaces and handler delegates to (*reaper).run so
the failure paths can be driven in tests. Mutation testing is why: with
concrete clients, deleting the reportOutcomes call, the per-region
outcome.record, the FSx denial re-route, or handler's delegation entirely
left every test passing. A failure-observability change that cannot itself
be observed failing is the one unacceptable outcome. 17 mutants killed, one
confirmed equivalent (single-page FSx fakes cannot distinguish the
first-page guard).

Nothing here deletes or terminates; it only classifies and reports.

Closes #469. Addresses #457 failure mode A and #254 idea 3.
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.

ttl-reaper: a dead account's assume-role failures poison sum.Errors forever (#457 failure mode A)

1 participant