Broker front hides the peer: POST /v1/reachability/self dials 127.0.0.1, so the self-probe never observes the caller's line (GOTCHAS #250) #2010

Closed
opened 2026-09-30 03:14:04 +00:00 by ben · 2 comments
Owner

Observed 2026-09-29 from a home laptop (Colombia, 177.255.202.2):

$ curl -X POST https://broker.idss.nz/v1/reachability/self
{"host":"","address":"127.0.0.1","vantage":"broker.idss.nz","groups":[{"group":"web","required":true,"verdict":"open","ports":[{"port":80,"verdict":"open"},{"port":443,"verdict":"open"}]}],...}

The route reads RemoteAddr (by design — ADR 0253: never a caller-supplied header, or it becomes an open dialer). Behind the broker's reverse proxy that peer is the proxy's loopback, so the broker dials itself and reports open for every caller. GOTCHAS #250 names the fix: the front must preserve the real peer (the PROXY protocol between the proxy and the broker), never X-Forwarded-For.

Why it matters now: cmd/gateway-check (the pre-founding checker, built 2026-09-29 on session/gateway-check) is the first consumer. It compares the observed address with the machine's OpenDNS address and honestly reports outside-in unproven on a mismatch — so today no operator can get an outside-in answer, and founding's Connect-section check (DDR 0240) inherits the same blind spot when it moves onto this route.

Ask (Ben): this is a security-posture change on a deployed Matou service (ADR 0174 §3) — rule the PROXY-protocol front (Caddy servers { listener_wrappers { proxy_protocol } } on the broker's listener, or the equivalent for whatever fronts it), and whether the broker should REFUSE to probe a loopback/private RemoteAddr (it is never a real caller) rather than dial it.

Acceptance: the curl above from a home line returns that line's public address; gateway-check on a machine with 80/443 forwarded reads ✓ visitors … your port forwarding works.

**Observed 2026-09-29** from a home laptop (Colombia, 177.255.202.2): ``` $ curl -X POST https://broker.idss.nz/v1/reachability/self {"host":"","address":"127.0.0.1","vantage":"broker.idss.nz","groups":[{"group":"web","required":true,"verdict":"open","ports":[{"port":80,"verdict":"open"},{"port":443,"verdict":"open"}]}],...} ``` The route reads `RemoteAddr` (by design — ADR 0253: never a caller-supplied header, or it becomes an open dialer). Behind the broker's reverse proxy that peer is the proxy's loopback, so the broker dials **itself** and reports `open` for every caller. GOTCHAS #250 names the fix: the front must preserve the real peer (the **PROXY protocol** between the proxy and the broker), never X-Forwarded-For. **Why it matters now:** `cmd/gateway-check` (the pre-founding checker, built 2026-09-29 on `session/gateway-check`) is the first consumer. It compares the observed `address` with the machine's OpenDNS address and honestly reports *outside-in unproven* on a mismatch — so today no operator can get an outside-in answer, and founding's Connect-section check (DDR 0240) inherits the same blind spot when it moves onto this route. **Ask (Ben):** this is a security-posture change on a deployed Matou service (ADR 0174 §3) — rule the PROXY-protocol front (Caddy `servers { listener_wrappers { proxy_protocol } }` on the broker's listener, or the equivalent for whatever fronts it), and whether the broker should REFUSE to probe a loopback/private `RemoteAddr` (it is never a real caller) rather than dial it. **Acceptance:** the curl above from a home line returns that line's public address; `gateway-check` on a machine with 80/443 forwarded reads `✓ visitors … your port forwarding works`.
Author
Owner

Ruled by Ben 2026-10-05 ("I want the tool to answer itself") — BUILT, on main as f2a9f1c7 (2026-10-06).

  • broker/internal/proxyproto: with BROKER_PROXY_PROTOCOL=1 every accepted connection must open with a PROXY protocol v2 header (what Caddy's transport http { proxy_protocol v2 } sends) and the header's source becomes RemoteAddr; a header-less connection is dropped, never served. No X-Forwarded-For is read (ADR 0253 holds). Note: the Caddy syntax in this ticket's body (listener_wrappers { proxy_protocol }) is the wrong direction — that is Caddy receiving PROXY; the fix needs Caddy sending it to the upstream.
  • The self-probe now refuses a loopback/private/link-local/CGNAT peer with a 400 naming the address seen, and dials nothing — the second question in the ask, answered yes.
  • Seam tests drive the route through the PROXY listener with a claimed public peer, plus the refusal and the header-less drop. GOTCHAS #250 carries the closing entry; ADR 0253 is amended.

Cutover (hands-on, root on the mail droplet — the rail cannot change Caddy): the push deploys the new binary with the switch OFF (unchanged behaviour). Then, in ONE step because either half alone breaks every request, run the staged /tmp/proxy-protocol-cutover.sh (also scripts/broker/proxy-protocol-cutover.sh in the repo; --revert undoes it). It refuses to run until the installed binary knows the switch.

Acceptance: curl -sX POST https://broker.idss.nz/v1/reachability/self from a home line answers that line's public address; gateway-check (now also asking the router to forward 80/443 with consent — Matou/gateway-check d151917) reads ✓ visitors … your port forwarding works on a forwarded machine.

**Ruled by Ben 2026-10-05 ("I want the tool to answer itself") — BUILT, on main as f2a9f1c7 (2026-10-06).** - `broker/internal/proxyproto`: with `BROKER_PROXY_PROTOCOL=1` every accepted connection must open with a PROXY protocol **v2** header (what Caddy's `transport http { proxy_protocol v2 }` sends) and the header's source becomes `RemoteAddr`; a header-less connection is dropped, never served. No `X-Forwarded-For` is read (ADR 0253 holds). Note: the Caddy syntax in this ticket's body (`listener_wrappers { proxy_protocol }`) is the wrong direction — that is Caddy *receiving* PROXY; the fix needs Caddy *sending* it to the upstream. - The self-probe now **refuses** a loopback/private/link-local/CGNAT peer with a 400 naming the address seen, and dials nothing — the second question in the ask, answered yes. - Seam tests drive the route through the PROXY listener with a claimed public peer, plus the refusal and the header-less drop. GOTCHAS #250 carries the closing entry; ADR 0253 is amended. **Cutover (hands-on, root on the mail droplet — the rail cannot change Caddy):** the push deploys the new binary with the switch OFF (unchanged behaviour). Then, in ONE step because either half alone breaks every request, run the staged `/tmp/proxy-protocol-cutover.sh` (also `scripts/broker/proxy-protocol-cutover.sh` in the repo; `--revert` undoes it). It refuses to run until the installed binary knows the switch. **Acceptance:** `curl -sX POST https://broker.idss.nz/v1/reachability/self` from a home line answers that line's public address; `gateway-check` (now also asking the router to forward 80/443 with consent — `Matou/gateway-check` d151917) reads `✓ visitors … your port forwarding works` on a forwarded machine.
Author
Owner

Cutover done by Ben 2026-10-07 05:49Z — acceptance met.

broker booted … proxy_protocol=true
$ curl -sX POST https://broker.idss.nz/v1/reachability/self     # from a Starlink laptop
{"address":"138.84.41.249","vantage":"broker.idss.nz","groups":[{"group":"web","verdict":"closed","ports":[{"port":80,"verdict":"filtered"},{"port":443,"verdict":"filtered"}]}]}

The address is the caller's own (= OpenDNS's view of that line) and the verdict is honest (CGNAT). Caddy vhost carries transport http { proxy_protocol v2 }; /v1/gateways/offer and the rest still 200. GOTCHAS #250 closing note on main. Closing.

**Cutover done by Ben 2026-10-07 05:49Z — acceptance met.** ``` broker booted … proxy_protocol=true $ curl -sX POST https://broker.idss.nz/v1/reachability/self # from a Starlink laptop {"address":"138.84.41.249","vantage":"broker.idss.nz","groups":[{"group":"web","verdict":"closed","ports":[{"port":80,"verdict":"filtered"},{"port":443,"verdict":"filtered"}]}]} ``` The address is the caller's own (= OpenDNS's view of that line) and the verdict is honest (CGNAT). Caddy vhost carries `transport http { proxy_protocol v2 }`; `/v1/gateways/offer` and the rest still 200. GOTCHAS #250 closing note on main. Closing.
ben closed this issue 2026-10-07 05:50:21 +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.

Dependencies

No dependencies set.

Reference
Matou/idss#2010
No description provided.