Hand certificates and CA files to HAProxy as credentials

The settings only allow paths in the state directory, which is 0700 root
and which HAProxy (a user of its own) cannot enter. systemd reads the
files and gives the service copies; a path unit restarts it when one
changes. The load balancer test keeps its files in the state directory
now, and verifies the backends' certificate.
This commit is contained in:
2026-11-28 21:23:09 +01:00
parent 2ebf45af81
commit 20ec791827
4 changed files with 62 additions and 4 deletions
+1
View File
@@ -252,6 +252,7 @@ A service on several hosts that must be reachable from outside and inside, with
- **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).
- **Files:** `certificate` and `backendTls.caFile` are paths in the state directory (the settings editor allows nothing else), which is 0700 root: HAProxy runs as its own user, so systemd reads the files as root and hands the service copies (`LoadCredential`, under `/run/credentials/haproxy.service/`; the configuration names those). A path unit restarts HAProxy when one of the files changes (a renewed certificate). Store paths are used as they are. (Found in use in 0.14.0: the `loadbalancer` test used store paths and so missed it; it now keeps both files in `/var/lib/router/lb/` and verifies the backends' certificate.)
- **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`.