authoravatarclover caruso<git@paperclover.net>2026-11-22 13:21:26-08:00
committeravatarclover caruso<git@paperclover.net>2026-11-22 20:28:52-08:00
logae6bbd8f709665dd637e4fb32533cd24dac7369f
tree88db9106d3b886189185cfdd3dd644a8e74fbe3f
parente48b8974b84edabf8620505e5be01424e35eac7e
signature Signed by SSH key SHA256:52mNGHRsVFBDED9IAX5pe+LRWUefqTbxEReunq21QvU

Add a sandbox container network limited to the public internet and PostgreSQL

Services can opt into a podman network whose forwarded traffic to private, tailnet and link-local addresses is dropped before routing, except PostgreSQL on the host. Assisted-by: claude-sonnet-5.5

1 files changed, 19 insertions(+), 0 deletions(-)

nixos/snowglobe.nix+19
......@@ -34,6 +34,25 @@ in
3434 iptables -A nixos-fw -i enp4s0 -s ${(builtins.fromJSON (builtins.readFile ../config/mac-studio-sandbox.json)).guestAddress}/32 -p tcp --dport 2049 -j nixos-fw-accept
3535 ip6tables -A nixos-fw -i enp4s0 -s fe80::/10 -p tcp --dport 445 -j nixos-fw-accept
3636 ip6tables -A nixos-fw -i enp4s0 -s fc00::/7 -p tcp --dport 445 -j nixos-fw-accept
37 '' + ''
38 iptables -t raw -N sandbox-egress 2>/dev/null || iptables -t raw -F sandbox-egress
39 iptables -t raw -A sandbox-egress -d ${(builtins.head config.networking.interfaces.enp4s0.ipv4.addresses).address} -p tcp --dport 15432 -j RETURN
40 ${lib.concatMapStringsSep "\n" (range: "iptables -t raw -A sandbox-egress -d ${range} -j DROP") [ "10.0.0.0/8" "172.16.0.0/12" "192.168.0.0/16" "100.64.0.0/10" "169.254.0.0/16" ]}
41 iptables -t raw -C PREROUTING -i sandbox0 -j sandbox-egress 2>/dev/null || iptables -t raw -I PREROUTING -i sandbox0 -j sandbox-egress
42 '';
43
44 # Containers on `sandbox` reach the public internet and PostgreSQL, nothing else on the host or LAN.
45 systemd.services.podman-sandbox-network = {
46 wantedBy = [ "multi-user.target" ];
47 before = [ "nomad.service" ];
48 serviceConfig = { Type = "oneshot"; RemainAfterExit = true; };
49 script = "${config.virtualisation.podman.package}/bin/podman network create --ignore --disable-dns --subnet 10.89.0.0/24 --interface-name sandbox0 sandbox";
50 };
51 networking.firewall.interfaces.sandbox0.allowedTCPPorts = [ 15432 ];
52 networking.firewall.extraStopCommands = ''
53 iptables -t raw -D PREROUTING -i sandbox0 -j sandbox-egress 2>/dev/null || true
54 iptables -t raw -F sandbox-egress 2>/dev/null || true
55 iptables -t raw -X sandbox-egress 2>/dev/null || true
3756 '';
3857
3958 services.caddy.virtualHosts."${spacebarVoice.subdomain}.${config.environment.variables.SNOWGLOBE_DOMAIN}".extraConfig = ''