mirror of
https://github.com/ryan4yin/nix-config.git
synced 2026-12-03 11:14:01 +01:00
feat(nixos): default-deny host inbound, trust the LAN/tailnet (#325)
Hosts used to trust the router as the only boundary (servers ran with the firewall off; service ports were opened globally), so any LAN device could reach every host service. Move filtering to the hosts as defence in depth behind the router, which keeps its firewall on and uses a port mapping for the few ports we actually need. - base: nftables backend; deny inbound by default; trust the home LAN by source and the tailnet by interface (restrict the tailnet with ACLs); suppress per-service `openFirewall` global ports; allow node_exporter only from the monitoring host. The local podman bridge, the tailnet and the pod CIDRs are accepted only after the node_exporter drop. - servers: stop disabling the firewall; drop redundant global port opens (caddy 80/443, NFS 2049, Jellyfin, localsend/test ports); delete the redundant desktop firewall module; aarch64/riscv64 import the firewall explicitly (akane was missing it). - k3s: Cilium pods (10.0.0.0/8, fd00::/8) may reach host services; drop the flannel-era cni0/flannel.1 trust. - youko: postgres listens on localhost + the LAN with pg_hba limited to the LAN; the NFS export stays LAN-scoped; remove the unauthenticated v2ray proxy. - tests: `security-firewall` asserts every host runs the shared firewall, has the LAN CIDR rule and no global ports.
This commit is contained in:
1 parent
2314754655
commit
e5b95affa6
23 files changed
+139
-169
No files matched your search
@@ -1,20 +1,40 @@
|
||||
{ lib, myvars, ... }:
|
||||
let
|
||||
inherit (myvars.networking) lanCidr;
|
||||
# The host that scrapes the exporters (VictoriaMetrics runs on youko).
|
||||
monitoringHost = myvars.networking.hostsAddr.youko.ipv4;
|
||||
in
|
||||
{
|
||||
# for security reasons, only open the following ports to the network by default.
|
||||
networking.firewall.allowedTCPPorts = [
|
||||
# localsend
|
||||
53317
|
||||
# Hosts bring their own firewall as defence in depth behind the router's
|
||||
# (which stays on, with port mappings for the few ports we need): the home
|
||||
# LAN and the tailnet are trusted equally (tighten the tailnet with Tailscale
|
||||
# ACLs), and everything else is denied on both address families.
|
||||
networking.nftables.enable = true;
|
||||
|
||||
# tcp ports for testing & sharing
|
||||
63080
|
||||
63081
|
||||
63082
|
||||
63083
|
||||
63084
|
||||
63085
|
||||
63086
|
||||
63087
|
||||
63088
|
||||
63089
|
||||
];
|
||||
# networking.firewall.allowedUDPPorts = [ ... ];
|
||||
networking.firewall = {
|
||||
enable = true;
|
||||
|
||||
# Nothing is opened to the Internet. LAN/tailnet/local-container access
|
||||
# comes from the rules below; per-service `openFirewall` ports are
|
||||
# suppressed.
|
||||
allowedTCPPorts = lib.mkForce [ ];
|
||||
allowedUDPPorts = lib.mkForce [ ];
|
||||
|
||||
extraInputRules = ''
|
||||
# node_exporter is scraped only by the monitoring host, not the whole
|
||||
# LAN/tailnet/local containers.
|
||||
ip saddr != ${monitoringHost} tcp dport 9100 drop
|
||||
|
||||
# The local container bridge and the tailnet have the same access as the
|
||||
# LAN. Kept after the drop above so neither can reach node_exporter.
|
||||
iifname "podman0" accept
|
||||
iifname "tailscale0" accept
|
||||
|
||||
# The home LAN is the trusted core.
|
||||
ip saddr ${lanCidr} accept
|
||||
ip6 saddr fe80::/10 accept
|
||||
# Tailscale's WireGuard port, for direct (non-DERP) connections.
|
||||
udp dport 41641 accept
|
||||
'';
|
||||
};
|
||||
}
|
||||
@@ -1,10 +0,0 @@
|
||||
# Desktops hold personal data and laptops join untrusted networks, so enable the
|
||||
# firewall here (repo-wide default is off, see modules/nixos/base/ssh.nix).
|
||||
# SSH/Tailscale/LocalSend/Sunshine keep working via their own `openFirewall` options.
|
||||
{
|
||||
networking.firewall = {
|
||||
enable = true;
|
||||
# Trust everything from the tailnet.
|
||||
trustedInterfaces = [ "tailscale0" ];
|
||||
};
|
||||
}
|
||||
@@ -15,16 +15,16 @@
|
||||
../base/ssh.nix
|
||||
../base/user-group.nix
|
||||
|
||||
# This server imports base files individually instead of the whole
|
||||
# modules/nixos/base group, so pull the shared firewall in explicitly.
|
||||
../base/networking/firewall.nix
|
||||
|
||||
../../base
|
||||
# AppArmor is wired via modules/nixos/base/default.nix for other hosts; this
|
||||
# aarch64 server imports base files individually, so add it explicitly.
|
||||
(mylib.relativeToRoot "hardening/apparmor")
|
||||
];
|
||||
|
||||
# Servers run on the trusted internal LAN (NAT'd; WAN protected at the router).
|
||||
# Keep the firewall off here; the secure default is ON (see modules/nixos/base/ssh.nix).
|
||||
networking.firewall.enable = false;
|
||||
|
||||
# Fix: jasper is marked as broken, refusing to evaluate.
|
||||
environment.enableAllTerminfo = lib.mkForce false;
|
||||
}
|
||||
@@ -13,6 +13,10 @@
|
||||
../base/ssh.nix
|
||||
../base/user-group.nix
|
||||
|
||||
# This server imports base files individually instead of the whole
|
||||
# modules/nixos/base group, so pull the shared firewall in explicitly.
|
||||
../base/networking/firewall.nix
|
||||
|
||||
../../base
|
||||
];
|
||||
}
|
||||
@@ -1,11 +1,11 @@
|
||||
{ lib, ... }:
|
||||
{ ... }:
|
||||
{
|
||||
imports = [
|
||||
../base
|
||||
../../base
|
||||
];
|
||||
|
||||
# Servers run on the trusted internal LAN (NAT'd; WAN protected at the router).
|
||||
# Keep the firewall off here; the secure default is ON (see modules/nixos/base/ssh.nix).
|
||||
networking.firewall.enable = false;
|
||||
# Servers used to keep the firewall off, trusting the router alone. They now
|
||||
# run the shared base firewall (modules/nixos/base/networking/firewall.nix)
|
||||
# like every other host, as defence in depth behind the router.
|
||||
}
|
||||
Reference in new issue
Block a user