Files
nixos-config/hosts/m3-hermes/services/ai-memory.nix
T
m3ta-chiron d8239fcd32 fix(m3-hermes): firewall — interface match instead of IPv4 CIDR in ip46tables
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.
2026-10-31 13:17:42 +01:00

56 lines
2.2 KiB
Nix

{
config,
pkgs,
...
}: let
# Mesh-only via interface match on wt0 (NetBird) — an IPv4 CIDR in -s
# would abort the ip6tables run of ip46tables and fail the unit.
port = config.m3ta.ports.get "ai-memory";
in {
# ── ai-memory server ──────────────────────────────────────────────────
# Shared agent memory for all hosts (private + work), see
# https://aimemory.sh. Clients: m3ta-home `coding.aiMemory`.
#
# Flow: Agent → memory.m3ta.dev (TLS via m3-atlas Traefik) → Netbird → :${toString port}
# Hermes on this host talks to 127.0.0.1 directly.
services.ai-memory = {
enable = true;
# Same build as the clients (m3ta-home uses llm-agents.ai-memory),
# prebuilt via the numtide cache instead of compiling the flake.
package = pkgs.llm-agents.ai-memory;
bind = "0.0.0.0";
inherit port;
enableWeb = true;
# Root bearer, token pepper, recovery token, cookie/proxy settings and
# the LLM provider key. Never put any of these into `settings`.
ageSecret = "ai-memory-server-env";
settings = {
allowed_hosts = ["memory.m3ta.dev" "localhost" "127.0.0.1" "::1"];
# One operator, several workspaces (private, az, home): keep one
# cross-project profile for all of them. With database users the
# profile is off unless enabled explicitly.
profile = {
enabled = true;
share = "global";
};
# Shared server: auto-improvement proposals wait for approval.
auto_improve.require_approval = true;
};
};
# A changed secret (model, keys, tokens) does not change the unit file, so
# without this the running server keeps the old environment after a switch.
systemd.services.ai-memory.restartTriggers = [config.age.secrets."ai-memory-server-env".file];
networking.firewall = {
extraCommands = ''
# Allow ai-memory only from Netbird mesh VPN
ip46tables -A nixos-fw -p tcp --dport ${toString port} -i wt0 -j nixos-fw-accept
'';
extraStopCommands = ''
ip46tables -D nixos-fw -p tcp --dport ${toString port} -i wt0 -j nixos-fw-accept 2>/dev/null || true
'';
};
}