From fec8d7cb2562db80ff08cefc0b0bd1179cea00ae Mon Sep 17 00:00:00 2001 From: Erik Simon Date: Sat, 19 Sep 2026 02:25:14 +0200 Subject: [PATCH] fix(mars): trust only neptun's proxy for the Hermes dashboard Replaces FORWARDED_ALLOW_IPS="*" with dashboard.trusted_proxies pinned to neptun's tailnet IP (merged into config.yaml by prepare-dirs via yq) and pins HERMES_DASHBOARD_PUBLIC_URL so the OIDC redirect_uri stays https. Co-Authored-By: Claude Opus 5 --- hosts/mars/hermes-agent.nix | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/hosts/mars/hermes-agent.nix b/hosts/mars/hermes-agent.nix index 0d84e48..a0fd164 100644 --- a/hosts/mars/hermes-agent.nix +++ b/hosts/mars/hermes-agent.nix @@ -52,6 +52,10 @@ let # is hers to make, anywhere inside HERMES_WRITE_SAFE_ROOT=/opt/data. giteaHost = "git.mgaction.town"; + # neptun's tailnet IP: its Caddy is the only proxy whose X-Forwarded-Proto + # the dashboard should trust. + neptunTailnetIp = "100.64.0.5"; + # luna's webhook filters, mounted READ-ONLY from the nix store rather than # written into hermesHome: that IS her write-safe root, so a writable copy # would let her edit her own loop guard back out. A missing script fails @@ -139,7 +143,7 @@ in wants = [ "network-online.target" ]; after = [ "network-online.target" ]; unitConfig.RequiresMountsFor = [ "/mnt/jupiter" ]; - path = [ pkgs.git pkgs.tea pkgs.curl pkgs.coreutils ]; + path = [ pkgs.git pkgs.tea pkgs.curl pkgs.coreutils pkgs.yq-go ]; serviceConfig.Type = "oneshot"; # Everything here is either local or bounded to ~30s by the probe loop, so # anything past two minutes is a hang, not slowness. @@ -210,6 +214,15 @@ in # scripts as uid ${hermesUid}. chown ${hermesUid}:${hermesGid} ${hermesHome}/scripts + # trusted_proxies has no env override and Hermes owns config.yaml, so + # only this key is merged in; without it the Secure cookie flag breaks. + conf=${hermesHome}/config.yaml + [ -e "$conf" ] || : > "$conf" + yq '.dashboard.trusted_proxies = ["${neptunTailnetIp}"]' "$conf" > "$conf.new" + chown ${hermesUid}:${hermesGid} "$conf.new" + chmod --reference="$conf" "$conf.new" + mv -f "$conf.new" "$conf" + if [ -d ${hermesHome}/.config ]; then chown ${hermesUid}:${hermesGid} ${hermesHome}/.config fi @@ -268,12 +281,9 @@ in HERMES_DASHBOARD_HOST = "0.0.0.0"; # must be tailscale0-reachable, not just loopback HERMES_DASHBOARD_OIDC_ISSUER = "https://auth.mgaction.town/application/o/hermes/"; HERMES_DASHBOARD_OIDC_CLIENT_ID = "4BqdJu3htnMtSZnyEu5zHnsSOvlEbw3Ie3mYVlh6"; - # uvicorn only trusts X-Forwarded-Proto from forwarded_allow_ips - # (default 127.0.0.1); neptun's Caddy reaches this over a real routed - # tailnet IP, so without this it builds an http:// redirect_uri that - # Authentik rejects. Safe to trust any peer: 9119 is already scoped to - # loopback + tailscale0 only. - FORWARDED_ALLOW_IPS = "*"; + # Pins the OIDC redirect_uri to https; otherwise it is rebuilt from + # forwarded headers (see trusted_proxies in prepare-dirs). + HERMES_DASHBOARD_PUBLIC_URL = "https://hermes.mgaction.town"; }; environmentFiles = [ config.sops.templates."hermes-agent.env".path ]; cmd = [ "gateway" "run" ];