gateway: the address heartbeat — keep a residential gateway's DNS record current #330

Closed
opened 2026-08-07 17:32:52 +00:00 by ben · 2 comments
Owner

A gateway on a residential connection usually has a dynamic public IP. Nothing in the fleet observes or re-derives it, so when the ISP rotates the address the community goes dark until a human notices.

Standup.GatewayIP is set exactly once (internal/founding/standup.go:481) and PointSubdomain is called exactly once, during founding, from the operator's laptop (standup.go:632). ADR 0014 already names the future problem: "The revisit trigger is gateway-IP churn becoming a support burden."

Why this is small

  • The re-point primitive exists. Zone.PutRecords is documented as "creates or repoints" (broker/internal/broker/broker.go:69-74), implemented as a real upsert (zone.go:283-299), and returns only once the record answers from the authoritative NS (zone.go:377-400). Calling it twice for a slug is already safe.
  • Discovery exists. internal/dns/resolver.go:24-42 reflects the connection's public address off myip.opendns.com — written for the CGNAT pre-check, reusable as-is (a gateway behind NAT cannot read its own public address from an interface).
  • A home for the loop exists. control-plane already runs go c.mon.Run(context.Background(), aggregationInterval) (control-plane/cmd/control-plane/main.go:481), gated on c.whole. A second goroutine beside it needs no new binary, no systemd unit, no supply step and no Nix change — which also sidesteps the Attach-layer blocker.

What is missing

  1. Blocked on the broker security ticket. A loop calling /point on a timer over an unauthenticated endpoint with a volatile ledger makes that exposure materially worse. Nothing here starts before that lands.
  2. No fleet-to-broker path. internal/brokerclient has one production consumer, the operator app helper (app/helper/cmd/helper/wiring_prod.go:237); control-plane/ does not import it, and holds no broker credential.
  3. Failure posture. Per ADR 0100 / ADR 0071 a heartbeat that cannot write must raise a standing named state — a silently stale record is exactly the "absence read as healthy" ADR 0071 forbids.
  4. The acme-dns coupling. internal/clan/acmedns.go:135-137 embeds the gateway IP in the delegated zone's NS and glue A records, so an address change invalidates certificate issuance, not just service routing. Either the heartbeat rewrites glue too, or acme-dns learns its address at runtime instead of render time. Cheaper to design in now, since RenderAcmeDNS has no attach step yet.

Scope boundary that needs ruling

This can only ever work on the <slug>.idss.nz path. The Zone port is bound to that apex by construction (Issuer.slugOf, broker.go:233-244; the Cloudflare token is zone-scoped, zone.go:81-86) and ADR 0049 §2 refuses registrar API integration outright: "No API integration with arbitrary registrars — an unbounded surface, refused." Own-domain communities are architecturally excluded, not merely unbuilt.

Accepting that split honestly is probably right, but it is Ben's call — and it means own-domain + residential stays a manual-fix posture.

Alternative considered

A heartbeat channel already exists end-to-end on the ingest side (enroll.FleetReporting.Report -> monitor.HeartbeatStream, internal/monitor/stream.go:31-63, arrival-stamped, StaleAfter 5 min, ADR 0071 silence classification). But StatusReport carries no address field, the agent has no periodic emit loop yet, and the agent never runs on the gateway by design (agent/cmd/agent/main.go:1-5). Riding it is possible but not cheaper.

Background: docs/research/2026-08-07-home-gateway-reachability-scope.md §4.

A gateway on a residential connection usually has a **dynamic** public IP. Nothing in the fleet observes or re-derives it, so when the ISP rotates the address the community goes dark until a human notices. `Standup.GatewayIP` is set exactly once (`internal/founding/standup.go:481`) and `PointSubdomain` is called exactly once, during founding, from the operator's laptop (`standup.go:632`). ADR 0014 already names the future problem: *"The revisit trigger is gateway-IP churn becoming a support burden."* ## Why this is small - **The re-point primitive exists.** `Zone.PutRecords` is documented as "creates or **repoints**" (`broker/internal/broker/broker.go:69-74`), implemented as a real upsert (`zone.go:283-299`), and returns only once the record answers from the authoritative NS (`zone.go:377-400`). Calling it twice for a slug is already safe. - **Discovery exists.** `internal/dns/resolver.go:24-42` reflects the connection's public address off `myip.opendns.com` — written for the CGNAT pre-check, reusable as-is (a gateway behind NAT cannot read its own public address from an interface). - **A home for the loop exists.** `control-plane` already runs `go c.mon.Run(context.Background(), aggregationInterval)` (`control-plane/cmd/control-plane/main.go:481`), gated on `c.whole`. A second goroutine beside it needs no new binary, no systemd unit, no supply step and no Nix change — which also sidesteps the Attach-layer blocker. ## What is missing 1. **Blocked on the broker security ticket.** A loop calling `/point` on a timer over an unauthenticated endpoint with a volatile ledger makes that exposure materially worse. Nothing here starts before that lands. 2. **No fleet-to-broker path.** `internal/brokerclient` has one production consumer, the operator app helper (`app/helper/cmd/helper/wiring_prod.go:237`); `control-plane/` does not import it, and holds no broker credential. 3. **Failure posture.** Per ADR 0100 / ADR 0071 a heartbeat that cannot write must raise a standing named state — a silently stale record is exactly the "absence read as healthy" ADR 0071 forbids. 4. **The acme-dns coupling.** `internal/clan/acmedns.go:135-137` embeds the gateway IP in the delegated zone's NS and glue A records, so an address change invalidates certificate issuance, not just service routing. Either the heartbeat rewrites glue too, or acme-dns learns its address at runtime instead of render time. Cheaper to design in now, since `RenderAcmeDNS` has no attach step yet. ## Scope boundary that needs ruling This can only ever work on the **`<slug>.idss.nz`** path. The `Zone` port is bound to that apex by construction (`Issuer.slugOf`, `broker.go:233-244`; the Cloudflare token is zone-scoped, `zone.go:81-86`) and ADR 0049 §2 refuses registrar API integration outright: *"No API integration with arbitrary registrars — an unbounded surface, refused."* Own-domain communities are architecturally excluded, not merely unbuilt. Accepting that split honestly is probably right, but it is Ben's call — and it means own-domain + residential stays a manual-fix posture. ## Alternative considered A heartbeat channel already exists end-to-end on the ingest side (`enroll.FleetReporting.Report` -> `monitor.HeartbeatStream`, `internal/monitor/stream.go:31-63`, arrival-stamped, `StaleAfter` 5 min, ADR 0071 silence classification). But `StatusReport` carries no address field, the agent has no periodic emit loop yet, and the agent never runs on the gateway by design (`agent/cmd/agent/main.go:1-5`). Riding it is possible but not cheaper. Background: `docs/research/2026-08-07-home-gateway-reachability-scope.md` §4.
Author
Owner

Ruled by Ben 2026-08-08 (decision sweep) → ADR 0136 (1716193, on main): the heartbeat is <slug>.idss.nz-only (own-domain + residential is accepted as a stated manual-fix posture — honest copy, not implication), lives as a control-plane goroutine beside the monitor loop, and rewrites every address-bearing record including the acme-dns NS/glue — a healed A record with broken cert issuance is not healed. A heartbeat that cannot write raises a standing named state (ADR 0071/0100). Auth is the claim secret (ADR 0135) reaching the gateway via the vars machinery (sops). Blocked on #322 landing → agent-blocked; flip to ready-for-agent when #322 closes.

Ruled by Ben 2026-08-08 (decision sweep) → **ADR 0136** (`1716193`, on main): the heartbeat is **`<slug>.idss.nz`-only** (own-domain + residential is accepted as a stated manual-fix posture — honest copy, not implication), lives as a **`control-plane` goroutine** beside the monitor loop, and **rewrites every address-bearing record including the acme-dns NS/glue** — a healed A record with broken cert issuance is not healed. A heartbeat that cannot write raises a standing named state (ADR 0071/0100). Auth is the claim secret (ADR 0135) reaching the gateway via the vars machinery (sops). Blocked on #322 landing → `agent-blocked`; flip to `ready-for-agent` when #322 closes.
Author
Owner

Implemented in da024fa (on origin/main).

Per Ben's ruling (ADR 0136), the address heartbeat now keeps a residential gateway's <slug>.idss.nz record current against dynamic-IP churn.

What shipped:

  • internal/heartbeat — the engine (seam): a Discoverer port (the gateway's public address) + a Repointer port (the broker /point upsert), and a Tick that re-points only when the observed address changed or a prior write is still owed. Red-first seam tests cover: unchanged→silent, changed→point, no-seed self-heal, failed-write raises a standing repoint-failed state (keeps last-known-good, records pending IP, holds raised-at) then clears on recovery, discovery gap is never green, a discovery gap does not mask a known-stale record, and Run ticks-then-cancels.
  • internal/dns.PublicIP — exports the CGNAT pre-check's OpenDNS reflection lookup, reused as-is (honest from behind NAT).
  • internal/brokerclient.IssuanceApex — the idss scope boundary constant.
  • control-plane/cmd/control-plane/main.go — first brokerclient import; the goroutine starts beside the monitor loop, gated on its own wiring (community apex under idss.nz and OURCLOUD_CLAIM_SECRET present), else rests loud (ADR 0100). The re-point rewrites the whole broker-owned record family (slug A + *.<slug> wildcard + _acme-challenge CNAME) in one call and threads the gateway's published acme-dns fulldomain so cert issuance re-points with routing. Wiring tests cover rest (no apex / own-domain / no-secret) and wire (idss+secret).
  • STATUS.md — header lead + milestone log.

Failure posture (ADR 0071/0100): success is silent; a write that cannot land raises a standing named state that stays live until a later write succeeds — never a silently-stale record.

Scope honoured: idss-only (own-domain + residential is a stated manual posture, ADR 0049/0136).

Follow-up (noted in STATUS header): the gateway-side acme-dns daemon glue (internal/clan/acmedns.go) has no production attach caller yet, so its rewrite rides the future deploy path; folding the heartbeat's standing state into the monitor's alert set is the next slice (the engine holds it queryably + logs it loud today).

Verified: go build/go test/go vet/golangci-lint/gofmt green; the pre-push gate (whole-tree Go stages) passed.

Implemented in `da024fa` (on `origin/main`). Per Ben's ruling (ADR 0136), the address heartbeat now keeps a residential gateway's `<slug>.idss.nz` record current against dynamic-IP churn. **What shipped:** - `internal/heartbeat` — the engine (seam): a `Discoverer` port (the gateway's public address) + a `Repointer` port (the broker `/point` upsert), and a `Tick` that re-points only when the observed address changed or a prior write is still owed. Red-first seam tests cover: unchanged→silent, changed→point, no-seed self-heal, failed-write raises a **standing** `repoint-failed` state (keeps last-known-good, records pending IP, holds raised-at) then clears on recovery, discovery gap is never green, a discovery gap does not mask a known-stale record, and `Run` ticks-then-cancels. - `internal/dns.PublicIP` — exports the CGNAT pre-check's OpenDNS reflection lookup, reused as-is (honest from behind NAT). - `internal/brokerclient.IssuanceApex` — the idss scope boundary constant. - `control-plane/cmd/control-plane/main.go` — first `brokerclient` import; the goroutine starts beside the monitor loop, gated on its own wiring (community apex under `idss.nz` **and** `OURCLOUD_CLAIM_SECRET` present), else rests loud (ADR 0100). The re-point rewrites the whole broker-owned record family (slug A + `*.<slug>` wildcard + `_acme-challenge` CNAME) in one call and threads the gateway's published acme-dns fulldomain so cert issuance re-points with routing. Wiring tests cover rest (no apex / own-domain / no-secret) and wire (idss+secret). - `STATUS.md` — header lead + milestone log. **Failure posture (ADR 0071/0100):** success is silent; a write that cannot land raises a standing named state that stays live until a later write succeeds — never a silently-stale record. **Scope honoured:** idss-only (own-domain + residential is a stated manual posture, ADR 0049/0136). **Follow-up (noted in STATUS header):** the gateway-side acme-dns *daemon* glue (`internal/clan/acmedns.go`) has no production attach caller yet, so its rewrite rides the future deploy path; folding the heartbeat's standing state into the monitor's alert set is the next slice (the engine holds it queryably + logs it loud today). Verified: `go build`/`go test`/`go vet`/`golangci-lint`/`gofmt` green; the pre-push gate (whole-tree Go stages) passed.
ben closed this issue 2026-08-09 01:11:11 +00:00
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#330
No description provided.