Repository navigation
feat(ttl-reaper): report account subdomains with no credentials (#457) - #458
Merged
Merged
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
The #438 DNS sweep is per-account and derives each subdomain from the accounts in REAPER_ROLE_ARNS, so records belonging to an account absent from that list were invisible: no sweep, no error, no signal at all. That is the silent half of the leak — the loud half (a listed account whose assume-role fails) at least poisons the error count. Walk the zone once per run, decode each {base36} label back to an account ID, and log every subdomain whose account we hold no credentials for. Report-only, deliberately. An unmanaged subdomain is ambiguous: an account that uninstalled, or a live one someone forgot to add to REAPER_ROLE_ARNS. Without credentials there is no way to tell which, because DescribeInstances is how emptiness is proven — so deleting on the second reading would tear the DNS out from under working spores. Same reasoning as the sweep's existing refusal to delete against a partial live set: no deletion without a complete picture. The hazard this surfaces is concrete: a released public IP returns to the EC2 pool, so an abandoned A-record eventually resolves to an unrelated instance. Verified against the live spore.host zone — it flags exactly 4zlw3a1t.spore.host (account 390967728545, not in the org and with no cross-account role) and nothing else, sparing the zone's www/api/alias and DecodeAccountID discriminates exactly rather than heuristically: every 12-digit account ID is precisely 8 base36 characters (36^7 < 10^11 and 36^8 > 10^12), so www/api decode far outside the account range and can never masquerade as accounts. A false positive here would report live DNS as abandoned, so classification is a pure function tested without AWS. Mutation-checked the guards: dropping the domain-suffix test, the managed check, the last-label rule, or the sort all fail the new tests. That pass also caught a real bug in this change — the original guard compared a name against its own already-trimmed value, so it never excluded anything, and out-of-domain names only passed by luck of their last label not decoding. Broader deprovisioning lifecycle (registry status/lastSeenAt, the K/N policy, correlated-failure trap) stays in #457.
scttfrdmn
force-pushed
the
feat/reaper-unmanaged-subdomain-report
branch
from
July 31, 2026 02:20
7416eeb to
42d5682
Compare
This was referenced Jul 31, 2026
scttfrdmn
added a commit
that referenced
this pull request
Jul 31, 2026
…466) The #457 unmanaged-subdomain report deliberately deleted nothing, and said why: an unmanaged subdomain is ambiguous — an account that uninstalled and left records behind, or a live account someone forgot to add to REAPER_ROLE_ARNS — and the two are indistinguishable *precisely because we lack the credentials*, since DescribeInstances is how emptiness is proven. The portal's account-prober supplies exactly that proof. It holds a role the registry knows about (spore-portal-onboard — a different role from the reaper's spawn-ttl-reaper-ec2) and probes every region, writing the result to spore-portal-accounts. So for an account in the registry the ambiguity is now resolvable, and accountlifecycle.DNSExpiryEligible is the verdict: dormant -> eligible (reachable AND provably empty for N days) offboarded -> eligible (a human stated the intent) active -> no (the account is in use) unreachable -> no (#457 trap 2: the role we would verify through is gone, so emptiness can no longer be proven — that needs a human, not a longer wait) absent / unreadable -> no (the prober has no opinion; the original #458 ambiguity stands in full) The verdict is ALWAYS logged. Acting on it needs a new default-off REAPER_DNS_EXPIRE on top of the sweep's existing opt-in. Two switches rather than one because REAPER_DNS_SWEEP is already enabled in production: folding expiry into it would make an existing flag silently destructive on upgrade, for a class of records it has never touched. What has NOT changed is the cost of being wrong. spored registers DNS once, at boot (pkg/agent/agent.go) with no periodic re-registration, so a wrongly deleted A-record never self-heals — the spore keeps running and is simply unreachable by name until it reboots. Hence: expiry deletes only A-records, never the #121 friendly CNAMEs (a dangling CNAME resolves to nothing, whereas a stale A-record eventually resolves to a stranger's box once the IP recycles). The decision that authorizes a deletion is a pure function (authorizeExpiry), so the full truth table — every combination of verdict and configuration that could delete a live spore's DNS — is tested in one place with no AWS. A route53API seam covers the other half: a pure test proves what the reaper decides, only a fake proves what it actually sends. IAM is read-only by construction: dynamodb:Scan on the registry table and kms:Decrypt on its CMK, never UpdateItem/PutItem/DeleteItem and never GenerateDataKey. The prober owns every write, and the reaper being unable to write the table is what makes it impossible for a reaper bug to manufacture the eligibility it then acts on. New summary fields: DNSExpiryEligible / DNSExpiryIneligible (verdicts) and DNSExpiredRecords. Eligible-but-not-Expired is the normal, healthy reading — it means the verdict exists and the flag is off. Also fixes `make build`, which named main.go instead of the package and so would have shipped a binary silently missing expiry.go had it not been referenced. And threads the new template parameters through `make deploy`, which sam otherwise marks UsePreviousValue — the same omission that once made #438 unreachable from the Makefile. Refs #457, #458, #466
scttfrdmn
added a commit
that referenced
this pull request
Jul 31, 2026
…466) The #457 unmanaged-subdomain report deliberately deleted nothing, and said why: an unmanaged subdomain is ambiguous — an account that uninstalled and left records behind, or a live account someone forgot to add to REAPER_ROLE_ARNS — and the two are indistinguishable *precisely because we lack the credentials*, since DescribeInstances is how emptiness is proven. The portal's account-prober supplies exactly that proof. It holds a role the registry knows about (spore-portal-onboard — a different role from the reaper's spawn-ttl-reaper-ec2) and probes every region, writing the result to spore-portal-accounts. So for an account in the registry the ambiguity is now resolvable, and accountlifecycle.DNSExpiryEligible is the verdict: dormant -> eligible (reachable AND provably empty for N days) offboarded -> eligible (a human stated the intent) active -> no (the account is in use) unreachable -> no (#457 trap 2: the role we would verify through is gone, so emptiness can no longer be proven — that needs a human, not a longer wait) absent / unreadable -> no (the prober has no opinion; the original #458 ambiguity stands in full) The verdict is ALWAYS logged. Acting on it needs a new default-off REAPER_DNS_EXPIRE on top of the sweep's existing opt-in. Two switches rather than one because REAPER_DNS_SWEEP is already enabled in production: folding expiry into it would make an existing flag silently destructive on upgrade, for a class of records it has never touched. What has NOT changed is the cost of being wrong. spored registers DNS once, at boot (pkg/agent/agent.go) with no periodic re-registration, so a wrongly deleted A-record never self-heals — the spore keeps running and is simply unreachable by name until it reboots. Hence: expiry deletes only A-records, never the #121 friendly CNAMEs (a dangling CNAME resolves to nothing, whereas a stale A-record eventually resolves to a stranger's box once the IP recycles). The decision that authorizes a deletion is a pure function (authorizeExpiry), so the full truth table — every combination of verdict and configuration that could delete a live spore's DNS — is tested in one place with no AWS. A route53API seam covers the other half: a pure test proves what the reaper decides, only a fake proves what it actually sends. IAM is read-only by construction: dynamodb:Scan on the registry table and kms:Decrypt on its CMK, never UpdateItem/PutItem/DeleteItem and never GenerateDataKey. The prober owns every write, and the reaper being unable to write the table is what makes it impossible for a reaper bug to manufacture the eligibility it then acts on. New summary fields: DNSExpiryEligible / DNSExpiryIneligible (verdicts) and DNSExpiredRecords. Eligible-but-not-Expired is the normal, healthy reading — it means the verdict exists and the flag is off. Also fixes `make build`, which named main.go instead of the package and so would have shipped a binary silently missing expiry.go had it not been referenced. And threads the new template parameters through `make deploy`, which sam otherwise marks UsePreviousValue — the same omission that once made Refs #457, #458, #466
scttfrdmn
added a commit
that referenced
this pull request
Jul 31, 2026
…466) (#468) The #457 unmanaged-subdomain report deliberately deleted nothing, and said why: an unmanaged subdomain is ambiguous — an account that uninstalled and left records behind, or a live account someone forgot to add to REAPER_ROLE_ARNS — and the two are indistinguishable *precisely because we lack the credentials*, since DescribeInstances is how emptiness is proven. The portal's account-prober supplies exactly that proof. It holds a role the registry knows about (spore-portal-onboard — a different role from the reaper's spawn-ttl-reaper-ec2) and probes every region, writing the result to spore-portal-accounts. So for an account in the registry the ambiguity is now resolvable, and accountlifecycle.DNSExpiryEligible is the verdict: dormant -> eligible (reachable AND provably empty for N days) offboarded -> eligible (a human stated the intent) active -> no (the account is in use) unreachable -> no (#457 trap 2: the role we would verify through is gone, so emptiness can no longer be proven — that needs a human, not a longer wait) absent / unreadable -> no (the prober has no opinion; the original #458 ambiguity stands in full) The verdict is ALWAYS logged. Acting on it needs a new default-off REAPER_DNS_EXPIRE on top of the sweep's existing opt-in. Two switches rather than one because REAPER_DNS_SWEEP is already enabled in production: folding expiry into it would make an existing flag silently destructive on upgrade, for a class of records it has never touched. What has NOT changed is the cost of being wrong. spored registers DNS once, at boot (pkg/agent/agent.go) with no periodic re-registration, so a wrongly deleted A-record never self-heals — the spore keeps running and is simply unreachable by name until it reboots. Hence: expiry deletes only A-records, never the #121 friendly CNAMEs (a dangling CNAME resolves to nothing, whereas a stale A-record eventually resolves to a stranger's box once the IP recycles). The decision that authorizes a deletion is a pure function (authorizeExpiry), so the full truth table — every combination of verdict and configuration that could delete a live spore's DNS — is tested in one place with no AWS. A route53API seam covers the other half: a pure test proves what the reaper decides, only a fake proves what it actually sends. IAM is read-only by construction: dynamodb:Scan on the registry table and kms:Decrypt on its CMK, never UpdateItem/PutItem/DeleteItem and never GenerateDataKey. The prober owns every write, and the reaper being unable to write the table is what makes it impossible for a reaper bug to manufacture the eligibility it then acts on. New summary fields: DNSExpiryEligible / DNSExpiryIneligible (verdicts) and DNSExpiredRecords. Eligible-but-not-Expired is the normal, healthy reading — it means the verdict exists and the flag is off. Also fixes `make build`, which named main.go instead of the package and so would have shipped a binary silently missing expiry.go had it not been referenced. And threads the new template parameters through `make deploy`, which sam otherwise marks UsePreviousValue — the same omission that once made Refs #457, #458, #466
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.
Closes the first checkbox of #457. Report-only; no behavior change to the reap or sweep paths.
The gap
The #438 sweep is per-account and derives each subdomain from
REAPER_ROLE_ARNS(main.go:985). Records belonging to an account absent from that list are therefore invisible to it — no sweep, no error, no signal. That is the silent half of the leak; the loud half (a listed account whose assume-role fails) at least poisonssum.Errors.Live example, still in the zone:
win11-test.4zlw3a1t.spore.host→13.223.189.34.4zlw3a1tdecodes to account 390967728545, which has no cross-account role, is not inREAPER_ROLE_ARNS, and is not in the org.What this adds
One
ListResourceRecordSetswalk per run → distinct{base36}labels → decode → diff against the configured account set → log and count what's left over. New summary fieldsDNSUnmanagedSubdomains/DNSUnmanagedRecords.Why it deletes nothing
An unmanaged subdomain is ambiguous — an account that uninstalled, or a live one someone forgot to add to
REAPER_ROLE_ARNS— and there is no way to tell which, precisely because we lack credentials:DescribeInstancesis how emptiness gets proven. Deleting on the second reading tears the DNS out from under working spores. This is the same rule the sweep already follows in refusing to delete against a partial live set (main.go:987-992): no deletion without a complete picture. So it raises a signal for a human and stops.The hazard it makes visible is concrete: a released public IP returns to the EC2 pool, so an abandoned A-record eventually resolves to an unrelated instance.
Exact discrimination, not a heuristic
A false positive here tells an operator that a live account is abandoned, so
dns.DecodeAccountID(new inverse ofEncodeAccountID) is exact: every 12-digit account ID is precisely 8 base36 characters, since 36^7 < 10^11 and 36^8 > 10^12.wwwandapiare legal base36 but decode far outside the account range;mycelium-developmentisn't base36 at all. The width check is documented as a cheap early-out rather than a correctness guard, because the range test alone is sufficient.Verification
go test ./pkg/dns/andgo test ./lambda/ttl-reaper/green;go vet+gofmtclean.spore.hostzone (driven via a scratch test, since removed): flags exactly4zlw3a1t.spore.host— 1 subdomain, 1 record, 0 errors — and spares the zone'swww/api, CloudFront alias A-records, and Use the AWS account's friendly name (not just base36 account ID) in DNS and elsewhere #121 friendly CNAMEs.That mutation pass earned its keep: it caught a real bug in this change's first draft. The original guard compared a name against its own already-trimmed value (
name == rawafterTrimSuffixhad run), so it never excluded anything — out-of-domain names were passing only by luck of their last label not decoding. Fixed to test the domain suffix explicitly, with a case (host.4zlw3a1t.) that fails without it.Out of scope
Registry lifecycle (
status/lastSeenAt), the K/N dormancy policy, and the correlated-failure trap (a CloudFormation stack recreation changes the reaper's role-ARN suffix and breaks every customer's trust policy at once, which must never read as mass uninstall) all stay in #457 — that half changes the onboarding contract and deserves its own decision.