Repository navigation
feat(reaper): make failures observable and alarmable (#469) - #471
Merged
Merged
Conversation
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.
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.
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.Errorsforever" — 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.Errorsdrives nothing. Verified before writing any code:handlerendedreturn sum, nil— always nil, so the LambdaErrorsmetric never moved however many scans failed.Summarywent to one log line and was returned to EventBridge. Nothing read it.notify/notifyFSxfire only on successful reaps. No failure path notified.AWS::CloudWatch::Alarmin all of spawn), not in spore-host's OpenTofu.portal-account-proberhas two.AccessDeniedand a transient throttle were literally the same event.So the noise was a symptom. The disease: the reaper's entire failure path was unobserved.
Errorsis the only field inSummarythat 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 fromportal-account-prober'sisDeniedrather 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:
ErrorsAccountsDeniedFSxAccountsDeniedFSx is separate because
fsx:*is a different grant fromec2:*: an account can scan instances perfectly and never reclaim a filesystem. That is #212 exactly — an FSxAccessDeniedthat 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; optionalALARM_TOPIC_ARN):REAPER REACHED NO ACCOUNTSREAPER ACCOUNT UNREACHABLEREAPER FSX UNREACHABLEAWS/LambdaErrors)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
spore-portal-onboard(trusts phone-home), not thespawn-ttl-reaper-ec2role 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.handlerstill returnsnil— making it error would mark runs failed that did real work and change EventBridge retry behaviour.Verification
gofmt·go vet· 76 tests pass ·cfn-lint0 ·sam validate --lint0 ·make build·govulncheck0 ·trivy fs0 ·trivy config0 ·semgrep0 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.Clientinaccount, deleting thereportOutcomescall entirely, dropping the per-regionoutcome.record, removing the FSx denial re-route, or havinghandlerstop 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 — soec2For/fsxForbecame interfaces andhandlerdelegates 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()requiresfsxReached == 0either 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
make deployis the maintainer's call;ALARM_TOPIC_ARNis the one new decision (an alarm with no topic is visible but pages no one).