Skip to content

feat(ttl-reaper): report account subdomains with no credentials (#457) - #458

Merged
scttfrdmn merged 1 commit into
mainfrom
feat/reaper-unmanaged-subdomain-report
Jul 31, 2026
Merged

scttfrdmn merged 1 commit into
mainfrom
feat/reaper-unmanaged-subdomain-report

Conversation

@scttfrdmn

Copy link
Copy Markdown
Contributor

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 poisons sum.Errors.

Live example, still in the zone: win11-test.4zlw3a1t.spore.host → 13.223.189.34. 4zlw3a1t decodes to account 390967728545, which has no cross-account role, is not in REAPER_ROLE_ARNS, and is not in the org.

What this adds

One ListResourceRecordSets walk per run → distinct {base36} labels → decode → diff against the configured account set → log and count what's left over. New summary fields DNSUnmanagedSubdomains / DNSUnmanagedRecords.

UNMANAGED subdomain 4zlw3a1t.spore.host (account 390967728545) — 1 record(s),
  no credentials to reconcile; add its role to REAPER_ROLE_ARNS to sweep it,
  or offboard it deliberately (#457)

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: DescribeInstances is 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 of EncodeAccountID) is exact: every 12-digit account ID is precisely 8 base36 characters, since 36^7 < 10^11 and 36^8 > 10^12. www and api are legal base36 but decode far outside the account range; mycelium-development isn'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/ and go test ./lambda/ttl-reaper/ green; go vet + gofmt clean.
  • Round-trip property test: encode→decode is the identity for the range edges and every real account in the org.
  • Live, read-only, against the real spore.host zone (driven via a scratch test, since removed): flags exactly 4zlw3a1t.spore.host — 1 subdomain, 1 record, 0 errors — and spares the zone's www/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.
  • Mutation-checked the four guards that matter — dropping the domain-suffix test, the managed-account check, the last-label rule, or the sort each fail the new tests.

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 == raw after TrimSuffix had 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.

@codecov

codecov Bot commented Jul 31, 2026 •

Copy link
Copy Markdown

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
scttfrdmn force-pushed the feat/reaper-unmanaged-subdomain-report branch from 7416eeb to 42d5682 Compare July 31, 2026 02:20
@scttfrdmn
scttfrdmn merged commit e4739e0 into main Jul 31, 2026
7 checks passed
@scttfrdmn
scttfrdmn deleted the feat/reaper-unmanaged-subdomain-report branch July 31, 2026 02:38
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
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