Load balancers
router.loadBalancers: services on several hosts (HAProxy) with HTTP checks, TLS terminated on the router or passed through, the client in X-Forwarded-For or the PROXY protocol, host names that choose a service on a shared port and are published in the local DNS. A status page lists the backends.
This commit is contained in:
@@ -246,6 +246,19 @@ Two sources, so nothing the machine already exports is written twice.
|
||||
- **node_exporter** (`router.metrics.nodeExporter`, `modules/router/metrics.nix`): CPU, memory, disks, interfaces and systemd units. Off by default. It listens on all addresses, but the firewall opens its port (9100) only to the zones in `zones` (one allow rule each, to `local`); `wan` is refused by an assertion. With no zone it can only be read on the router itself.
|
||||
- Tested in `webui` (token needed, the samples, node_exporter from the LAN and on the router, the rule names the LAN's device only) and `assertions`. The **Prometheus page** (Services → Prometheus, `exporter.go`) edits the exporter's settings (enable, port, zones to open it to; `wan` and the router's own ports are refused) and shows the scrape config for `/metrics` and for node_exporter. Not done: per-LAN traffic of the web UI's own history (node_exporter has the interface counters), and alert rules or a Grafana dashboard.
|
||||
|
||||
## Load balancers (2026-11-27)
|
||||
|
||||
A service on several hosts that must be reachable from outside and inside, with backend checks (the first case: an API on `hv1` and `hv2`). `router.loadBalancers.<name>` (`options.nix`, `modules/router/loadbalancer.nix`) generates an HAProxy configuration (`services.haproxy`); nothing else on the router changes.
|
||||
|
||||
- **Listening:** `listen.port` and `listen.zones` (`wan` = the uplink, or the zones of LANs and tunnels). The firewall opens that port in those zones itself (`lbInput` in `firewall.nix`), so no rule is needed. IPv4 and IPv6 are bound apart: one dual-stack socket shows IPv4 clients as `::ffff:a.b.c.d` in `X-Forwarded-For` (found by the VM test).
|
||||
- **TLS, a decision per service:** `terminate` (the router decrypts with `certificate`, a PEM with chain and key, or with its own ACME certificate when `router.acme.domains` covers `hosts`; to the backends in the clear or, with `backendTls.enable`, encrypted again, verified only if `backendTls.verify`), `passthrough` (bytes only; the backends have the certificate, and only the checks speak TLS) or `none`. `protocol` is `http` (adds `X-Forwarded-For`) or `tcp` (always with passthrough). `proxyProtocol` sends the client's address to backends that read it (for tcp).
|
||||
- **Backends:** names of DHCP reservations or IPv4 addresses, on `backendPort` (default the listen port). `balance`: `roundrobin`, `leastconn`, `source`. Checks: an HTTP GET of `check.path` (2xx/3xx) every `check.interval`, `fall` failures take a backend out, `rise` successes bring it back; `check.useHttp = false` only connects. With no backend up the service answers 503.
|
||||
- **Host names:** `hosts` is the Host header or TLS name that selects the service, so services may share a port (each needs `hosts`; they must agree on `tls` and `protocol`). The names are also published in the local DNS (`dns.hosts`, `mkDefault`) as the router's addresses on the LANs the service listens in, so inside and outside use the same name. This is the host-based routing that was open for ports 80/443 (TLS name or Host header; the web UI's own port still has to be another one).
|
||||
- **Assertions:** a backend that is neither a reservation nor an address, an unknown zone, a port the router itself uses (SSH, DNS, the web UI) or that `firewall.nat` forwards, shared ports without `hosts`, services on a port that disagree, passthrough with `http`, no certificate without ACME, a certificate that does not cover `hosts`.
|
||||
- **Web UI:** Network → Load balancers (`loadbalancer.go`): the saved configuration beside what HAProxy says (`show stat` on `/run/haproxy/haproxy.sock`: state, last check, connections, time in the state), refreshed every 10 s; "not applied" for a saved service HAProxy does not know yet. Services are edited in Advanced (no form yet).
|
||||
- Tested in the `loadbalancer` VM test (both backends used from outside and inside, `X-Forwarded-For`, the DNS name, passthrough, the closed port, a sick and a stopped backend, 503, the statistics columns the page reads), `assertions` and the Go tests. Not tested: the PROXY protocol, `balance = source`, `backendTls.verify`, shared ports in a VM, the router's own ACME certificate.
|
||||
- Open: a form for the settings, backend state in `/metrics` and the MCP tools, UDP, drain/maintenance of a backend from the page.
|
||||
|
||||
## Not done yet (2026-11-01, after 0.12.0)
|
||||
|
||||
Remote access
|
||||
@@ -256,7 +269,7 @@ Remote access
|
||||
- Rule for all of it: changes go through `settings.json` and `router-apply` (commit-confirm), never straight to the live system; tokens have scopes; every call is logged.
|
||||
|
||||
Firewall and networking
|
||||
- **Host-based routing on 80/443**: decide by TLS server name (or the `Host` header) between the router's web UI and a host behind it. It needs an SNI proxy on the router and loses the client address unless the host takes the PROXY protocol. Until then, expose the web UI and SSH on their own ports with `wan -> local` rules.
|
||||
- **Host-based routing on 80/443**: *mostly done by the load balancers* (see above: services sharing a port by `hosts`). Still open: sharing 443 with the router's own web UI, which needs the web UI behind the proxy. Until then, expose the web UI and SSH on their own ports with `wan -> local` rules.
|
||||
- **WireGuard**: live status (handshake, transfer) in the web UI; a tunnel with `dns = true` but no address.
|
||||
- **IPv6** for forwards: a pinhole for a host behind the router is possible by hand (`wan -> lan` with an IPv6 `destination`), nothing helps with finding the host's delegated address. Also open: other LANs are IPv4-only (PD serves one LAN), DHCPv6 reservations, NPTv6.
|
||||
- **Multi-WAN failover**, **QoS** (CAKE/SQM): deferred, not started.
|
||||
|
||||
Reference in New Issue
Block a user