broker: pre-challenge wildcard CNAME poisons resolver caches against the delegation — DNS-01 first-issuance races a 300s stale window (finish-leg reds) #547

Closed
opened 2026-08-14 22:27:34 +00:00 by ben · 4 comments
Owner

What breaks

Every own-VPS founding races its own DNS caches — and mostly loses. Drives 20260814T202512Z, 214116Z (and 221459Z unless it wins the lottery) all red at the finish leg with the same signature: every Caddy DNS-01 order (wildcard + apex, production + staging fallback) dies on timed out waiting for record to fully propagate, so id.<apex> never answers TLS inside the door budget.

The mechanism (live-probed 22:14–22:26Z, drive 221459Z)

  1. Point time: the challenge fulldomain cannot exist yet (acme-dns registers at first NixOS boot), so the broker honestly writes only apex A + *.<slug> CNAME <slug> (ADR 0100). The wildcard matches _acme-challenge.<slug>.
  2. Caddy starts ordering immediately at first boot — ~100s before the heartbeat's first re-point carries the fulldomain — and its propagation polls prime the pinned public resolvers (1.1.1.1/8.8.8.8) with the WRONG wildcard chain (_acme-challenge → apex, TXT NODATA) at TTL 300.
  3. The heartbeat upserts the real _acme-challenge CNAME + acme.<slug> NS + glue — but each resolver cache node keeps the poisoned chain for up to 300s. Per-attempt propagation timeout (~120s) + certmagic backoff means attempts 1–3 usually straddle stale caches, and the 120×5s door budget expires first. A lottery: drive 171114Z drew a green ("certs first-try"), the next three drew red.

Probe evidence (same instant, 22:24:28Z):

  • @8.8.8.8 → CNAME dced5343-….acme.rehearsal-b.idss.nz, TXT "TVC43ykIqEBpuRFnh0nBIon3jiCiAMbey3A9wn2NQFk" — delegation correct, droplet acme-dns reachable from outside (kills the "syd1 inbound :53" theory).
  • @1.1.1.1 (checker's primary) → still _acme-challenge → rehearsal-b.idss.nz (the stale wildcard chain), TXT empty; converged only at 22:25:58Z. @9.9.9.9 still stale after that.

Fix directed

  • cfDefaultTTL 300 → 60 in broker/internal/broker/zone.go (Cloudflare's explicit floor). Bounds every stale window to one minute so Caddy's second attempt sees the truth. Seam test pins TTL ≤ 60 on all five records PutRecords writes.
  • Redeploy the broker on the mail droplet after landing (same hot-deploy shape as #508's clearance; note on the ticket when built).

Complementary, not sufficient: #532's cert-store persistence (skips issuance on RE-drives only — first foundings still race).

Also observed (note, not this ticket's scope)

After production-CA attempts fail, Caddy falls back to the LE staging CA (order URLs flip to acme-staging-v02) — if a staging cert ever wins, the door serves an untrusted cert. Worth a GOTCHAS eye when this lands.

Filed from the live probe session; #492's deferred 'finish' diagnosis — reporter was limit-parked at filing time.

## What breaks Every own-VPS founding races its own DNS caches — and mostly loses. Drives `20260814T202512Z`, `214116Z` (and `221459Z` unless it wins the lottery) all red at the finish leg with the same signature: every Caddy DNS-01 order (wildcard + apex, production + staging fallback) dies on `timed out waiting for record to fully propagate`, so `id.<apex>` never answers TLS inside the door budget. ## The mechanism (live-probed 22:14–22:26Z, drive 221459Z) 1. Point time: the challenge fulldomain cannot exist yet (acme-dns registers at first NixOS boot), so the broker honestly writes only apex A + `*.<slug> CNAME <slug>` (ADR 0100). **The wildcard matches `_acme-challenge.<slug>`.** 2. Caddy starts ordering immediately at first boot — ~100s before the heartbeat's first re-point carries the fulldomain — and its propagation polls prime the pinned public resolvers (1.1.1.1/8.8.8.8) with the WRONG wildcard chain (`_acme-challenge → apex`, TXT NODATA) at **TTL 300**. 3. The heartbeat upserts the real `_acme-challenge` CNAME + `acme.<slug>` NS + glue — but each resolver cache node keeps the poisoned chain for up to 300s. Per-attempt propagation timeout (~120s) + certmagic backoff means attempts 1–3 usually straddle stale caches, and the 120×5s door budget expires first. A lottery: drive 171114Z drew a green ("certs first-try"), the next three drew red. Probe evidence (same instant, 22:24:28Z): - `@8.8.8.8` → CNAME `dced5343-….acme.rehearsal-b.idss.nz`, TXT `"TVC43ykIqEBpuRFnh0nBIon3jiCiAMbey3A9wn2NQFk"` — delegation correct, droplet acme-dns reachable from outside (kills the "syd1 inbound :53" theory). - `@1.1.1.1` (checker's primary) → still `_acme-challenge → rehearsal-b.idss.nz` (the stale wildcard chain), TXT empty; converged only at 22:25:58Z. `@9.9.9.9` still stale after that. ## Fix directed - `cfDefaultTTL` 300 → **60** in `broker/internal/broker/zone.go` (Cloudflare's explicit floor). Bounds every stale window to one minute so Caddy's second attempt sees the truth. Seam test pins TTL ≤ 60 on all five records PutRecords writes. - Redeploy the broker on the mail droplet after landing (same hot-deploy shape as #508's clearance; note on the ticket when built). Complementary, not sufficient: #532's cert-store persistence (skips issuance on RE-drives only — first foundings still race). ## Also observed (note, not this ticket's scope) After production-CA attempts fail, Caddy falls back to the LE **staging** CA (order URLs flip to acme-staging-v02) — if a staging cert ever wins, the door serves an untrusted cert. Worth a GOTCHAS eye when this lands. Filed from the live probe session; #492's deferred 'finish' diagnosis — reporter was limit-parked at filing time.
Author
Owner

swarm-claim host=elitebook-distributed-server-03 run=6423
(automated multi-host claim — lowest live claim id works this ticket)

swarm-claim host=elitebook-distributed-server-03 run=6423 (automated multi-host claim — lowest live claim id works this ticket)
Author
Owner

close-report for #547 — status success

⛔ close-report gates REFUSED this close — the following claims did not verify:

  • commit d1a3d59 is not reachable from origin/main (not landed on main)
  • changed_files: 'broker/internal/broker/zone.go' is not in the diff of the claimed commits
  • changed_files: 'broker/internal/broker/zone_test.go' is not in the diff of the claimed commits
  • changed_files: 'STATUS.md' is not in the diff of the claimed commits
envelope
{
  "issue": 547,
  "status": "success",
  "commits": [
    "d1a3d59"
  ],
  "changed_files": [
    "broker/internal/broker/zone.go",
    "broker/internal/broker/zone_test.go",
    "STATUS.md"
  ],
  "tests": [
    {
      "command": "nix develop .#go-ci --command go test ./broker/internal/broker/",
      "exit_code": 0
    },
    {
      "command": "nix develop .#go-ci --command golangci-lint run ./internal/broker/",
      "exit_code": 0
    }
  ],
  "criteria": {
    "cfDefaultTTL 300 -> 60 in broker/internal/broker/zone.go": "zone.go: cfDefaultTTL = 60 (Cloudflare's explicit floor), commit d1a3d59",
    "Seam test pins TTL <= 60 on all five records PutRecords writes": "TestCloudflareZone_WritesShortTTLToBoundTheStaleWindow asserts 1..60 on all 5 records (A + wildcard CNAME + challenge CNAME + acme NS + glue A), zone_test.go; go test green",
    "Redeploy the broker on the mail droplet": "Deployment step — not doable from the sandbox; noted on ticket and in STATUS.md/commit as the follow-up for the next iteration/operator"
  },
  "summary": "Broker DNS records now write at Cloudflare's 60s floor instead of 300, bounding the pre-challenge wildcard's stale window so first-issuance DNS-01 stops racing its own resolver caches.",
  "blockers": []
}
**close-report** for #547 — status `success` :no_entry: **close-report gates REFUSED this close** — the following claims did not verify: - commit d1a3d59 is not reachable from origin/main (not landed on main) - changed_files: 'broker/internal/broker/zone.go' is not in the diff of the claimed commits - changed_files: 'broker/internal/broker/zone_test.go' is not in the diff of the claimed commits - changed_files: 'STATUS.md' is not in the diff of the claimed commits <details><summary>envelope</summary> ```json { "issue": 547, "status": "success", "commits": [ "d1a3d59" ], "changed_files": [ "broker/internal/broker/zone.go", "broker/internal/broker/zone_test.go", "STATUS.md" ], "tests": [ { "command": "nix develop .#go-ci --command go test ./broker/internal/broker/", "exit_code": 0 }, { "command": "nix develop .#go-ci --command golangci-lint run ./internal/broker/", "exit_code": 0 } ], "criteria": { "cfDefaultTTL 300 -> 60 in broker/internal/broker/zone.go": "zone.go: cfDefaultTTL = 60 (Cloudflare's explicit floor), commit d1a3d59", "Seam test pins TTL <= 60 on all five records PutRecords writes": "TestCloudflareZone_WritesShortTTLToBoundTheStaleWindow asserts 1..60 on all 5 records (A + wildcard CNAME + challenge CNAME + acme NS + glue A), zone_test.go; go test green", "Redeploy the broker on the mail droplet": "Deployment step — not doable from the sandbox; noted on ticket and in STATUS.md/commit as the follow-up for the next iteration/operator" }, "summary": "Broker DNS records now write at Cloudflare's 60s floor instead of 300, bounding the pre-challenge wildcard's stale window so first-issuance DNS-01 stops racing its own resolver caches.", "blockers": [] } ``` </details>
Author
Owner

close-report for #547 — status success

✅ close-report gates passed — every claim verified against main; closing.

envelope
{
  "issue": 547,
  "status": "success",
  "commits": [
    "d1a3d595412077d81c4b113e819f7b4328ce6e72"
  ],
  "changed_files": [
    "broker/internal/broker/zone.go",
    "broker/internal/broker/zone_test.go",
    "STATUS.md"
  ],
  "tests": [
    {
      "command": "nix develop .#go-ci --command go test ./broker/internal/broker/",
      "exit_code": 0
    },
    {
      "command": "nix develop .#go-ci --command golangci-lint run ./internal/broker/",
      "exit_code": 0
    }
  ],
  "criteria": {
    "cfDefaultTTL 300 -> 60 in broker/internal/broker/zone.go": "zone.go: cfDefaultTTL = 60 (Cloudflare's explicit floor), commit d1a3d59",
    "Seam test pins TTL <= 60 on all five records PutRecords writes": "TestCloudflareZone_WritesShortTTLToBoundTheStaleWindow asserts 1..60 on all 5 records (A + wildcard CNAME + challenge CNAME + acme NS + glue A), zone_test.go; go test green",
    "Redeploy the broker on the mail droplet": "Deployment step — not doable from the sandbox; noted on ticket and in STATUS.md/commit as the follow-up for the next iteration/operator"
  },
  "summary": "Broker DNS records now write at Cloudflare's 60s floor instead of 300, bounding the pre-challenge wildcard's stale window so first-issuance DNS-01 stops racing its own resolver caches.",
  "blockers": []
}
**close-report** for #547 — status `success` :white_check_mark: **close-report gates passed** — every claim verified against main; closing. <details><summary>envelope</summary> ```json { "issue": 547, "status": "success", "commits": [ "d1a3d595412077d81c4b113e819f7b4328ce6e72" ], "changed_files": [ "broker/internal/broker/zone.go", "broker/internal/broker/zone_test.go", "STATUS.md" ], "tests": [ { "command": "nix develop .#go-ci --command go test ./broker/internal/broker/", "exit_code": 0 }, { "command": "nix develop .#go-ci --command golangci-lint run ./internal/broker/", "exit_code": 0 } ], "criteria": { "cfDefaultTTL 300 -> 60 in broker/internal/broker/zone.go": "zone.go: cfDefaultTTL = 60 (Cloudflare's explicit floor), commit d1a3d59", "Seam test pins TTL <= 60 on all five records PutRecords writes": "TestCloudflareZone_WritesShortTTLToBoundTheStaleWindow asserts 1..60 on all 5 records (A + wildcard CNAME + challenge CNAME + acme NS + glue A), zone_test.go; go test green", "Redeploy the broker on the mail droplet": "Deployment step — not doable from the sandbox; noted on ticket and in STATUS.md/commit as the follow-up for the next iteration/operator" }, "summary": "Broker DNS records now write at Cloudflare's 60s floor instead of 300, bounding the pre-challenge wildcard's stale window so first-issuance DNS-01 stops racing its own resolver caches.", "blockers": [] } ``` </details>
ben closed this issue 2026-08-14 22:32:38 +00:00
Author
Owner

AMENDED DIRECTION (read before closing) — #548's forensics on drive 221459Z confirm the mechanism AND narrow the fix: the wildcard issued on its first post-convergence retry, but the APEX order kept failing propagation for the whole run. A poisoned cache node can hold a NEGATIVE answer (TXT NODATA via the wildcard chain) whose TTL rides Cloudflare's SOA minimum (RFC 2308), NOT our record TTL — so TTL 300→60 shrinks the positive-stale window but cannot bound the negative one. Land BOTH: (1) cfDefaultTTL 300→60 + seam test as directed; (2) close the poisoning window at its source — gate Caddy's first start on the delegation being live: a pre-start oneshot (or ExecStartPre) on the gateway that polls dig +short CNAME _acme-challenge.<apex> @1.1.1.1 (and @8.8.8.8) until it returns the acme-dns fulldomain, bounded (~5 min, fail-open with a loud journal line so the door never deadlocks on a broker outage). The heartbeat writes that CNAME ~90s after boot, so the gate typically waits <2 min and saves 3 wasted ACME attempts + the cache poisoning entirely. If the render side is too big for this ticket, land (1) + file the gate as a directed follow-up — do NOT close #547 as sufficient on (1) alone. Staging-flip note for the GOTCHAS entry: certmagic retries against the LE test CA by design after a failed attempt (rate-limit protection) — benign, switches back on success.

**AMENDED DIRECTION (read before closing)** — #548's forensics on drive 221459Z confirm the mechanism AND narrow the fix: the wildcard issued on its first post-convergence retry, but the APEX order kept failing propagation for the whole run. A poisoned cache node can hold a NEGATIVE answer (TXT NODATA via the wildcard chain) whose TTL rides Cloudflare's SOA minimum (RFC 2308), NOT our record TTL — so TTL 300→60 shrinks the positive-stale window but cannot bound the negative one. Land BOTH: (1) cfDefaultTTL 300→60 + seam test as directed; (2) close the poisoning window at its source — gate Caddy's first start on the delegation being live: a pre-start oneshot (or ExecStartPre) on the gateway that polls `dig +short CNAME _acme-challenge.<apex> @1.1.1.1` (and @8.8.8.8) until it returns the acme-dns fulldomain, bounded (~5 min, fail-open with a loud journal line so the door never deadlocks on a broker outage). The heartbeat writes that CNAME ~90s after boot, so the gate typically waits <2 min and saves 3 wasted ACME attempts + the cache poisoning entirely. If the render side is too big for this ticket, land (1) + file the gate as a directed follow-up — do NOT close #547 as sufficient on (1) alone. Staging-flip note for the GOTCHAS entry: certmagic retries against the LE test CA by design after a failed attempt (rate-limit protection) — benign, switches back on success.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
Matou/idss#547
No description provided.