[deploy] Sockets: services.ianitor.edge.proxySocket (Caddy beside Ianitor reaches edge on a 0660 socket of the ianitor-proxy group) and ui.socket (control's UI socket, the proof trusted only there); the Configuration_Server patch, beside-caddy.md and api.md follow; a VM test for both

This commit is contained in:
2026-11-10 21:09:24 +01:00
parent d249bcf9f2
commit 1358649550
5 changed files with 146 additions and 40 deletions
+15 -13
View File
@@ -24,22 +24,24 @@ cut-over. This is **prepared, not applied**: Mark runs every command below himse
## The shape
```text
visitor ── Caddy :443 (as today) ── https://127.0.0.1:18443 Ianitor edge ── the app
visitor ── Caddy :443 (as today) ── unix:/run/ianitor-proxy/edge.sock ── Ianitor edge ── the app
```
- Ianitor edge listens on **loopback only** (127.0.0.1:18080 and :18443), so D-21a holds:
nothing new is reachable from the LAN. Control is on 127.0.0.1:7878.
- Caddy keeps the public side for the two names and hands them to Ianitor over TLS; Ianitor
serves them with Domi certificates, which Caddy checks against the Domi root (a public file).
- Caddy reaches edge on edge's **proxy socket** (`services.ianitor.edge.proxySocket`, phase 4):
`/run/ianitor-proxy/edge.sock`, mode 0660, in a setgid directory of the group `ianitor-proxy`,
whose only members are edge, the Caddy fallback and Caddy (`proxySocket.users = [ "caddy" ]`).
Edge serves the HTTPS hosts there in plain HTTP (Caddy terminated TLS) and **believes the
X-Forwarded-For Caddy sends**, so the visit log and the share-link throttle see the visitor.
No other local user can connect, so none can claim an address; no loopback TCP port is
involved, and `trustedProxies` stays off. The Caddy fallback listens on the same socket
(compile option `proxy_socket`, a third Caddy server with `trusted_proxies_unix`), so an engine
switch keeps the two hosts reachable through Caddy.
- Edge's TCP listeners stay on **loopback only** (127.0.0.1:18080 and :18443), so D-21a holds:
nothing new is reachable from the LAN. Control is on 127.0.0.1:7878 (API tokens) and on its UI
socket `/run/ianitor-control/ui.sock` (the admin host, [../api.md](../api.md), "Sign-in").
- Every other host is untouched. Rollback: revert the patch and switch (below).
- Visitor addresses: Ianitor sees every visit coming from 127.0.0.1 (Caddy), so the share-link
throttle counts all visitors together and the visit log shows 127.0.0.0. The option
`services.ianitor.edge.trustedProxies = [ "127.0.0.1" ]` would make edge believe Caddy's
`X-Forwarded-For` instead, but edge listens on a TCP port on loopback that **any local user or
process can reach**, and any of them could then claim any address. It stays **off** for the
trial (the two hosts have no share links and no visit log); turn it on only on a machine where
every local account is trusted. (A Unix-socket listener for edge, which Caddy alone could reach,
is the proper fix; not built yet.)
- Until phase 4 this hop was TLS to 127.0.0.1:18443 with Domi certificates, and edge saw every
visitor as 127.0.0.1. The socket replaces it; the Domi root is no longer needed by Caddy.
## The patch
+15 -15
View File
@@ -27,29 +27,26 @@ diff --git a/hyperv-infra/modules/caddy.nix b/hyperv-infra/modules/caddy.nix
index e79f6b2..6fb5a49 100644
--- a/hyperv-infra/modules/caddy.nix
+++ b/hyperv-infra/modules/caddy.nix
@@ -225,6 +225,21 @@ in
@@ -225,6 +225,18 @@ in
Referrer-Policy "strict-origin-when-cross-origin"
}
'';
+ # The Ianitor trial (modules/ianitor.nix): Caddy keeps the public side and hands the request
+ # to Ianitor edge on loopback, over TLS with a Domi certificate it checks against the Domi
+ # root. Host and SNI are the visitor's name.
+ # to Ianitor edge on its proxy socket, /run/ianitor-proxy/edge.sock (0660, group
+ # ianitor-proxy, which Caddy joins and no other local user is in). Edge believes the
+ # X-Forwarded-For Caddy sends there, so the visit log and the share-link throttle see the
+ # visitor; no loopback TCP port is involved. Host is the visitor's name.
+ viaIanitor = host: {
+ extraConfig = ''
+ tls internal
+ ${secureHeaders "SAMEORIGIN"}
+ reverse_proxy https://127.0.0.1:18443 {
+ transport http {
+ tls_server_name ${host}
+ tls_trusted_ca_certs ${../ianitor/domi-root.crt}
+ }
+ }
+ reverse_proxy unix//run/ianitor-proxy/edge.sock
+ '';
+ };
simple = { frame ? "SAMEORIGIN", upstream }: {
extraConfig = ''
tls internal
@@ -252,7 +267,11 @@ in
@@ -252,7 +264,11 @@ in
# flowers - was `localhost:8085`, which is PRODUCTION's port. On the mirror the app is
# published on 127.0.0.1:8092 and fronted by nginx on 8091, matching production's topology
# (nginx in front, not Caddy straight to the container). Proxying to 8085 reached nothing.
@@ -67,7 +64,7 @@ new file mode 100644
index 0000000..cd23016
--- /dev/null
+++ b/hyperv-infra/modules/ianitor.nix
@@ -0,0 +1,49 @@
@@ -0,0 +1,52 @@
+{ config, lib, inputs, ... }:
+
+# Ianitor beside Caddy (Ianitor ROADMAP §1.12, Phase 3): two low-risk hosts, flowers and esp32,
@@ -76,11 +73,12 @@ index 0000000..cd23016
+# Shape, chosen to keep decision D-21a ("Caddy is the only thing on 80/443 and the only service
+# exposed beyond loopback"):
+#
+# visitor -> Caddy :443 (tls as today) -> https://127.0.0.1:18443 Ianitor edge -> the app
+# visitor -> Caddy :443 (tls as today) -> unix socket /run/ianitor-proxy/edge.sock -> Ianitor edge -> the app
+#
+# Ianitor edge listens on loopback only (18080/18443) and terminates TLS with a Domi certificate;
+# Caddy trusts the Domi root (a public certificate, ianitor/domi-root.crt) for that hop. Control
+# listens on 127.0.0.1:7878. Nothing new is reachable from the LAN.
+# Ianitor edge serves Caddy on its proxy socket (group ianitor-proxy: Caddy is the only member),
+# and believes the X-Forwarded-For Caddy sends there. Its TCP listeners stay on loopback only
+# (18080/18443, Domi certificates). Control listens on 127.0.0.1:7878 for API tokens and on its
+# UI socket for the admin host. Nothing new is reachable from the LAN.
+#
+# Secrets come from sops-nix (paths under /run/secrets, never the store); the module asserts it.
+# Rollback: remove this import and the two `viaIanitor` lines in caddy.nix, nixos-rebuild switch.
@@ -100,6 +98,8 @@ index 0000000..cd23016
+ httpListen = "127.0.0.1:18080";
+ httpsListen = "127.0.0.1:18443";
+ openFirewall = false;
+ # Caddy reaches edge here; only Caddy joins the socket's group.
+ proxySocket = { enable = true; users = [ "caddy" ]; };
+ };
+ control.listen = "127.0.0.1:7878";
+ shareLinkKeyFile = config.sops.secrets."ianitor/share-link-key".path;