Skip to content

fix(ttl-reaper): make the #438 DNS sweep reachable from make deploy - #453

Merged
scttfrdmn merged 1 commit into
mainfrom
fix/reaper-dns-sweep-deployable
Jul 31, 2026
Merged

scttfrdmn merged 1 commit into
mainfrom
fix/reaper-dns-sweep-deployable

Conversation

@scttfrdmn

Copy link
Copy Markdown
Contributor

Follow-up to #439 (the #438 DNS reconciliation sweep), from verifying that fix live.

The gap

The sweep is correct, but it could not be turned on through the repo's own deploy path.
make deploy never passed DnsSweep — nor DnsZoneId/DnsDomain — in
--parameter-overrides, and sam deploy marks every parameter it isn't given as
UsePreviousValue (deploy_context.py:356).
On an existing stack that silently keeps whatever is deployed; on a fresh stack it falls
back to the template default, false. So the REAPER_DNS_SWEEP knob documented in the
README had no supported way to be set.

This is not hypothetical. Production today:

Changes

  • Makefile: pass DnsZoneId/DnsDomain/DnsSweep explicitly (DNS_ZONE_ID /
    DNS_DOMAIN / DNS_SWEEP, defaulting to the previous behavior — off), with a comment
    explaining the UsePreviousValue trap so the next parameter isn't dropped the same way.
  • README: the enabling invocation; that ROLE_ARNS must list every account with
    records under the zone (the sweep is per-account, deriving each {base36} subdomain
    from the account ID); and a verify section that says to confirm dns-sweep=true on the
    init line rather than assume the feature is live, plus what a sweep hit and a safety
    abort look like in the log.
  • sweepableRecord(): extracted the sweep's in-scope decision, no behavior change.
    It was inline with the paginated ListResourceRecordSets call and therefore untestable,
    despite being the highest-consequence logic in the sweep — a record wrongly judged
    in-scope is a live-DNS outage.

Verification

  • go test ./... green; sam validate passes; gofmt/go vet clean.
  • New TestSweepableRecord covers every exclusion: subdomain apex, zone apex, another
    account's subdomain, a deceptively similar suffix (box.evil-5k0zfnmq.spore.host), the
    Use the AWS account's friendly name (not just base36 account ID) in DNS and elsewhere #121 friendly CNAMEs, and alias A-records. Mutation-checked — removing the alias guard
    fails the test.
  • Live, read-only. Drove the real sweepAccountDNS in dry-run against the live
    spore.host zone. For 4zlw3a1t it logged
    DNS sweep: WOULD delete orphaned A-record win11-test.4zlw3a1t.spore.host -> 13.223.189.34 (no live instance)
    (DNSScanned=1 DNSReaped=1), and spared every alias and out-of-account record. The
    partial-scan safety path was confirmed live too: a cross-account DescribeInstances
    denial logged aborting sweep for this account and deleted nothing.

Nothing was deleted, and no deploy is included here — enabling the sweep in production is
a separate, explicitly-approved step.

Note on gap (1) of #438

#438 also named "Cleanup isn't wired to SIGTERM in cmd/spored". That is in fact already
wired — waitForShutdown() → agent.Cleanup() → DeleteDNS since 0ea9e39 (2026-06-08),
with TimeoutStopSec=30 in the systemd unit. No change needed.

The sweep landed working but unreachable. `make deploy` never passed
DnsSweep (nor DnsZoneId/DnsDomain) in --parameter-overrides, and
`sam deploy` marks every parameter it isn't given as UsePreviousValue:
on an existing stack that silently keeps whatever is already deployed,
and on a fresh stack it falls back to the template default, 'false'.
So the documented REAPER_DNS_SWEEP knob could not be turned on through
the repo's own deploy path — the live production reaper still runs a
pre-#438 build with no REAPER_DNS_SWEEP in its environment at all,
while the spore.host zone holds an orphaned A-record of exactly the
kind #438 exists to reap.

Pass all three DNS parameters explicitly (DNS_ZONE_ID / DNS_DOMAIN /
DNS_SWEEP) and document the enabling invocation, including that
ROLE_ARNS must list every account with records under the zone — the
sweep is per-account, so an account absent from that list is never
reconciled. The verify section now says to confirm dns-sweep=true on
the init line instead of assuming the feature is live, and shows what
a sweep hit and a safety abort each look like in the log.

Also extract the sweep's in-scope decision as a pure sweepableRecord()
(no behavior change). It was inline with the paginated Route53 call and
so untestable, despite being the highest-consequence logic in the sweep
— a record wrongly judged in-scope is a live-DNS outage. Now covered
for each exclusion: the subdomain apex, the zone apex, another
account's subdomain, a deceptively similar suffix, the #121 friendly
CNAMEs, and alias A-records that carry an AWS target rather than an IP.

Verified read-only against the live spore.host zone: driving
sweepAccountDNS in dry-run reconciled the real records and flagged
win11-test.4zlw3a1t.spore.host -> 13.223.189.34 as an orphan (zero live
instances), while sparing every alias and out-of-account record. The
partial-scan safety path was also confirmed live — a cross-account
DescribeInstances denial logged "aborting sweep for this account" and
deleted nothing.
@scttfrdmn
scttfrdmn merged commit 1d35da5 into main Jul 31, 2026
7 checks passed
@scttfrdmn
scttfrdmn deleted the fix/reaper-dns-sweep-deployable branch July 31, 2026 01:00
scttfrdmn added a commit that referenced this pull request Jul 31, 2026
* feat(taskcohort): cohort provider seam for a fungible worker pool (#70 P1)

* feat(taskpool): SQS run-scoped queue + fungible worker pull-loop (#70 P1)

* test(taskpool): queue lifecycle against real Substrate SQS (#70 P1)

* fix(ttl-reaper): pass sam deploy parameters via a params file

Found while performing the deploy #453 made possible: `make deploy` did
not work at all with the parameters #453 added. sam matches the ENTIRE
--parameter-overrides string against one regex, and an empty value
breaks that match. NOTIFY_URL, DNS_ZONE_ID and DNS_DOMAIN are all empty
by default, so the invocation either failed at argument parsing —

  Error: Invalid value for '--parameter-overrides': NotifyUrl= is not a
  valid format.

— or, with the long ParameterKey=…,ParameterValue=… form, fell through
to a different pattern and mis-keyed everything:

  Parameter overrides : {"Environment": "production", "DryRun": "true",
    "ParameterKey": "NotifyUrl,ParameterValue=", ...}

That second form is the dangerous one. The deploy SUCCEEDS, but NotifyUrl
was never overridden and a bogus "ParameterKey" parameter was submitted
instead — a deploy that applies something other than what was asked for,
with no error to notice. Repeating the flag per pair doesn't work either:
the last occurrence wins and the rest are silently dropped.

Generate a file:// params file instead, the only form that accepts empty
values (verified: all eight parameters arrive intact, NotifyUrl as ""),
and echo the mode-setting parameters — dry-run, scan-self, dns-sweep,
zone, domain — so a deploy can never quietly leave a feature off. Not
NotifyUrl: it's a Slack webhook secret and does not belong in a console
or CI log. The generated file is gitignored and removed by `make clean`.

Verified by deploying the reaper for real: parameters landed correctly,
and the live init line now reads dns-sweep=true (sweep enabled, still
dry-run) where before it had no dns-sweep field at all.
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