You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
DNS records leak when spored doesn't exit through Cleanup (abrupt terminate/spot/crash) — no backstop reaper #438
Route53 A-records under an account's {base36}.spore.host subdomain outlive their instances. In the dev account (435415984226, base36 5k0zfnmq) I found stale records pointing at IPs with no live instance:
gatetest.5k0zfnmq.spore.host → 13.221.19.38 (no such instance)
tstest.5k0zfnmq.spore.host → 3.227.10.61 (no such instance)
Both still resolve publicly. Meanwhile instances that self-terminated on TTL did deregister correctly (verified: name → NONE after termination).
Root cause
Deregistration only happens when spored runs Cleanup() → DeleteDNS. Confirmed paths that call it: terminate() (TTL self-terminate, agent.go:1619), spot-interrupt (1198), and a couple of other graceful exits. But instances that exit without spored running Cleanup leak their record:
spot reclaim faster than the interruption handler completes.
Two gaps:
Cleanup isn't wired to SIGTERM.cmd/spored already has signal.Notify(..., SIGTERM) for shutdown, but the DNS Cleanup isn't invoked on that path — so even a graceful systemctl stop (and the shutdown that precedes an OS-level terminate) may not deregister. Hooking Cleanup to the SIGTERM handler would cover systemctl stop and instance-stop, though not hard kills.
No backstop DNS reaper. Nothing reconciles Route53 against live instances. This is the only reliable fix for the abrupt-exit cases (which are inherent — a crashed box can't deregister itself). Analogous to the orphan-instance reaper (spawn-ts#23 / the TTL-reaper Server-side TTL reaper: out-of-band backstop so a spore can never outlive its deadline (even if spored is dead) #70): periodically list {base36}.spore.host A-records and delete any whose IP has no running spawn:managed instance in that account. Natural home: the spawn-dns-updater Lambda gaining a sweep mode, or the existing TTL-reaper Lambda also reaping DNS.
Impact
Stale DNS accumulates indefinitely and resolves to dead (or eventually reassigned) public IPs — a correctness and mild security concern (a name could later point at someone else's EC2 IP). Cosmetically clutters the zone.
Repro
Launch a spawn instance (gets {name}.{base36}.spore.host), then terminate it from the console/API (not via TTL). The A-record remains in Route53 and keeps resolving.
Found while running the spawn-ts browser BYOA demo; the browser launcher can't deregister (instance-side spored owns it), so this is purely a spored/infra concern.
Verified — issue is valid; one correction to claim #1, and the reaper is closer than the report assumes
Confirmed the mechanism against the code. Two adjustments to the writeup, but the core gap (no record-driven reconciliation) is real.
Correction to gap #1 ("Cleanup isn't wired to SIGTERM")
It is wired. On Unix, waitForShutdown() (cmd/spored/shutdown_other.go) does signal.Notify(sigChan, SIGINT, SIGTERM) and blocks on it; runDaemon() then runs agent.Cleanup(cleanupCtx) → DeleteDNS (cmd/spored/main.go:211-237). So a systemctl stop (and the SIGTERM an OS shutdown sends) does deregister today, within the 10s cleanup budget. The real uncovered cases are the ones inherent to abrupt exit: hard crash / OOM / power-off, and a fast spot reclaim or API terminate where the box dies before cleanup completes.
Gap #2 is the actual fix — and partially exists already
The ttl-reaper Lambda already deletes DNS (#247) — but only for instances it can still see. It's instance-driven: DescribeInstances → for each past-deadline/reaped candidate it calls deleteDNS() (lambda/ttl-reaper/main.go:407,822; comment: "spored's graceful DeleteDNS never ran"). It captures spawn:dns-name/base36/accountName from the instance tags to know what to delete.
The hole: once an instance is gone from DescribeInstances (terminated out-of-band and aged out of the API after ~1h, or hard-crashed and reaped by AWS), there's no candidate left to key off — so its record is orphaned with nothing pointing at it. That's exactly your gatetest/tstest: instance long gone, record remains. (Side note: both now return NXDOMAIN/empty via public DoH — either TTL-expired from resolver cache or cleaned since you filed — but the mechanism stands.)
Recommended fix (record-driven sweep — the inverse enumeration)
Add a reconciliation pass to the ttl-reaper (it already has Route53 perms + the account-base36 mapping):
Build the set of livespawn:managed instance public IPs from the DescribeInstances pass it already does.
Delete any A-record whose IP is not in that live set — with a grace window (e.g. skip records younger than ~15m) to avoid racing a just-launched instance that registered before it appears in the reaper's instance list.
This is the only reliable fix for the abrupt-exit cases (a crashed box can't deregister itself), and it complements — doesn't replace — the existing spored-Cleanup and #247 reaper-teardown paths. The security angle (a stale name later resolving to a reassigned EC2 IP) makes the grace-windowed sweep worth doing.
Scope note
The fix lives in infra (the ttl-reaper Lambda), not the spawn CLI/spored — so I'm flagging it for a maintainer rather than implementing it here. Happy to draft the sweep logic + tests against lambda/ttl-reaper if you want it as a PR. No code changed for this analysis; read-only.
Fixed by PR #439 (merged) — opt-in DNS reconciliation sweep in the ttl-reaper.
What shipped:REAPER_DNS_SWEEP=true makes the reaper, per account, list the {base36}.{domain} A-records and delete any whose IP has no live (running/pending) spawn:managed instance. base36 is derived from the account ID, so a subdomain with a stale record and zero instances is still reconciled — the record-driven inverse enumeration the #247 instance-driven teardown can't do. This is the reliable fix for the abrupt-exit cases (crash / out-of-band terminate / fast spot reclaim) a crashed box can't self-deregister.
Safety: opt-in + default off, honors REAPER_DRY_RUN, aborts without deleting if any region's live-IP scan errors (never deletes against a partial live set), touches only plain A-records under the account subdomain (skips the apex + Route53 alias records), and reuses the existing #247 Route53 + DescribeInstances IAM (no new permissions). Pure orphanedRecords core is unit-tested.
Recommended rollout: deploy with REAPER_DNS_SWEEP=trueandREAPER_DRY_RUN=true first — it'll log WOULD delete orphaned A-record … for each stale record (should include the gatetest/tstest leaks you found). Verify that list, then flip REAPER_DRY_RUN=false.
Verified the fix live (read-only) while closing out the spawn-ts side. Three findings:
1. Gap (1) is already closed. This issue named "Cleanup isn't wired to SIGTERM in cmd/spored" — it is: waitForShutdown() → agent.Cleanup() → DeleteDNS, since 0ea9e39 (2026-06-08), with TimeoutStopSec=30 in the systemd unit. No change needed.
2. The gap-(2) sweep works. Drove the real sweepAccountDNS in dry-run against the live spore.host zone. It correctly flagged a genuine orphan —
DNS sweep: WOULD delete orphaned A-record win11-test.4zlw3a1t.spore.host -> 13.223.189.34 (no live instance)
— with zero live spawn:managed instances in any scanned region, while sparing every alias and out-of-account record. The partial-scan safety abort was confirmed live too: a cross-account DescribeInstances denial logged aborting sweep for this account and deleted nothing.
3. But it isn't running in production, and couldn't be turned on.make deploy never passed DnsSweep (nor DnsZoneId/DnsDomain), and sam deploy marks omitted parameters UsePreviousValue — so the documented REAPER_DNS_SWEEP knob had no supported way to be set. Consistent with production: spawn-ttl-reaper-production last updated 2026-06-25 (before #439 landed on 07-23), no REAPER_DNS_SWEEP in its environment, and no dns-sweep= field on its live init line. Fixed in #453.
Also worth noting: the orphan above belongs to account 390967728545, which is not in the reaper's RoleArns. The sweep is per-account (it derives each {base36} subdomain from the account ID), so that record stays orphaned until the account is added — #453's README change calls this out.
Remaining to fully close the loop, both gated on approval: deploying the reaper with DNS_SWEEP=true, and the explicit non-graceful (out-of-band terminate) de-register test this issue targets.
Live verification (infra 966362334030 + dev 435415984226)
Verified both halves of this issue against the real spore.host zone rather than trusting green CI.
Gap 1 — Cleanup not wired to SIGTERM: already closed.cmd/spored/main.gowaitForShutdown() calls agent.Cleanup(cleanupCtx), which reaches DeleteDNS (pkg/agent/agent.go:1436-1481). In place since 0ea9e39.
Gap 2 — no backstop reaper: closed in code, but unreachable in production. The sweep (8c0a014 / #439) was correct, but make deploy never passed DnsSweep, and sam deploy marks any parameter it is not given as UsePreviousValue — so the production stack silently kept dns-sweep=false while both the code and the README claimed the feature existed. #453 + #455 fix that. #455 also fixes a second, more dangerous bug found while deploying: with an empty parameter value, sam either rejects the whole --parameter-overrides string or silently mis-keys every parameter (observed NotifyUrl swallowed as the literal key ParameterKey) — a deploy that reports success having applied something other than what was asked.
Production now reports enforcement and the sweep both live:
Driving the real sweepAccountDNS in dry-run against the live zone found a genuine orphan — win11-test.4zlw3a1t.spore.host → 13.223.189.34, zero live instances — and correctly spared every alias record and every record outside the account's {base36} subdomain. That orphan's account (390967728545) is not in RoleArns, so the sweep will never reconcile it until the cross-account role is deployed there; the sweep is per-account by construction.
Correction to this issue's premise: an EC2 API terminate is graceful
The title lists "out-of-band terminate" alongside crash and spot reclaim. It doesn't belong there. Launched abrupt438 in dev, confirmed registration, then terminated purely via aws ec2 terminate-instances — never touching the instance:
The record was gone at +20s, while the instance was still shutting-down, and CloudTrail attributes the DELETE to the dying instance itself — spawn-dns-updater logged the caller as arn:aws:sts::435415984226:assumed-role/spored-instance-role/i-0783ecd0903e0df0c. TerminateInstances triggers an ACPI shutdown → systemd SIGTERM → sporedCleanup() → DeleteDNS, comfortably inside TimeoutStopSec=30. No leak occurred, so the sweep had nothing to reclaim.
Still unverified live: the genuinely abrupt paths — hard crash / OOM kill, and spot reclaim faster than the shutdown can complete. They're hard to produce on demand. The sweep is the right backstop for them and is now provably enabled and provably safe against the live zone, but its reclaim path has so far only been exercised against a pre-existing orphan, not one created during a test.
Activity
scttfrdmn commentedon Jul 23, 2026
Verified — issue is valid; one correction to claim #1, and the reaper is closer than the report assumes
Confirmed the mechanism against the code. Two adjustments to the writeup, but the core gap (no record-driven reconciliation) is real.
Correction to gap #1 ("Cleanup isn't wired to SIGTERM")
It is wired. On Unix,
waitForShutdown()(cmd/spored/shutdown_other.go) doessignal.Notify(sigChan, SIGINT, SIGTERM)and blocks on it;runDaemon()then runsagent.Cleanup(cleanupCtx)→DeleteDNS(cmd/spored/main.go:211-237). So asystemctl stop(and the SIGTERM an OS shutdown sends) does deregister today, within the 10s cleanup budget. The real uncovered cases are the ones inherent to abrupt exit: hard crash / OOM / power-off, and a fast spot reclaim or API terminate where the box dies before cleanup completes.Gap #2 is the actual fix — and partially exists already
The ttl-reaper Lambda already deletes DNS (#247) — but only for instances it can still see. It's instance-driven:
DescribeInstances→ for each past-deadline/reaped candidate it callsdeleteDNS()(lambda/ttl-reaper/main.go:407,822; comment: "spored's graceful DeleteDNS never ran"). It capturesspawn:dns-name/base36/accountNamefrom the instance tags to know what to delete.The hole: once an instance is gone from
DescribeInstances(terminated out-of-band and aged out of the API after ~1h, or hard-crashed and reaped by AWS), there's no candidate left to key off — so its record is orphaned with nothing pointing at it. That's exactly yourgatetest/tstest: instance long gone, record remains. (Side note: both now return NXDOMAIN/empty via public DoH — either TTL-expired from resolver cache or cleaned since you filed — but the mechanism stands.)Recommended fix (record-driven sweep — the inverse enumeration)
Add a reconciliation pass to the ttl-reaper (it already has Route53 perms + the account-base36 mapping):
ListResourceRecordSetsunder{base36}.spore.host(A-records + the Use the AWS account's friendly name (not just base36 account ID) in DNS and elsewhere #121 friendly CNAMEs).spawn:managedinstance public IPs from theDescribeInstancespass it already does.This is the only reliable fix for the abrupt-exit cases (a crashed box can't deregister itself), and it complements — doesn't replace — the existing spored-Cleanup and #247 reaper-teardown paths. The security angle (a stale name later resolving to a reassigned EC2 IP) makes the grace-windowed sweep worth doing.
Scope note
The fix lives in infra (the ttl-reaper Lambda), not the spawn CLI/spored — so I'm flagging it for a maintainer rather than implementing it here. Happy to draft the sweep logic + tests against
lambda/ttl-reaperif you want it as a PR. No code changed for this analysis; read-only.feat(ttl-reaper): DNS reconciliation sweep for orphaned records (#438) (
scttfrdmn commentedon Jul 23, 2026
Fixed by PR #439 (merged) — opt-in DNS reconciliation sweep in the ttl-reaper.
What shipped:
REAPER_DNS_SWEEP=truemakes the reaper, per account, list the{base36}.{domain}A-records and delete any whose IP has no live (running/pending)spawn:managedinstance.base36is derived from the account ID, so a subdomain with a stale record and zero instances is still reconciled — the record-driven inverse enumeration the #247 instance-driven teardown can't do. This is the reliable fix for the abrupt-exit cases (crash / out-of-band terminate / fast spot reclaim) a crashed box can't self-deregister.Safety: opt-in + default off, honors
REAPER_DRY_RUN, aborts without deleting if any region's live-IP scan errors (never deletes against a partial live set), touches only plain A-records under the account subdomain (skips the apex + Route53 alias records), and reuses the existing #247 Route53 + DescribeInstances IAM (no new permissions). PureorphanedRecordscore is unit-tested.Recommended rollout: deploy with
REAPER_DNS_SWEEP=trueandREAPER_DRY_RUN=truefirst — it'll logWOULD delete orphaned A-record …for each stale record (should include thegatetest/tstestleaks you found). Verify that list, then flipREAPER_DRY_RUN=false.Closed as completed.
scttfrdmn commentedon Jul 31, 2026
Verified the fix live (read-only) while closing out the spawn-ts side. Three findings:
1. Gap (1) is already closed. This issue named "
Cleanupisn't wired to SIGTERM incmd/spored" — it is:waitForShutdown()→agent.Cleanup()→DeleteDNS, since 0ea9e39 (2026-06-08), withTimeoutStopSec=30in the systemd unit. No change needed.2. The gap-(2) sweep works. Drove the real
sweepAccountDNSin dry-run against the livespore.hostzone. It correctly flagged a genuine orphan —— with zero live
spawn:managedinstances in any scanned region, while sparing every alias and out-of-account record. The partial-scan safety abort was confirmed live too: a cross-accountDescribeInstancesdenial loggedaborting sweep for this accountand deleted nothing.3. But it isn't running in production, and couldn't be turned on.
make deploynever passedDnsSweep(norDnsZoneId/DnsDomain), andsam deploymarks omitted parametersUsePreviousValue— so the documentedREAPER_DNS_SWEEPknob had no supported way to be set. Consistent with production:spawn-ttl-reaper-productionlast updated 2026-06-25 (before #439 landed on 07-23), noREAPER_DNS_SWEEPin its environment, and nodns-sweep=field on its live init line. Fixed in #453.Also worth noting: the orphan above belongs to account
390967728545, which is not in the reaper'sRoleArns. The sweep is per-account (it derives each{base36}subdomain from the account ID), so that record stays orphaned until the account is added — #453's README change calls this out.Remaining to fully close the loop, both gated on approval: deploying the reaper with
DNS_SWEEP=true, and the explicit non-graceful (out-of-band terminate) de-register test this issue targets.fix(ttl-reaper): make the #438 DNS sweep reachable from make deploy (#…
scttfrdmn commentedon Jul 31, 2026
Live verification (infra 966362334030 + dev 435415984226)
Verified both halves of this issue against the real
spore.hostzone rather than trusting green CI.Gap 1 —
Cleanupnot wired to SIGTERM: already closed.cmd/spored/main.gowaitForShutdown()callsagent.Cleanup(cleanupCtx), which reachesDeleteDNS(pkg/agent/agent.go:1436-1481). In place since 0ea9e39.Gap 2 — no backstop reaper: closed in code, but unreachable in production. The sweep (8c0a014 / #439) was correct, but
make deploynever passedDnsSweep, andsam deploymarks any parameter it is not given asUsePreviousValue— so the production stack silently keptdns-sweep=falsewhile both the code and the README claimed the feature existed. #453 + #455 fix that. #455 also fixes a second, more dangerous bug found while deploying: with an empty parameter value,sameither rejects the whole--parameter-overridesstring or silently mis-keys every parameter (observedNotifyUrlswallowed as the literal keyParameterKey) — a deploy that reports success having applied something other than what was asked.Production now reports enforcement and the sweep both live:
Driving the real
sweepAccountDNSin dry-run against the live zone found a genuine orphan —win11-test.4zlw3a1t.spore.host→ 13.223.189.34, zero live instances — and correctly spared every alias record and every record outside the account's{base36}subdomain. That orphan's account (390967728545) is not inRoleArns, so the sweep will never reconcile it until the cross-account role is deployed there; the sweep is per-account by construction.Correction to this issue's premise: an EC2 API terminate is graceful
The title lists "out-of-band terminate" alongside crash and spot reclaim. It doesn't belong there. Launched
abrupt438in dev, confirmed registration, then terminated purely viaaws ec2 terminate-instances— never touching the instance:The record was gone at +20s, while the instance was still
shutting-down, and CloudTrail attributes the DELETE to the dying instance itself —spawn-dns-updaterlogged the caller asarn:aws:sts::435415984226:assumed-role/spored-instance-role/i-0783ecd0903e0df0c.TerminateInstancestriggers an ACPI shutdown → systemd SIGTERM →sporedCleanup()→DeleteDNS, comfortably insideTimeoutStopSec=30. No leak occurred, so the sweep had nothing to reclaim.Still unverified live: the genuinely abrupt paths — hard crash / OOM kill, and spot reclaim faster than the shutdown can complete. They're hard to produce on demand. The sweep is the right backstop for them and is now provably enabled and provably safe against the live zone, but its reclaim path has so far only been exercised against a pre-existing orphan, not one created during a test.
feat(ttl-reaper): report account subdomains with no credentials (#457)
feat(ttl-reaper): report account subdomains with no credentials (#457) (
feat(ttl-reaper): expire unmanaged subdomain DNS on registry verdict (#…
fix(reaper): read the live stack before deploying, so unspecified par…
DNS leases: expire abandoned records without credentials in the ownin…