Skip to content

DNS leases: expire abandoned records without credentials in the owning account - #875

Merged
scttfrdmn merged 1 commit into
mainfrom
feat/dns-lease
Oct 12, 2026
Merged

scttfrdmn merged 1 commit into
mainfrom
feat/dns-lease

Conversation

@scttfrdmn

Copy link
Copy Markdown
Contributor

The gap

A spore in an account the TTL reaper doesn't cover registered loop-l12-esc.c0zxr0ao.spore.host today. 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:

backstop how it decides needs
DNS sweep (#438) DescribeInstances in the owning account a role there
DNS expiry (#466) the portal prober proved the account empty a role there
self-hosted reaper (#625) runs in the owner's account no access to spore.host's zone at all

For 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.

  • spored re-registers about hourly — 1h ± 10m, jittered so a job array launched together doesn't hit Route53's 5/sec limit — through one registerDNS method shared with boot, so renewal can't drift into a different request. spawn:dns-status is re-tagged only on change, not hourly.
  • DNS updater writes _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.
  • TTL reaper reports leases unrenewed for 6 hours and, armed, expires the A-record and its lease — only for account subdomains it does not cover.

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 register is a one-shot caller of the same pkg/dns client. Had the client always requested a lease, every record it registers would be expired 6h later under a live instance. TestOnlyARenewingCallerMayRequestALease parses every non-test Go file and fails if anything but spored's agent calls SetRenewing(true) — or if the agent does without calling refreshDNSLease. 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:

  • a body with no lease field — what every released spored sends — gets no lease;
  • a non-renewing client re-registering a name clears an inherited lease. Without that, a renewing spored replaced by an older one would leave a lease that ages out under a live instance.

The reaper:

guard revert that fails
covered accounts never expired by lease (a stale lease there = hung spored on a live box) exemption removed
only stale leases act "expire any lease"
unparseable lease reported, never acted on authorize unparseable
re-reads the lease right before deleting — a mid-run renewal wins re-read skipped
refuses to run with no resolved account IDs (else everything looks uncovered) guard removed
nothing acts unless armed; dry-run honoured ignore the flag
a future-dated lease reads fresh, so clock skew can't expire a live record — (pkg/dns table)

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.

DnsLeaseExpire arrives false and is live-wins (not in ALWAYS_ASSERT), so arming it later isn't undone by a plain make deploy. Added to the #650 guard's mode-setting list.

The cross-module contract

lambda/dns-updater is its own Go module and can't import pkg/dns, so it carries a copy of the lease name and format. Drift would silently disable the feature. TestDNSLeaseContractMatchesTheUpdater parses the updater's copy with go/ast and 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.go said "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/rand for the jitter. Not security-sensitive, so nosemgrep would've been defensible; switched to crypto/rand instead, 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/dns isn't public surface) all clean.

Not in this PR: three deploys

Merging changes nothing live. Order is forgiving — an old updater ignores the unknown lease field, and an old spored never sends it — but leases only start once all three are out: the updater (writes leases), the reaper (reports; DnsLeaseExpire stays false), and spored to S3 (new instances renew). Arming expiry is a further, separate decision after the report has been read.

🤖 Generated with Claude Code

…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

codecov Bot commented Oct 12, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 55.84416% with 34 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
pkg/agent/dns_lease.go 35.55% 27 Missing and 2 partials ⚠️
pkg/dns/client.go 0.00% 3 Missing ⚠️
pkg/agent/agent.go 77.77% 2 Missing ⚠️

📢 Thoughts on this report? Let us know!

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.

1 participant