Repository navigation
feat(ttl-reaper): DNS reconciliation sweep for orphaned records (#438) - #439
Merged
Merged
Conversation
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.
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.
Fixes #438.
Problem
DNS records outlive their instances when spored's
Cleanup→DeleteDNSnever runs (hard crash, out-of-bandTerminateInstances, fast spot reclaim). The existing #247 teardown deletes a record only while the reaper can still see the instance viaDescribeInstances— 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:managedinstance.base36is 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)
REAPER_DNS_SWEEP=false).REAPER_DRY_RUN— logsWOULD delete orphaned A-record ….route53:List/ChangeResourceRecordSetsscoped to the zone;ec2:DescribeInstancesfor self + assumed cross-account roles) — no new permissions.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 tidyrun for the newpkg/dnstransitive deps).Rollout
Ship with
REAPER_DNS_SWEEP=trueandREAPER_DRY_RUN=truefirst to log what it would delete, verify against known-stale records (e.g. thegatetest/tstestleaks in the issue), then flip dry-run off.