Repository navigation
feat(ttl-reaper): expire unmanaged subdomain DNS on the portal registry's verdict (#466) - #468
Merged
Merged
Conversation
scttfrdmn
force-pushed
the
feat/reaper-dns-expiry
branch
from
July 31, 2026 13:58
2378afa to
8723578
Compare
…466) The #457 unmanaged-subdomain report deliberately deleted nothing, and said why: an unmanaged subdomain is ambiguous — an account that uninstalled and left records behind, or a live account someone forgot to add to REAPER_ROLE_ARNS — and the two are indistinguishable *precisely because we lack the credentials*, since DescribeInstances is how emptiness is proven. The portal's account-prober supplies exactly that proof. It holds a role the registry knows about (spore-portal-onboard — a different role from the reaper's spawn-ttl-reaper-ec2) and probes every region, writing the result to spore-portal-accounts. So for an account in the registry the ambiguity is now resolvable, and accountlifecycle.DNSExpiryEligible is the verdict: dormant -> eligible (reachable AND provably empty for N days) offboarded -> eligible (a human stated the intent) active -> no (the account is in use) unreachable -> no (#457 trap 2: the role we would verify through is gone, so emptiness can no longer be proven — that needs a human, not a longer wait) absent / unreadable -> no (the prober has no opinion; the original #458 ambiguity stands in full) The verdict is ALWAYS logged. Acting on it needs a new default-off REAPER_DNS_EXPIRE on top of the sweep's existing opt-in. Two switches rather than one because REAPER_DNS_SWEEP is already enabled in production: folding expiry into it would make an existing flag silently destructive on upgrade, for a class of records it has never touched. What has NOT changed is the cost of being wrong. spored registers DNS once, at boot (pkg/agent/agent.go) with no periodic re-registration, so a wrongly deleted A-record never self-heals — the spore keeps running and is simply unreachable by name until it reboots. Hence: expiry deletes only A-records, never the #121 friendly CNAMEs (a dangling CNAME resolves to nothing, whereas a stale A-record eventually resolves to a stranger's box once the IP recycles). The decision that authorizes a deletion is a pure function (authorizeExpiry), so the full truth table — every combination of verdict and configuration that could delete a live spore's DNS — is tested in one place with no AWS. A route53API seam covers the other half: a pure test proves what the reaper decides, only a fake proves what it actually sends. IAM is read-only by construction: dynamodb:Scan on the registry table and kms:Decrypt on its CMK, never UpdateItem/PutItem/DeleteItem and never GenerateDataKey. The prober owns every write, and the reaper being unable to write the table is what makes it impossible for a reaper bug to manufacture the eligibility it then acts on. New summary fields: DNSExpiryEligible / DNSExpiryIneligible (verdicts) and DNSExpiredRecords. Eligible-but-not-Expired is the normal, healthy reading — it means the verdict exists and the flag is off. Also fixes `make build`, which named main.go instead of the package and so would have shipped a binary silently missing expiry.go had it not been referenced. And threads the new template parameters through `make deploy`, which sam otherwise marks UsePreviousValue — the same omission that once made Refs #457, #458, #466
scttfrdmn
force-pushed
the
feat/reaper-dns-expiry
branch
from
July 31, 2026 14:02
8723578 to
39150c6
Compare
This was referenced Jul 31, 2026
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 #466. Builds directly on #457 (the unmanaged-subdomain report) and #458 (why that report deleted nothing).
The blocker this removes
#458 declined to delete, and named its own blocker precisely:
An unmanaged subdomain is ambiguous — an account that uninstalled and left records behind, or a live account someone forgot to add to
REAPER_ROLE_ARNS.DescribeInstancesis how emptiness is proven, and the reaper has no credentials for an account outside its role list.The portal's
account-probersupplies exactly that proof. It holdsspore-portal-onboard— a different role from the reaper'sspawn-ttl-reaper-ec2, and one the registry actually knows about — and probes every region, writing the result tospore-portal-accounts. So for an account in the registry, the ambiguity is resolvable.The verdict
accountlifecycle.DNSExpiryEligibleis the single gate; the reaper deliberately does not re-implement the status logic:dormantoffboardedactiveunreachableThe verdict is always logged, on every unmanaged subdomain, whether or not deletion is enabled. Reading that report is how an operator decides whether enabling expiry is safe.
Two switches, not one
Deletion needs a new, default-off `REAPER_DNS_EXPIRE` on top of the existing `REAPER_DNS_SWEEP` (plus `REAPER_DRY_RUN` as always).
Separate because `REAPER_DNS_SWEEP` is already enabled in production — folding expiry into it would make an existing flag silently destructive on upgrade, for a class of records it has never touched.
What has not changed: the cost of being wrong
`spored` registers DNS once, at boot (`pkg/agent/agent.go` → `dnsClient.RegisterDNS`). There is no periodic re-registration, so a wrongly deleted A-record never self-heals — the spore keeps running and is simply unreachable by name until it reboots. That asymmetry is the entire justification for the second opt-in.
Consequently expiry deletes only A-records, never the #121 friendly CNAMEs: a dangling CNAME resolves to nothing, whereas a stale A-record eventually resolves to a stranger's box once the IP recycles.
Design
IAM: read-only by construction
`dynamodb:Scan` on the registry table and `kms:Decrypt` on its CMK. Never `UpdateItem`/`PutItem`/`DeleteItem`, never `GenerateDataKey` (only writes need it). The prober owns every write, and the reaper being unable to write the table is what makes it impossible for a reaper bug to manufacture the eligibility it then acts on.
Both policies are conditional — attached only when a zone, a domain, and the sweep are all configured.
Summary fields
`DNSExpiryEligible` / `DNSExpiryIneligible` (verdicts) and `DNSExpiredRecords` (deleted, or would-delete under dry-run). Eligible-but-not-Expired is the normal, healthy reading — it means the verdict exists and the flag is off. `DNSExpiredRecords` is named apart from the instance-level `Expired`.
Two adjacent bugs fixed
Verification
```
gofmt -l . clean
go vet ./... clean
go test -count=1 -short ./... ok (46.5% stmts)
cfn-lint template.yaml exit 0
make build bootstrap + function.zip, linux/arm64
trivy fs (vuln,secret H/C) exit 0 — 0 vulns, 0 secrets
trivy config exit 0 — 0 misconfigurations
govulncheck ./... exit 0 — 0 reachable
semgrep --config=auto --error exit 0 — 165 rules, 9 files, 0 findings
```
Tests cover every case the issue's checklist named: eligible-and-flag-off deletes nothing; registry-`Scan`-error deletes nothing; account absent from the registry deletes nothing; `unreachable` deletes nothing; `dormant` + flag + not-dry-run deletes exactly that subdomain's A-records and no CNAMEs. Plus nil/empty registry, dry-run, zone-list-error, and a fixture-integrity test asserting the base36 labels decode to the account IDs they claim (fixture drift would otherwise silently weaken every test — it did once, during development).
Mutation-tested: 10 mutants, 9 killed. Two survivors were log-only differences — but in report/dry-run mode the log is the deliverable, so both got tests and are now killed. The tenth ("zone-list error does not abort") is genuinely behaviourally equivalent: the subsequent loop has nothing to iterate.
Notes for review