Skip to content

feat(ttl-reaper): DNS reconciliation sweep for orphaned records (#438) - #439

Merged
scttfrdmn merged 1 commit into
mainfrom
feat/438-dns-reconciliation-sweep
Jul 23, 2026
Merged

scttfrdmn merged 1 commit into
mainfrom
feat/438-dns-reconciliation-sweep

Conversation

@scttfrdmn

Copy link
Copy Markdown
Contributor

Fixes #438.

Problem

DNS records outlive their instances when spored's Cleanup→DeleteDNS never runs (hard crash, out-of-band TerminateInstances, fast spot reclaim). The existing #247 teardown deletes a record only while the reaper can still see the instance via DescribeInstances — once it's terminated and aged out of the EC2 API (~1h), the record is orphaned with nothing to key off. It resolves forever to a dead (or later reassigned) public IP — a correctness + mild security issue.

(Per my analysis on the issue: the report's "Cleanup isn't wired to SIGTERM" was inaccurate — it is wired; and a DNS reaper partially exists via #247. The real gap is the record-driven reconciliation below.)

Fix — opt-in reconciliation sweep

REAPER_DNS_SWEEP=true (with a zone configured): after scanning an account's regions, list its {base36}.{domain} A-records and delete any whose IP has no live (running/pending) spawn:managed instance. base36 is derived from the account ID (pkg/dns.EncodeAccountID), so an account with a stale record and zero instances is still reconciled — the inverse enumeration the instance-driven path can't do.

Safety (destructive infra code — conservative by design)

Tests

orphanedRecords (the pure reconciliation core) is unit-tested: live IP → spared, no live owner → orphan, empty-live-set → all orphaned, nil → none. Full reaper suite passes; lambda builds (go mod tidy run for the new pkg/dns transitive deps).

Rollout

Ship with REAPER_DNS_SWEEP=true and REAPER_DRY_RUN=true first to log what it would delete, verify against known-stale records (e.g. the gatetest/tstest leaks in the issue), then flip dry-run off.

The #247 teardown only deletes a DNS record while the reaper still SEES
the instance via DescribeInstances. A record whose instance exited
abruptly (hard crash, out-of-band TerminateInstances, fast spot reclaim)
and has since aged out of the EC2 API is orphaned — it resolves forever
to a dead or later-reassigned IP (a mild security concern).

Add an opt-in record-driven sweep (REAPER_DNS_SWEEP=true): per account,
list {base36}.{domain} A-records and delete any whose IP has no live
(running/pending) spawn:managed instance. base36 is derived from the
account ID (via pkg/dns.EncodeAccountID), so an account with a stale
record and zero instances is still reconciled.

Safety: opt-in + default off; honors REAPER_DRY_RUN; aborts without
deleting if any region's live-IP scan errors (never delete against a
partial live set); only plain A-records under the account subdomain
(skips the apex and Route53 alias records). Reuses the existing
Route53 + DescribeInstances IAM already granted for #247/scan.

Pure orphanedRecords core unit-tested; template param + README + CHANGELOG.
@scttfrdmn
scttfrdmn merged commit 8c0a014 into main Jul 23, 2026
7 checks passed
@scttfrdmn
scttfrdmn deleted the feat/438-dns-reconciliation-sweep branch July 23, 2026 19:03
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.

DNS records leak when spored doesn't exit through Cleanup (abrupt terminate/spot/crash) — no backstop reaper

1 participant