|
|
@@ -65,23 +65,26 @@ to parse the connection.
|
|
65
|
65
|
|
|
66
|
66
|
### Why HAProxy uses `network_mode: host`
|
|
67
|
67
|
|
|
68
|
|
-When a container is on a bridge network and a port is published with
|
|
69
|
|
-`ports: "443:443"`, the source IP of inbound connections is rewritten
|
|
70
|
|
-to the bridge gateway before HAProxy sees it — Docker's `docker-proxy`
|
|
71
|
|
-userland forwarder accepts on the host and re-opens the connection
|
|
72
|
|
-from the gateway; Podman's `slirp4netns` / `pasta` does the same in
|
|
73
|
|
-rootless mode. The PROXY v2 header HAProxy then sends downstream
|
|
74
|
|
-carries that gateway address (e.g. `172.x.x.1`), not the real client.
|
|
75
|
|
-
|
|
76
|
|
-`network_mode: host` puts HAProxy in the host network namespace, so it
|
|
77
|
|
-binds `:443` / `:80` directly with no NAT in the path and observes the
|
|
78
|
|
-true source address of every connection. mtg and Caddy stay on the
|
|
79
|
|
-compose bridge and are published only on `127.0.0.1` — HAProxy reaches
|
|
80
|
|
-them via host loopback, and the PROXY v2 header carries the real
|
|
81
|
|
-client IP (v4 or v6) end-to-end.
|
|
82
|
|
-
|
|
83
|
|
-Trade-off: HAProxy occupies the host's `:443` and `:80`. Don't run
|
|
84
|
|
-anything else on those ports on the same host.
|
|
|
68
|
+A published port on a bridge network rewrites the source IP of inbound
|
|
|
69
|
+connections to the bridge gateway before HAProxy sees it (Docker's
|
|
|
70
|
+`docker-proxy`, Podman's `slirp4netns`/`pasta`), so the PROXY v2 header
|
|
|
71
|
+HAProxy forwards downstream carries that gateway address, not the real
|
|
|
72
|
+client. Host-mode HAProxy binds in the host netns directly, no NAT in
|
|
|
73
|
+the path, and the rewrite never happens. mtg and Caddy stay on the
|
|
|
74
|
+compose bridge and are published on `127.0.0.1` only — HAProxy reaches
|
|
|
75
|
+them over host loopback. `mtg-config.toml` does not need to change;
|
|
|
76
|
+fronting still uses `host = "web"` over compose-network DNS.
|
|
|
77
|
+
|
|
|
78
|
+**Trade-offs.**
|
|
|
79
|
+- HAProxy owns the host's `:443` and `:80` — don't run anything else
|
|
|
80
|
+ on those ports.
|
|
|
81
|
+- Linux host only. On Docker Desktop (macOS/Windows), "host" means
|
|
|
82
|
+ the Linux VM, not the user's machine, so external clients can't
|
|
|
83
|
+ reach the proxy.
|
|
|
84
|
+- If you run Docker with `userns-remap`, the in-container "root"
|
|
|
85
|
+ loses the privilege to bind `<1024` on the host; either disable
|
|
|
86
|
+ `userns-remap` for this stack or lower `net.ipv4.ip_unprivileged_port_start`
|
|
|
87
|
+ on the host.
|
|
85
|
88
|
|
|
86
|
89
|
## Fronting loop (why `[domain-fronting]` is set explicitly)
|
|
87
|
90
|
|