acme-dns-gate wastes ~4 min polling DNS on the seeded-cert path — short-circuit the gate when Caddy already holds a valid cert (the drive-provable half of #1500 part 1) #1502

Closed
opened 2026-09-15 19:57:21 +00:00 by matou-build-agent · 3 comments

Symptom

Every rented founding spends ~4 min inside the first control-plane switch waiting behind acme-dns-gate (#554/ADR 0014) for _acme-challenge.<slug>.idss.nz to go live on the pinned resolvers — even when the drive has seeded a valid Caddy cert store pre-deploy (#724/ADR 0176), so Caddy will place zero ACME orders this boot. The gate's whole purpose is to keep Caddy's first ACME order from poisoning a resolver's negative cache (#547). When Caddy already holds a valid cert for the identifier set, there is no first order to protect, so the gate's poll is pure wall-clock waste — the ~4 min the phase-9 drives burn on every fire (#1500 runs 20260915T155605Z, 20260915T164205Z).

This is the residue #1500 left open: #1500 proved the delegation cannot be published at claim (its target is the acme-dns fulldomain, a random per-registration value the box only generates at first boot; the broker learns it only via the post-boot heartbeat — ADR 0136 delegation-reconcile), so for a genuine first founding the ~4 min is a real floor. But the seeded-cert path (rehearsal re-drives AND production ADR-0176 re-foundings) needn't pay it.

Proposed fix

acme-dns-gate (internal/clan/acmedns.go acmednsGateScript) short-circuits exit 0 at the top when Caddy's storage already holds a currently-valid certificate covering the challenge apex (e.g. a non-expired *.crt under /var/lib/caddy/.local/share/caddy/certificates/** matching <apex> / *.<apex>, checked with openssl x509 -checkend). No valid cert → poll exactly as today (the first-founding path is untouched). The gate is already fail-open (every exit is 0), so a mis-detection is bounded to the existing fail-open behaviour — but the short-circuit must be conservative (a false "cert present" would let Caddy order early against a not-yet-live delegation and reopen the #547 poisoning window), which is why this wants its own red→green seam test and a rented drive to prove the wall-time drop, not a blind land.

Acceptance

  • With a valid seeded cert, acme-dns-gate exits 0 without polling; the clan-switch-gateway-*.service: Consumed … wall clock time line drops the DNS-propagation wait on the seeded path.
  • With no valid cert (genuine first founding), the gate polls exactly as today — proven by the existing TestRenderAcmeDNS_GatesCaddyOnDelegationLive plus a new "skips the poll when a valid cert is already staged" render/seam test.
  • Measured before/after on a rented-services drive's logs/droplet-journal.txt.

Found while working

#1500 (the switch stall + self-admit status 4). Filed as the drive-provable half of #1500's part 1; #1500 shipped the status-4 fix and documented this floor.

## Symptom Every rented founding spends ~4 min inside the first control-plane switch waiting behind `acme-dns-gate` (#554/ADR 0014) for `_acme-challenge.<slug>.idss.nz` to go live on the pinned resolvers — even when the drive has **seeded a valid Caddy cert store pre-deploy** (#724/ADR 0176), so Caddy will place **zero** ACME orders this boot. The gate's whole purpose is to keep Caddy's *first ACME order* from poisoning a resolver's negative cache (#547). When Caddy already holds a valid cert for the identifier set, there is no first order to protect, so the gate's poll is pure wall-clock waste — the ~4 min the phase-9 drives burn on every fire (#1500 runs `20260915T155605Z`, `20260915T164205Z`). This is the residue #1500 left open: #1500 proved the delegation **cannot** be published at claim (its target is the acme-dns `fulldomain`, a random per-registration value the box only generates at first boot; the broker learns it only via the post-boot heartbeat — ADR 0136 delegation-reconcile), so for a **genuine first founding** the ~4 min is a real floor. But the **seeded-cert path** (rehearsal re-drives AND production ADR-0176 re-foundings) needn't pay it. ## Proposed fix `acme-dns-gate` (`internal/clan/acmedns.go` `acmednsGateScript`) short-circuits `exit 0` at the top when Caddy's storage already holds a **currently-valid** certificate covering the challenge apex (e.g. a non-expired `*.crt` under `/var/lib/caddy/.local/share/caddy/certificates/**` matching `<apex>` / `*.<apex>`, checked with `openssl x509 -checkend`). No valid cert → poll exactly as today (the first-founding path is untouched). The gate is already **fail-open** (every exit is 0), so a mis-detection is bounded to the existing fail-open behaviour — but the short-circuit must be conservative (a false "cert present" would let Caddy order early against a not-yet-live delegation and reopen the #547 poisoning window), which is why this wants its own red→green seam test **and a rented drive to prove the wall-time drop**, not a blind land. ## Acceptance - With a valid seeded cert, `acme-dns-gate` exits 0 without polling; the `clan-switch-gateway-*.service: Consumed … wall clock time` line drops the DNS-propagation wait on the seeded path. - With no valid cert (genuine first founding), the gate polls exactly as today — proven by the existing `TestRenderAcmeDNS_GatesCaddyOnDelegationLive` plus a new "skips the poll when a valid cert is already staged" render/seam test. - Measured before/after on a `rented-services` drive's `logs/droplet-journal.txt`. ## Found while working #1500 (the switch stall + self-admit status 4). Filed as the drive-provable half of #1500's part 1; #1500 shipped the status-4 fix and documented this floor.
Author
Member

This was generated by AI during triage.

Triage — enhancement + ready-for-agent

Claim verified against the code. acmednsGateScript (internal/clan/acmedns.go:328) reads the published fulldomain fact and, whenever it is non-empty, polls the pinned resolvers seq 1 60 × sleep 5 (~5 min budget) before releasing Caddy — with no check for an already-valid cert. So the seeded-cert path (#724/ADR 0176; the store staged into /var/lib/caddy/.local/share/caddy — internal/certpersist StorageRoot) pays the full propagation wait even though Caddy will place zero ACME orders that boot. The ~4 min and the #547 poisoning window the gate exists to protect are both real and correctly described. Redundancy check: no existing short-circuit — the gate has only the three exit-0 paths (fact-absent, converged, budget-spent). No .out-of-scope/ match.

Ruled by agent under ADR 0174 — veto anytime

The call: the acceptance criterion "a rented drive to prove the wall-time drop … Measured before/after on a rented-services drive's logs/droplet-journal.txt" is the only thing that could push this off ready-for-agent (live infra / droplet creds → normally ready-for-session). Ruling: ready-for-agent. The agent-doable deliverable is the code short-circuit + a new red→green render/seam test; the rented-drive wall-time proof rides the rehearsal-executor rail (matou-workstation, which holds the droplet creds and polls the drive issue), not the swarm worker — exactly the split that let the parent #1500 ship ready-for-agent and prove 28/28 on a rented gateway. The rehearsal-report.sh rail auto-applies rehearsal-183/priority when the drive fires; no need to pre-apply here.

Why it's a two-way door: revertible by a single commit; the gate is already fail-open (every exit is 0), so a mis-detection is bounded to existing behaviour; and it is provable by the existing TestRenderAcmeDNS_GatesCaddyOnDelegationLive + the new "skips the poll when a valid cert is staged" test + the drive journal's wall-clock line. Not on the one-way-door list: no personal credentials, no security-posture widening (the fail-open contract is unchanged and the short-circuit is conservative + test-gated), no member-facing trust accept, no data destruction, no non-routine spend (rehearsal drives are routine).


Agent brief

Goal. acme-dns-gate must exit 0 at the top of acmednsGateScript — before the poll loop — when Caddy's storage already holds a currently-valid certificate covering the challenge apex, so the seeded-cert path (rehearsal re-drives and production ADR-0176 re-foundings) skips the ~4 min DNS-propagation wait. No valid cert → poll exactly as today (the genuine-first-founding path is untouched).

The change (internal/clan/acmedns.go, acmednsGateScript):

  • Insert a short-circuit ahead of the existing want= / fulldomain logic (or immediately after set -uo pipefail): scan Caddy's cert store under /var/lib/caddy/.local/share/caddy/certificates/** for a non-expired *.crt whose subject/SAN covers $apex or *.$apex, using openssl x509 -checkend <seconds> -noout -in <crt>. If one is found, log a loud journal line ("valid cert already staged for $apex — no first ACME order to protect, skipping delegation poll") and exit 0.
  • Be conservative — a false "cert present" lets Caddy order early against a not-yet-live delegation and reopens the #547 poisoning window. Match the apex explicitly (don't release on any random cert in the store); pick a -checkend margin that is safely non-zero. Keep the $var-only shell style (no ${...}) the file documents at internal/clan/acmedns.go:324-327 so the Nix here-string needs no antiquotation escaping.
  • Reference internal/certpersist StorageRoot/StateRoot for the paths rather than re-hardcoding where practical.

Tests (internal/clan/acmedns_test.go, model on TestRenderAcmeDNS_GatesCaddyOnDelegationLive / TestRenderAcmeDNS_GateIsFailOpen):

  • New render test: the gate script contains the valid-cert short-circuit — the openssl x509 -checkend check against the apex cert path and an exit 0 on the cert-present branch, ordered before the seq 1 60 poll.
  • Confirm the unchanged paths still assert: TestRenderAcmeDNS_GatesCaddyOnDelegationLive (poll present) and TestRenderAcmeDNS_GateIsFailOpen (no exit 1, bounded budget, loud budget-spent line) must still pass — the short-circuit must not weaken them.

Acceptance (from the issue):

  • With a valid seeded cert, the gate exits 0 without polling; clan-switch-gateway-*.service: Consumed … wall clock time drops the DNS-propagation wait on the seeded path.
  • With no valid cert, the gate polls exactly as today (proven by the retained TestRenderAcmeDNS_GatesCaddyOnDelegationLive + the new render test).
  • Wall-time before/after measured on a rented-services drive's logs/droplet-journal.txt — supplied by the rehearsal-executor rail, not this worker.

Files: internal/clan/acmedns.go (acmednsGateScript), internal/clan/acmedns_test.go. Parent: #1500 (shipped the status-4 fix; documented this floor). Related: #554/ADR 0014 (the gate), #547 (the poisoning window), #724/ADR 0176 + GOTCHAS #32 (the seeded store).

> *This was generated by AI during triage.* ## Triage — `enhancement` + `ready-for-agent` **Claim verified against the code.** `acmednsGateScript` (`internal/clan/acmedns.go:328`) reads the published `fulldomain` fact and, whenever it is non-empty, polls the pinned resolvers `seq 1 60` × `sleep 5` (~5 min budget) before releasing Caddy — with **no** check for an already-valid cert. So the seeded-cert path (`#724`/ADR 0176; the store staged into `/var/lib/caddy/.local/share/caddy` — `internal/certpersist` `StorageRoot`) pays the full propagation wait even though Caddy will place zero ACME orders that boot. The `~4 min` and the `#547` poisoning window the gate exists to protect are both real and correctly described. Redundancy check: no existing short-circuit — the gate has only the three exit-0 paths (fact-absent, converged, budget-spent). No `.out-of-scope/` match. ## Ruled by agent under ADR 0174 — veto anytime **The call:** the acceptance criterion "a rented drive to prove the wall-time drop … Measured before/after on a `rented-services` drive's `logs/droplet-journal.txt`" is the only thing that could push this off `ready-for-agent` (live infra / droplet creds → normally `ready-for-session`). **Ruling: `ready-for-agent`.** The agent-doable deliverable is the code short-circuit + a new red→green render/seam test; the rented-drive wall-time proof rides the **rehearsal-executor** rail (matou-workstation, which holds the droplet creds and polls the drive issue), not the swarm worker — exactly the split that let the parent **#1500** ship `ready-for-agent` and prove 28/28 on a rented gateway. The `rehearsal-report.sh` rail auto-applies `rehearsal-183`/`priority` when the drive fires; no need to pre-apply here. **Why it's a two-way door:** revertible by a single commit; the gate is already fail-open (every exit is 0), so a mis-detection is bounded to existing behaviour; and it is provable by the existing `TestRenderAcmeDNS_GatesCaddyOnDelegationLive` + the new "skips the poll when a valid cert is staged" test + the drive journal's wall-clock line. **Not on the one-way-door list:** no personal credentials, no security-posture widening (the fail-open contract is unchanged and the short-circuit is conservative + test-gated), no member-facing trust accept, no data destruction, no non-routine spend (rehearsal drives are routine). --- ## Agent brief **Goal.** `acme-dns-gate` must `exit 0` at the top of `acmednsGateScript` — before the poll loop — when Caddy's storage already holds a **currently-valid** certificate covering the challenge apex, so the seeded-cert path (rehearsal re-drives and production ADR-0176 re-foundings) skips the ~4 min DNS-propagation wait. No valid cert → poll exactly as today (the genuine-first-founding path is untouched). **The change** (`internal/clan/acmedns.go`, `acmednsGateScript`): - Insert a short-circuit ahead of the existing `want=` / fulldomain logic (or immediately after `set -uo pipefail`): scan Caddy's cert store under `/var/lib/caddy/.local/share/caddy/certificates/**` for a non-expired `*.crt` whose subject/SAN covers `$apex` or `*.$apex`, using `openssl x509 -checkend <seconds> -noout -in <crt>`. If one is found, log a loud journal line ("valid cert already staged for $apex — no first ACME order to protect, skipping delegation poll") and `exit 0`. - **Be conservative** — a false "cert present" lets Caddy order early against a not-yet-live delegation and reopens the `#547` poisoning window. Match the apex explicitly (don't release on any random cert in the store); pick a `-checkend` margin that is safely non-zero. Keep the `$var`-only shell style (no `${...}`) the file documents at `internal/clan/acmedns.go:324-327` so the Nix here-string needs no antiquotation escaping. - Reference `internal/certpersist` `StorageRoot`/`StateRoot` for the paths rather than re-hardcoding where practical. **Tests** (`internal/clan/acmedns_test.go`, model on `TestRenderAcmeDNS_GatesCaddyOnDelegationLive` / `TestRenderAcmeDNS_GateIsFailOpen`): - New render test: the gate script contains the valid-cert short-circuit — the `openssl x509 -checkend` check against the apex cert path and an `exit 0` on the cert-present branch, ordered *before* the `seq 1 60` poll. - Confirm the unchanged paths still assert: `TestRenderAcmeDNS_GatesCaddyOnDelegationLive` (poll present) and `TestRenderAcmeDNS_GateIsFailOpen` (no `exit 1`, bounded budget, loud budget-spent line) must still pass — the short-circuit must not weaken them. **Acceptance** (from the issue): - With a valid seeded cert, the gate exits 0 without polling; `clan-switch-gateway-*.service: Consumed … wall clock time` drops the DNS-propagation wait on the seeded path. - With no valid cert, the gate polls exactly as today (proven by the retained `TestRenderAcmeDNS_GatesCaddyOnDelegationLive` + the new render test). - Wall-time before/after measured on a `rented-services` drive's `logs/droplet-journal.txt` — supplied by the rehearsal-executor rail, not this worker. **Files:** `internal/clan/acmedns.go` (`acmednsGateScript`), `internal/clan/acmedns_test.go`. Parent: **#1500** (shipped the status-4 fix; documented this floor). Related: `#554`/ADR 0014 (the gate), `#547` (the poisoning window), `#724`/ADR 0176 + GOTCHAS #32 (the seeded store).
Author
Member

swarm-claim host=matou-dev-server-01 run=24733
(automated multi-host claim — lowest live claim id works this ticket)

swarm-claim host=matou-dev-server-01 run=24733 (automated multi-host claim — lowest live claim id works this ticket)
Author
Member

close-report for #1502 — status success

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

envelope
{
  "issue": 1502,
  "status": "success",
  "commits": [
    "1bfff1cf"
  ],
  "changed_files": [
    "STATUS.md",
    "internal/clan/acmedns.go",
    "internal/clan/acmedns_test.go"
  ],
  "tests": [
    {
      "command": "go test ./internal/clan/ ./internal/certpersist/",
      "exit_code": 0
    },
    {
      "command": "go vet ./internal/clan/",
      "exit_code": 0
    },
    {
      "command": "go build ./...",
      "exit_code": 0
    }
  ],
  "criteria": {
    "With a valid seeded cert, acme-dns-gate exits 0 without polling; the switch service's wall clock drops the DNS-propagation wait on the seeded path": "internal/clan/acmedns.go acmednsGateScript: short-circuit scans certpersist.StorageRoot/certificates and `exit 0`s before the seq 1 60 poll when a non-expired cert (openssl x509 -checkend 2592000) carries $apex/*.$apex as a SAN; verified executing against a crafted valid-apex cert (throwaway exec test, case1). Wall-time before/after supplied by the rehearsal-executor rail on the next rented-services drive.",
    "With no valid cert (genuine first founding), the gate polls exactly as today — proven by TestRenderAcmeDNS_GatesCaddyOnDelegationLive plus a new skips-the-poll render/seam test": "TestRenderAcmeDNS_GatesCaddyOnDelegationLive retained green (poll unchanged); new TestRenderAcmeDNS_GateSkipsPollWhenValidCertStaged asserts the short-circuit is ordered BEFORE seq 1 60; exec test cases 2-4 (different-apex, near-expiry, substring) fall through to poll/fail-open.",
    "Measured before/after on a rented-services drive's logs/droplet-journal.txt": "Executor-rail deliverable (matou-workstation holds droplet creds), per the ADR-0174 ruling in the issue comments; the agent-doable code short-circuit + red-green render/seam test is shipped here."
  },
  "summary": "acme-dns delegation gate short-circuits exit 0 on a valid seeded cert covering the apex, skipping the ~4-min DNS-propagation poll while staying conservative and fail-open.",
  "reason": "",
  "blockers": []
}
**close-report** for #1502 — status `success` :white_check_mark: **close-report gates passed** — every claim verified against main; issue closed. <details><summary>envelope</summary> ```json { "issue": 1502, "status": "success", "commits": [ "1bfff1cf" ], "changed_files": [ "STATUS.md", "internal/clan/acmedns.go", "internal/clan/acmedns_test.go" ], "tests": [ { "command": "go test ./internal/clan/ ./internal/certpersist/", "exit_code": 0 }, { "command": "go vet ./internal/clan/", "exit_code": 0 }, { "command": "go build ./...", "exit_code": 0 } ], "criteria": { "With a valid seeded cert, acme-dns-gate exits 0 without polling; the switch service's wall clock drops the DNS-propagation wait on the seeded path": "internal/clan/acmedns.go acmednsGateScript: short-circuit scans certpersist.StorageRoot/certificates and `exit 0`s before the seq 1 60 poll when a non-expired cert (openssl x509 -checkend 2592000) carries $apex/*.$apex as a SAN; verified executing against a crafted valid-apex cert (throwaway exec test, case1). Wall-time before/after supplied by the rehearsal-executor rail on the next rented-services drive.", "With no valid cert (genuine first founding), the gate polls exactly as today — proven by TestRenderAcmeDNS_GatesCaddyOnDelegationLive plus a new skips-the-poll render/seam test": "TestRenderAcmeDNS_GatesCaddyOnDelegationLive retained green (poll unchanged); new TestRenderAcmeDNS_GateSkipsPollWhenValidCertStaged asserts the short-circuit is ordered BEFORE seq 1 60; exec test cases 2-4 (different-apex, near-expiry, substring) fall through to poll/fail-open.", "Measured before/after on a rented-services drive's logs/droplet-journal.txt": "Executor-rail deliverable (matou-workstation holds droplet creds), per the ADR-0174 ruling in the issue comments; the agent-doable code short-circuit + red-green render/seam test is shipped here." }, "summary": "acme-dns delegation gate short-circuits exit 0 on a valid seeded cert covering the apex, skipping the ~4-min DNS-propagation poll while staying conservative and fail-open.", "reason": "", "blockers": [] } ``` </details>
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.

Dependencies

No dependencies set.

Reference
Matou/idss#1502
No description provided.