Repository navigation
DNS leases: expire abandoned records without credentials in the owning account - #875
Merged
Merged
Conversation
…g account Every backstop for a stale A-record asked about the instance behind it: the DNS sweep (#438) calls DescribeInstances in the owning account and DNS expiry (#466) relies on the portal prober assuming a role there. For an account the reaper does not cover — one spore.host must never hold credentials in, or any governed org — a record left by an abruptly terminated instance pointed at its IP indefinitely, under a spore.host name, after AWS reassigned that IP. A self-hosted reaper (#625) cannot help: it cannot touch spore.host's zone. A lease asks the owner instead. spored re-registers ~hourly (jittered) through the same path as its boot registration; the DNS updater stamps a _spore-lease.<record> TXT in the same Route53 batch as the A-record, only under the SigV4-verified caller's namespace; the reaper reports leases unrenewed for six hours and, with REAPER_DNS_LEASE_EXPIRE=true, expires them — for account subdomains it does NOT cover. Safety, each gated against a compiling revert: leasing is opt-in per client and only spored's agent opts in (`spawn dns register` shares the client and must not); a request with no lease field gets none, through the real handler; a non-renewing re-registration clears an inherited lease; covered accounts are never expired by lease; unparseable leases are never acted on; future-dated leases read fresh; the reaper re-reads before deleting so a mid-run renewal wins; DnsLeaseExpire arrives off and is live-wins. Also corrects expiry.go's claim that spored registers once and never re-registers, which is no longer true of renewing clients.
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
This was referenced Oct 12, 2026
Merged
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.
The gap
A spore in an account the TTL reaper doesn't cover registered
loop-l12-esc.c0zxr0ao.spore.hosttoday. If that instance dies without running spored's cleanup — console terminate, spot reclaim, crash — nothing on the spore.host side ever removes the record. It keeps pointing at the IP after AWS hands that IP to someone else, under a spore.host name.Every existing backstop asks about the instance, so every one needs credentials in the owning account:
DescribeInstancesin the owning accountFor an account spore.host must never hold credentials in — and for any governed org that won't grant an external principal access — none of them can run.
The fix: ask the owner, not the instance
A lease. The record's owner keeps asserting it is alive; when it stops, the zone alone says the record is abandoned.
registerDNSmethod shared with boot, so renewal can't drift into a different request.spawn:dns-statusis re-tagged only on change, not hourly._spore-lease.<record>TXT in the same Route53 batch as the A-record (atomic), only under the SigV4-verified caller's namespace ([HIGH] dns-updater accepts unsigned identity docs + default-allows cross-account → Route53 spoofing #173) — nobody can renew someone else's record. Removed on DELETE.No new infrastructure and no IAM change: the reaper's Route53 grant is zone-scoped with no record-type condition (checked), and the updater already writes TXT for
_spore-owner.Safety — each property gated against a revert that compiles
Leasing is opt-in per client, and only spored opts in. This was the hazard found while building it:
spawn dns registeris a one-shot caller of the samepkg/dnsclient. Had the client always requested a lease, every record it registers would be expired 6h later under a live instance.TestOnlyARenewingCallerMayRequestALeaseparses every non-test Go file and fails if anything but spored's agent callsSetRenewing(true)— or if the agent does without callingrefreshDNSLease. External consumers checked against local clones with a working control: none call it.Today's clients are unaffected, proven through the real handler on the Substrate Route53 emulator:
leasefield — what every released spored sends — gets no lease;The reaper:
pkg/dnstable)A-records and the lease only — never alias CNAMEs, matching
expireSubdomain's existing reasoning: a dangling CNAME resolves to nothing, a dangling A-record resolves to a stranger.DnsLeaseExpirearrivesfalseand is live-wins (not inALWAYS_ASSERT), so arming it later isn't undone by a plainmake deploy. Added to the #650 guard's mode-setting list.The cross-module contract
lambda/dns-updateris its own Go module and can't importpkg/dns, so it carries a copy of the lease name and format. Drift would silently disable the feature.TestDNSLeaseContractMatchesTheUpdaterparses the updater's copy withgo/astand compares values, not text — the comment beside the copy names the prefix too, and would satisfy a substring match. Verified against drift in both the name and the layout.A comment this makes false, corrected
expiry.gosaid "spored registers DNS once, at boot — there is no periodic re-registration, so a wrongly deleted A-record never self-heals." No longer true of a renewing spored — and it's the premise #466's caution rests on. Corrected rather than left, noting it's still true of every pre-lease spored, which is why #466's caution correctly stands.Semgrep
Flagged
math/randfor the jitter. Not security-sensitive, sonosemgrepwould've been defensible; switched tocrypto/randinstead, which costs nothing. Jitter gate re-verified against the new implementation.make check(all 9 nested modules),make check-docs, semgrep,api-snapshot(no drift —pkg/dnsisn't public surface) all clean.Not in this PR: three deploys
Merging changes nothing live. Order is forgiving — an old updater ignores the unknown
leasefield, and an old spored never sends it — but leases only start once all three are out: the updater (writes leases), the reaper (reports;DnsLeaseExpirestaysfalse), and spored to S3 (new instances renew). Arming expiry is a further, separate decision after the report has been read.🤖 Generated with Claude Code