From ed558a196fcbc65c1af82fb0f54fdd6773c76b66 Mon Sep 17 00:00:00 2001 From: Ari Sosnovsky Date: Mon, 26 Oct 2026 12:26:19 -0400 Subject: [PATCH] ensuring only relevant access is provided --- docs/NETWORK.md | 3 +++ modules/hermenix/network.nix | 2 +- tests/network-modes-check.nix | 6 +++++- 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/docs/NETWORK.md b/docs/NETWORK.md index 8f0d8c4..fa4e3df 100644 --- a/docs/NETWORK.md +++ b/docs/NETWORK.md @@ -70,6 +70,9 @@ services.hermenix.publish = [ ``` DNATs the uplink port and opens the forward rule. Ports need not match. +A published port only answers on the host's own addresses (LAN, tailscale, and +so on). Traffic to other addresses the host routes for, such as containers with +their own LAN IPs, is left alone. Publishing is the one change that lets the outside world start conversations with the agent's machine — put TLS/auth in front of anything that isn't a toy. diff --git a/modules/hermenix/network.nix b/modules/hermenix/network.nix index fb1f0bc..6906ad8 100644 --- a/modules/hermenix/network.nix +++ b/modules/hermenix/network.nix @@ -58,7 +58,7 @@ in type nat hook prerouting priority dstnat; '' + lib.concatMapStrings (s: '' - iifname != "${net.bridge}" ${s.proto} dport ${toString s.hostPort} dnat to ${net.guestAddress}:${toString s.guestPort} + iifname != "${net.bridge}" fib daddr type local ${s.proto} dport ${toString s.hostPort} dnat to ${net.guestAddress}:${toString s.guestPort} '') cfg.publish + '' } diff --git a/tests/network-modes-check.nix b/tests/network-modes-check.nix index 915d6df..d8ad09d 100644 --- a/tests/network-modes-check.nix +++ b/tests/network-modes-check.nix @@ -148,7 +148,11 @@ let hostResults = { # --- NAT mode: the original behaviour has to be unchanged ---------- "nat: no bridged-mode bridge table" = !(natNft ? "hermenix-bridge"); - "nat: publish is DNATed to the guest" = has "dnat to 10.77.0.2:8080" natNat.content; + "nat: publish is DNATed to the guest, only for the host's own addresses" = + has "fib daddr type local tcp dport 8080 dnat to 10.77.0.2:8080" natNat.content; + "nat: every DNAT rule is limited to the host's own addresses" = lib.all ( + l: !(has "dnat to" l) || has "fib daddr type local" l + ) (lib.splitString "\n" natNat.content); "nat: outbound masquerades on the uplink" = has "masquerade" natNat.content; "nat: input rules match the fixed service-net address" = has "ip saddr 10.77.0.2 tcp dport 5000 accept" natInput && !(has "meta mark" natInput);