Skip to content

feat(ttl-reaper): expire unmanaged subdomain DNS on the portal registry's verdict (#466) - #468

Merged
scttfrdmn merged 1 commit into
mainfrom
feat/reaper-dns-expiry
Jul 31, 2026
Merged

scttfrdmn merged 1 commit into
mainfrom
feat/reaper-dns-expiry

Conversation

@scttfrdmn

Copy link
Copy Markdown
Contributor

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:

we cannot tell the two apart precisely because we lack the credentials

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. DescribeInstances is how emptiness is proven, and the reaper has no credentials for an account outside its role list.

The portal's account-prober supplies exactly that proof. It holds spore-portal-onboard — a different role from the reaper's spawn-ttl-reaper-ec2, and one the registry actually knows about — and probes every region, writing the result to spore-portal-accounts. So for an account in the registry, the ambiguity is resolvable.

The verdict

accountlifecycle.DNSExpiryEligible is the single gate; the reaper deliberately does not re-implement the status logic:

Registry status Eligible Why
dormant yes reachable and provably empty for N days — emptiness established through a working role
offboarded yes 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. Needs a human, not a longer wait
absent / unreadable no the prober has no opinion, so the original #458 ambiguity stands in full

The 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

  • `authorizeExpiry(verdict, registryOK, expireDNS) -> action` is pure, 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. Matches the `orphanedRecords`/`sweepableRecord` style the issue asked for.
  • `registryOK` is an input rather than folded into the verdict: an unreadable registry produces the same "not in the registry" verdict as a genuinely unregistered account. Both refuse, but conflating them would hide the difference from the log.
  • A new `route53API` interface seam covers the other half. A pure decision function proves what the reaper decides; only a fake proves what it actually sends to Route53 — and for a record whose loss never self-heals, that distinction is worth the interface.

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

  1. `make build` named `main.go` instead of the package. Naming files builds only those files. This PR's second source file made it fail outright — but a file that wasn't referenced would have shipped a binary silently missing its code.
  2. The new template parameters are threaded through `make deploy`. `sam deploy` marks any parameter it isn't given as `UsePreviousValue`, so an omitted one is unreachable from the Makefile — the same omission that (per the Makefile's own comment) once made DNS records leak when spored doesn't exit through Cleanup (abrupt terminate/spot/crash) — no backstop reaper #438 impossible to enable via `make deploy`.

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

  • `go mod tidy` cannot run in this module: `accountlifecycle`'s `registry_test.go` imports substrate's root package, and tidy resolves a dependency's test deps at `@latest`, where that package no longer exists (v0.76.0). Upstream, not introduced here — the prober's tidy only succeeds because it has a local `replace`. No CI job gates `tidy` (CI runs `go build ./... && go vet ./... && go test -short ./...` per module). The `accountlifecycle` require was moved from the indirect block to direct by hand.
  • `Offboard` still has no caller anywhere; wiring the human-initiated path is separate work. `DNSExpiryEligible` already returns true for it.
  • Deploying this needs the prober's tofu module applied first, so the registry has rows to read.

@scttfrdmn
scttfrdmn force-pushed the feat/reaper-dns-expiry branch from 2378afa to 8723578 Compare July 31, 2026 13:58
…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
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.

Wire DNSExpiryEligible into the reaper: the prober can now prove what the unmanaged-subdomain report refused to guess

1 participant