diff --git a/hyperv-infra/flake.nix b/hyperv-infra/flake.nix index 0d30b91..4302dc7 100644 --- a/hyperv-infra/flake.nix +++ b/hyperv-infra/flake.nix @@ -60,6 +60,11 @@ # full commit rather than by branch: `nixos-unstable` drifts, and drifting is precisely the # failure mode that produced G-27 on production in the first place. nixpkgs-gitea.url = "github:nixos/nixpkgs/6368eda62c9775c38ef7f714b2555a741c20c72d"; + + # Ianitor (the Pingora reverse proxy), beside Caddy on two low-risk hosts. Its packages are + # built from its own pinned nixpkgs; only the module is evaluated against this one. Pin to a + # reviewed commit: MERGED_COMMIT is replaced by the merged hash before the first lock. + ianitor.url = "git+https://gitea.marek-novak.cz/mnovak/Ianitor.git?ref=main&rev=MERGED_COMMIT"; }; outputs = { self, nixpkgs, sops-nix, nixpkgs-gitea, ... }@inputs: { @@ -86,6 +91,8 @@ # Application modules ./modules/caddy.nix + # Ianitor beside Caddy: flowers and esp32 go through it (modules/ianitor.nix). + ./modules/ianitor.nix ./modules/home-assistant.nix # ./modules/nextcloud.nix 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,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 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 unix//run/ianitor-proxy/edge.sock + ''; + }; simple = { frame ? "SAMEORIGIN", upstream }: { extraConfig = '' tls internal @@ -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. - "flowers.stage.marek-novak.cz" = simple { upstream = "127.0.0.1:8091"; }; + # Through Ianitor (trial); before: simple { upstream = "127.0.0.1:8091"; }. + "flowers.stage.marek-novak.cz" = viaIanitor "flowers.stage.marek-novak.cz"; + + # Through Ianitor (trial). Explicit, so it wins over the `projects` entry below. + "esp32.stage.marek-novak.cz" = viaIanitor "esp32.stage.marek-novak.cz"; # supabase - the whole block previously proxied to 172.18.0.3 / .6 / .9. # diff --git a/hyperv-infra/modules/ianitor.nix b/hyperv-infra/modules/ianitor.nix new file mode 100644 index 0000000..cd23016 --- /dev/null +++ b/hyperv-infra/modules/ianitor.nix @@ -0,0 +1,52 @@ +{ config, lib, inputs, ... }: + +# Ianitor beside Caddy (Ianitor ROADMAP ยง1.12, Phase 3): two low-risk hosts, flowers and esp32, +# go through Ianitor's edge; every other host stays on Caddy exactly as before. +# +# 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) -> unix socket /run/ianitor-proxy/edge.sock -> Ianitor edge -> the app +# +# 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. + +let + stage = "stage.marek-novak.cz"; +in +{ + imports = [ inputs.ianitor.nixosModules.ianitor ]; + + sops.secrets."ianitor/share-link-key" = { }; + sops.secrets."ianitor/pki-password" = { }; + + services.ianitor = { + enable = true; + edge = { + 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" ]; services = [ "caddy" ]; }; + }; + control.listen = "127.0.0.1:7878"; + shareLinkKeyFile = config.sops.secrets."ianitor/share-link-key".path; + pki = { + enable = true; + rootCertificate = ../ianitor/domi-root.crt; + passwordFile = config.sops.secrets."ianitor/pki-password".path; + }; + }; + + # The trial hosts, as Ianitor route files. They are applied through the API after the first + # start (docs/deploy/beside-caddy.md in the Ianitor repo); listed here so the review sees them. + environment.etc."ianitor/trial-hosts.json".text = builtins.toJSON [ + { hostname = "flowers.${stage}"; upstreams = [ "http://127.0.0.1:8091" ]; tls = "domi"; auth = "none"; health_check = { path = "/"; interval_secs = 30; }; response_headers = [ { action = "set"; name = "X-Served-By"; value = "ianitor"; } ]; } + { hostname = "esp32.${stage}"; upstreams = [ "http://127.0.0.1:8093" ]; tls = "domi"; auth = "none"; health_check = { path = "/"; interval_secs = 30; }; response_headers = [ { action = "set"; name = "X-Served-By"; value = "ianitor"; } ]; } + ]; +}