The mesh-only accept rules used 'ip46tables ... -s 100.x/16'. ip46tables runs every rule through iptables AND ip6tables; ip6tables cannot parse an IPv4 CIDR and aborts with 'host/network not found', failing the whole firewall.service (status 2). Consequence beyond the unit failure: the firewall-start script aborted at the first such rule, so the trailing default-reject rules were never applied — the input filter was effectively OPEN (only SSH/established rules had been added). This also explains why the mesh services were reachable although the previous 100.64.0.0/16 source rule never matched any peer. Fix: match on the NetBird interface (-i wt0) instead of a source range — family-agnostic, survives NetBird range changes, and matches the idiom the generated script already uses for NetBird service ports. Applied to ai-memory, hermes-dashboard and t3code rules (add + stop-commands). After deploying: firewall.service completes, default-reject applies, and 49374/9119/8642/3773 become reachable from the mesh ONLY (previously open to everyone). Anything that silently relied on the open filter will start failing — that is the intended posture.
69 lines
2.6 KiB
Nix
69 lines
2.6 KiB
Nix
{
|
|
config,
|
|
pkgs,
|
|
inputs,
|
|
...
|
|
}: let
|
|
# Mesh-only via interface match on wt0 (NetBird) — works for ip46tables
|
|
# where an IPv4 CIDR in -s would abort the ip6tables run.
|
|
apiPort = config.m3ta.ports.get "hermes-api";
|
|
dashboardPort = config.m3ta.ports.get "hermes-dashboard";
|
|
|
|
# Reference the hermes-agent package from the running service config
|
|
hermesPkg = config.services.hermes-agent.package or (inputs.hermes-agent.packages.${pkgs.stdenv.hostPlatform.system}.default or pkgs.hermes-agent);
|
|
in {
|
|
# ── Hermes Dashboard systemd service ───────────────────────────────────
|
|
# Web UI for managing Hermes Agent — sessions, config, kanban, cron, etc.
|
|
#
|
|
# Flow: Browser → dash.m3ta.dev (TLS via m3-atlas Traefik) → Netbird → :${toString dashboardPort}
|
|
#
|
|
# --insecure is required to bind 0.0.0.0 (hermes refuses non-localhost otherwise).
|
|
# Safe because firewall restricts the dashboard/API ports to Netbird mesh only.
|
|
systemd.services.hermes-dashboard = {
|
|
description = "Hermes Agent Web Dashboard";
|
|
after = ["network.target" "hermes-agent.service"];
|
|
wants = ["hermes-agent.service"];
|
|
wantedBy = ["multi-user.target"];
|
|
|
|
serviceConfig = {
|
|
Type = "simple";
|
|
User = "hermes";
|
|
Group = "hermes";
|
|
|
|
ExecStart = "${hermesPkg}/bin/hermes dashboard --host 0.0.0.0 --port ${toString dashboardPort} --no-open --insecure";
|
|
|
|
# Environment matching the hermes-agent service
|
|
Environment = [
|
|
"HERMES_HOME=/var/lib/hermes/.hermes"
|
|
"HERMES_MANAGED=true"
|
|
"HOME=/var/lib/hermes"
|
|
];
|
|
|
|
# Security hardening (matching hermes-agent service pattern)
|
|
NoNewPrivileges = true;
|
|
ProtectSystem = "strict";
|
|
ProtectHome = "read-only";
|
|
ReadWritePaths = ["/var/lib/hermes" "/tmp"];
|
|
PrivateTmp = true;
|
|
|
|
# Restart policy
|
|
Restart = "on-failure";
|
|
RestartSec = 5;
|
|
};
|
|
};
|
|
|
|
# ── Firewall: Hermes network endpoints only from Netbird mesh ──────────
|
|
networking.firewall = {
|
|
extraCommands = ''
|
|
# Allow Hermes Dashboard and OpenAI-compatible API only from Netbird mesh VPN
|
|
ip46tables -A nixos-fw -p tcp --dport ${toString dashboardPort} -i wt0 -j nixos-fw-accept
|
|
ip46tables -A nixos-fw -p tcp --dport ${toString apiPort} -i wt0 -j nixos-fw-accept
|
|
'';
|
|
|
|
extraStopCommands = ''
|
|
ip46tables -D nixos-fw -p tcp --dport ${toString dashboardPort} -i wt0 -j nixos-fw-accept 2>/dev/null || true
|
|
ip46tables -D nixos-fw -p tcp --dport ${toString apiPort} -i wt0 -j nixos-fw-accept 2>/dev/null || true
|
|
'';
|
|
};
|
|
}
|