diff --git a/flake.nix b/flake.nix index 28693be..9270aaf 100644 --- a/flake.nix +++ b/flake.nix @@ -190,6 +190,7 @@ buildbot-gitea-oauth-secret = ./secrets/buildbot-gitea-oauth-secret.age; immich-shared = ./secrets/immich-shared.age; grafana-secret-key = ./secrets/grafana-secret-key.age; + umami-app-secret = ./secrets/umami-app-secret.age; linux-tracker-peer-minipc1 = ./secrets/linux-tracker-peer-minipc1.age; linux-tracker-peer-minipc2 = ./secrets/linux-tracker-peer-minipc2.age; linux-tracker-peer-minipc3 = ./secrets/linux-tracker-peer-minipc3.age; diff --git a/hosts/ABOUTME.md b/hosts/ABOUTME.md index 849b00a..29d6250 100644 --- a/hosts/ABOUTME.md +++ b/hosts/ABOUTME.md @@ -36,8 +36,8 @@ hosts/ | `hl-bigbox1/` | hl-bigbox1 | AI/compute server (NVIDIA + AMD); Immich machine-learning (CUDA) | | `hl-bigbox2/` | hl-bigbox2 | NFS storage server; Immich server/db (docker, `immich.home.sosnovsky.ca`) | | `hl-minipc1/` | hl-minipc1 | Core infra: Gitea (native or containerized), nix-serve, registry, Buzz (docker, `buzz-manage` CLI), monitoring (Grafana, Prometheus, Loki, OTel collector) | -| `hl-minipc2/` | hl-minipc2 | Container/media server | -| `hl-minipc3/` | hl-minipc3 | K3s worker node; central Caddy reverse-proxy (`*.home.sosnovsky.ca`, plus `gitea.skyg.ca` HTTP/SSH); serves LoopRail docs at `looprails.skyg.ca`; buildbot-nix CI master + worker (2 cores) | +| `hl-minipc2/` | hl-minipc2 | Container/media server; Umami for LoopRail telemetry (own nspawn container, `10.0.101.14`, reachable only from Caddy) | +| `hl-minipc3/` | hl-minipc3 | K3s worker node; central Caddy reverse-proxy (`*.home.sosnovsky.ca`, plus `gitea.skyg.ca` HTTP/SSH); serves LoopRail docs at `looprails.skyg.ca`, plus its guarded telemetry route `/t/v1` → Umami and the LAN-only `umami.home.sosnovsky.ca`; buildbot-nix CI master + worker (2 cores) | | `hl-pi1/` | hl-pi1 | Raspberry Pi CM4 (aarch64) — headless server, SSH only | | `hl-pi2/` | hl-pi2 | Raspberry Pi 4 (aarch64) — headless server, SSH only | | `hl-terra1/` | hl-terra1 | NFS storage + Jellyfin backup | diff --git a/hosts/hl-minipc2/services/default.nix b/hosts/hl-minipc2/services/default.nix index c91db3e..0fc02fe 100644 --- a/hosts/hl-minipc2/services/default.nix +++ b/hosts/hl-minipc2/services/default.nix @@ -7,5 +7,6 @@ ./stack2.nix ./timers.nix ./linux-tracker.nix + ./umami.nix ]; } diff --git a/hosts/hl-minipc2/services/umami.nix b/hosts/hl-minipc2/services/umami.nix new file mode 100644 index 0000000..b2cd24e --- /dev/null +++ b/hosts/hl-minipc2/services/umami.nix @@ -0,0 +1,74 @@ +{ config, skyg-secrets, ... }: +# Umami collects LoopRail's telemetry. Caddy on minipc3 sends it the public +# POST looprails.skyg.ca/t/v1 and the LAN-only dashboard. It runs in its own +# nspawn container with its own LAN address, and only Caddy can reach it. +let + app = config.skyg.internalNetworkingMap.apps.umami; + caddy = config.skyg.internalNetworkingMap.apps.caddy; + appNetwork = config.skyg.internalNetworkingMap.appNetwork; + parent = config.skyg.nixos.common.containers.networks.ipvlanLab.parent; + # nspawn names the ipvlan link iv-. + lanIf = "iv-${parent}"; + port = 3000; + secretPath = "/run/secrets/umami-app-secret"; + hostStateVersion = config.system.stateVersion; +in +{ + age.secrets.umami-app-secret.file = skyg-secrets.umami-app-secret; + + containers.umami = { + autoStart = true; + # Own network: an ipvlan link on the LAN, like the docker apps get. + privateNetwork = true; + extraFlags = [ "--network-ipvlan=${parent}" ]; + bindMounts.${secretPath} = { + hostPath = config.age.secrets.umami-app-secret.path; + isReadOnly = true; + }; + + config = { lib, ... }: { + system.stateVersion = hostStateVersion; + + networking = { + useDHCP = false; + interfaces.${lanIf}.ipv4.addresses = [{ + address = app.ip; + prefixLength = lib.toInt (lib.last (lib.splitString "/" appNetwork.subnet)); + }]; + defaultGateway = { address = appNetwork.gateway; interface = lanIf; }; + nftables.enable = true; + firewall = { + enable = true; + # Only Caddy may reach Umami, at most ~20 new connections a second. + # Caddy opens one connection per telemetry request, so this caps requests. + extraInputRules = '' + ip saddr ${caddy.ip} tcp dport ${toString port} ct state new limit rate 20/second burst 100 packets accept + ''; + }; + }; + + # Postgres only on its local socket. + services.postgresql.settings.listen_addresses = lib.mkForce ""; + + services.umami = { + enable = true; + createPostgresqlDatabase = true; + settings = { + APP_SECRET_FILE = secretPath; + HOSTNAME = "0.0.0.0"; + PORT = port; + DISABLE_UPDATES = true; + DISABLE_TELEMETRY = true; + # looprail's User-Agent would look like a bot. + DISABLE_BOT_CHECK = true; + }; + }; + }; + }; + + # A flood can't starve the rest of the host. + systemd.services."container@umami".serviceConfig = { + MemoryMax = "1G"; + CPUQuota = "100%"; + }; +} diff --git a/hosts/hl-minipc3/services/Caddyfile b/hosts/hl-minipc3/services/Caddyfile index 660c6e7..d7cb3ec 100644 --- a/hosts/hl-minipc3/services/Caddyfile +++ b/hosts/hl-minipc3/services/Caddyfile @@ -57,9 +57,50 @@ gitea.skyg.ca { looprails.skyg.ca { tls /etc/caddy/tls/gitea/fullchain.pem /etc/caddy/tls/gitea/key.pem - root * /srv/looprails - redir /looprail.html / permanent - file_server + + # Telemetry: only looprail's own requests reach Umami. + @telemetry { + method POST + path /t/v1 + header Content-Type application/json* + header User-Agent looprail/* + header X-Looprail-Telemetry {$LOOPRAIL_TELEMETRY_KEY} + } + handle @telemetry { + request_body { + max_size 256KB + } + rewrite * /api/batch + reverse_proxy {$UMAMI_IP}:3000 { + # Umami never sees the sender's IP. + header_up -X-Forwarded-For + header_up -X-Real-IP + header_up -Forwarded + header_up -CF-Connecting-IP + header_up -True-Client-IP + header_up -X-Client-IP + header_up -X-Looprail-Telemetry + # One connection per request, so Umami's rate limit counts requests. + transport http { + keepalive off + } + } + } + handle /t/* { + respond 404 + } + + handle { + root * /srv/looprails + redir /looprail.html / permanent + file_server + } +} + +# Umami dashboard for LoopRail telemetry, LAN only. +umami.home.sosnovsky.ca { + import lan_only + reverse_proxy {$UMAMI_IP}:3000 } # Buzz: straight to its own caddy, LAN only. diff --git a/hosts/hl-minipc3/services/caddy.nix b/hosts/hl-minipc3/services/caddy.nix index b395819..d128761 100644 --- a/hosts/hl-minipc3/services/caddy.nix +++ b/hosts/hl-minipc3/services/caddy.nix @@ -8,6 +8,10 @@ let portainer = config.skyg.internalNetworkingMap.apps.portainer; buzz = config.skyg.internalNetworkingMap.apps.buzz; publicGitea = config.skyg.internalNetworkingMap.apps.public-gitea; + umami = config.skyg.internalNetworkingMap.apps.umami; + # Sent by release looprail binaries on telemetry posts. It ships in the + # binary, so it only filters out scanners; it is not a secret. + looprailTelemetryKey = "70c685d238cc9ec7229e557a8de7b0d25527b1a402805251"; certDomain = "home.sosnovsky.ca"; giteaCertDomain = "gitea.skyg.ca"; # k8s Traefik ingress — fallback for hosts caddy doesn't handle itself. @@ -35,6 +39,8 @@ in PORTAINER_IP = portainer.ip; JELLYFIN_IP = jellyfin.ip; BUZZ_IP = buzz.ip; + UMAMI_IP = umami.ip; + LOOPRAIL_TELEMETRY_KEY = looprailTelemetryKey; K8S_INGRESS = k8sIngress; }; volumes = [ diff --git a/modules/main.nix b/modules/main.nix index e0dcd8c..2d5e843 100644 --- a/modules/main.nix +++ b/modules/main.nix @@ -112,6 +112,7 @@ in immich = { ip = "10.0.101.10"; }; immich-ml = { ip = "10.0.101.11"; }; gilix = { ip = "10.0.101.13"; }; + umami = { ip = "10.0.101.14"; }; jellyfin = { ip = "10.0.101.5"; }; nvr = { ip = "10.0.101.6"; }; portainer = { ip = "10.0.101.241"; }; @@ -124,6 +125,7 @@ in "immich.home.sosnovsky.ca" "gitea.skyg.ca" "looprails.skyg.ca" + "umami.home.sosnovsky.ca" ]; }; }; diff --git a/ray-2026.11.3+89c30837.tar.xz b/ray-2026.11.3+89c30837.tar.xz deleted file mode 100644 index aef86e8..0000000 Binary files a/ray-2026.11.3+89c30837.tar.xz and /dev/null differ diff --git a/secrets.nix b/secrets.nix index 8471a56..63b9334 100644 --- a/secrets.nix +++ b/secrets.nix @@ -80,4 +80,7 @@ in "secrets/linux-tracker-peer-bigbox1.age".publicKeys = [ ari fwdesk ]; "secrets/linux-tracker-peer-bigbox2.age".publicKeys = [ ari fwdesk ]; "secrets/linux-tracker-peer-terra1.age".publicKeys = [ ari fwdesk ]; + + # Unami App + "secrets/umami-app-secret.age".publicKeys = [ ari minipc2 ]; } diff --git a/secrets/umami-app-secret.age b/secrets/umami-app-secret.age new file mode 100644 index 0000000..a238462 --- /dev/null +++ b/secrets/umami-app-secret.age @@ -0,0 +1,7 @@ +age-encryption.org/v1 +-> ssh-ed25519 CIR0mA 8VtMsT7T4XfvUbix/ZBQjNtYNBvEsznysusG/JjlSV0 +NvrhVNN2F95A+H9szc8eIwL7SbLT8UEngEXnSbRV1QM +-> ssh-ed25519 ug+sMw gCL0H0WywGuFMkmihmK1IRe5jw16cMZ4PK19+8WL+Tc +TBpUBZoZORO8x0sLifLF49LQv6gimFU15+iCX6gXCFU +--- TRnC3PR8LvnH6uOl5GW1rE+T0UNoJtgkQ8Lmm3sueks +>ÜF׈H'¯K“û XÅR_0Ì™—’>Õ p¤.KÆ872s+iÛE\Ä‘Þ?dA.YNÐR¸)‚`°ÁF! \ No newline at end of file