nixos/home: Keep untrusted to the Internet
The routers reject new connections from the `untrusted` VLAN to internal destinations before the firewall's ICMP rules, then allow Internet transit via `wan` and `as211024`. The shared `lib.my.c.internalNets` also covers the modem's management subnet. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
+20
-2
@@ -363,6 +363,24 @@ instead anchor DNS on the VIPs via the shared `lib.my.c.home.vlanDns "<vlan>"` f
|
|||||||
`DNS` to `vips.<vlan>.{v4,v6}` and `Domains` to the advertised search list; the always-present
|
`DNS` to `vips.<vlan>.{v4,v6}` and `Domains` to the advertised search list; the always-present
|
||||||
static v4 VIP keeps resolution working even with v6 down.
|
static v4 VIP keeps resolution working even with v6 down.
|
||||||
|
|
||||||
|
#### Untrusted clients
|
||||||
|
|
||||||
|
The routers restrict clients on the `untrusted` VLAN to Internet destinations. The filter also
|
||||||
|
blocks access to colony, where the home prefixes are trusted across the mesh.
|
||||||
|
|
||||||
|
- `forward-early` sends new connections from `lan-untrusted` to `untrusted-internal`, which rejects
|
||||||
|
everything in `lib.my.c.internalNets`: private, CGNAT (Tailscale), link-local, multicast and
|
||||||
|
reserved IPv4, IPv6 ULA / link-local / multicast, and our own global IPv6 prefixes. It runs
|
||||||
|
before `forward`, whose ICMP rules would otherwise let pings through.
|
||||||
|
- `filter-untrusted` then accepts `wan` and `as211024` (IPv6 Internet transit) and rejects the
|
||||||
|
rest.
|
||||||
|
- Rejecting rather than dropping makes clients fall back from colony's IPv6 addresses (such as
|
||||||
|
`git.nul.ie`'s) to IPv4 immediately.
|
||||||
|
- Replies to connections from `hi` and `lo` are allowed, so trusted boxes can still reach
|
||||||
|
`untrusted` hosts.
|
||||||
|
- Traffic to the routers themselves goes through the same `input` rules as `wan`.
|
||||||
|
- Clients on `untrusted` share layer 2 with each other; the routers can't filter that.
|
||||||
|
|
||||||
#### DNS binding
|
#### DNS binding
|
||||||
|
|
||||||
`pdns-recursor` binds the VIPs directly; see
|
`pdns-recursor` binds the VIPs directly; see
|
||||||
@@ -406,8 +424,8 @@ The bare-metal backup uses DHCP from the Virgin Media modem on `wan` (VLAN 130),
|
|||||||
|
|
||||||
The full fabric story — which switch port carries what, why VLAN 10 is trunked untranslated,
|
The full fabric story — which switch port carries what, why VLAN 10 is trunked untranslated,
|
||||||
and the multi-ONT plan — is in [sites/home/switches.md](sites/home/switches.md); the
|
and the multi-ONT plan — is in [sites/home/switches.md](sites/home/switches.md); the
|
||||||
`my.homeRouter.*` options (`dns.wanSkipBroadcasts`, `firewall.untrustedRejectV4`) let each box
|
`my.homeRouter.dns.wanSkipBroadcasts` option lets each box tell `routing-common` about subnets
|
||||||
tell `routing-common` about subnets sharing its WAN interface.
|
sharing its WAN interface.
|
||||||
|
|
||||||
## The AS211024 L2 mesh
|
## The AS211024 L2 mesh
|
||||||
|
|
||||||
|
|||||||
@@ -68,15 +68,11 @@ uses the DOCSIS overhead preset.
|
|||||||
### Per-box `routing-common` options
|
### Per-box `routing-common` options
|
||||||
|
|
||||||
The modem's management subnet shares the `wan` interface, which `routing-common` itself knows
|
The modem's management subnet shares the `wan` interface, which `routing-common` itself knows
|
||||||
nothing about — it declares two per-box options
|
nothing about. This box sets `my.homeRouter.dns.wanSkipBroadcasts`
|
||||||
([`routing-common/default.nix`](../../../nixos/boxes/home/routing-common/default.nix)) that this
|
([`routing-common/default.nix`](../../../nixos/boxes/home/routing-common/default.nix)) to skip the
|
||||||
box sets:
|
modem subnet's broadcast address when auto-selecting the router's own `wan` A record for the zone's
|
||||||
|
LUA record. `untrusted` clients can't reach the modem subnet: it's private, so the
|
||||||
- `my.homeRouter.dns.wanSkipBroadcasts` — skip the modem subnet's broadcast address when
|
[`untrusted` filter](../../networking.md#untrusted-clients) rejects it.
|
||||||
auto-selecting the router's own `wan` A record for the zone's LUA record.
|
|
||||||
- `my.homeRouter.firewall.untrustedRejectV4` — reject untrusted clients from
|
|
||||||
reaching the modem subnet (needed only because it shares `wan`; WAN egress is otherwise
|
|
||||||
accepted).
|
|
||||||
|
|
||||||
## Switching (RSTP)
|
## Switching (RSTP)
|
||||||
|
|
||||||
|
|||||||
@@ -464,6 +464,22 @@ rec {
|
|||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
|
|
||||||
|
# Non-public destinations, plus our own IPv6 prefixes (trusted across the mesh), for keeping
|
||||||
|
# untrusted workloads to the Internet
|
||||||
|
internalNets = rec {
|
||||||
|
v4 = [
|
||||||
|
"0.0.0.0/8" "10.0.0.0/8" "100.64.0.0/10" "127.0.0.0/8" "169.254.0.0/16"
|
||||||
|
"172.16.0.0/12" "192.168.0.0/16" "224.0.0.0/4" "240.0.0.0/4"
|
||||||
|
];
|
||||||
|
v6 = [
|
||||||
|
"::/127" "::ffff:0:0/96" "fc00::/7" "fe80::/10" "ff00::/8"
|
||||||
|
] ++ map (p: colony.prefixes.${p}.v6) [ "home" "all" "cust" "as211024" ];
|
||||||
|
nftReject = ''
|
||||||
|
ip daddr { ${concatStringsSep ", " v4} } reject with icmpx admin-prohibited
|
||||||
|
ip6 daddr { ${concatStringsSep ", " v6} } reject with icmpx admin-prohibited
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
|
||||||
kelder = {
|
kelder = {
|
||||||
groups = {
|
groups = {
|
||||||
storage = 2000;
|
storage = 2000;
|
||||||
|
|||||||
@@ -94,11 +94,9 @@ in
|
|||||||
|
|
||||||
configuration = { lib, pkgs, config, assignments, allAssignments, ... }:
|
configuration = { lib, pkgs, config, assignments, allAssignments, ... }:
|
||||||
let
|
let
|
||||||
inherit (lib) mkIf mkMerge mkForce optionalString concatStringsSep;
|
inherit (lib) mkIf mkMerge mkForce;
|
||||||
inherit (lib.my) mkOpt' networkdAssignment;
|
inherit (lib.my) mkOpt' networkdAssignment;
|
||||||
inherit (lib.my.c) networkd;
|
inherit (lib.my.c) networkd;
|
||||||
|
|
||||||
cfg = config.my.homeRouter;
|
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
imports = map (m: import m index) [
|
imports = map (m: import m index) [
|
||||||
@@ -116,10 +114,6 @@ in
|
|||||||
Broadcast addresses to exclude when auto-selecting the router's own `wan` A record,
|
Broadcast addresses to exclude when auto-selecting the router's own `wan` A record,
|
||||||
for extra static subnets that share the `wan` interface.
|
for extra static subnets that share the `wan` interface.
|
||||||
'';
|
'';
|
||||||
firewall.untrustedRejectV4 = mkOpt' (listOf str) [ ] ''
|
|
||||||
IPv4 prefixes untrusted clients must be explicitly rejected from reaching. Only needed
|
|
||||||
for subnets sharing the `wan` interface, since `wan` egress is otherwise accepted.
|
|
||||||
'';
|
|
||||||
};
|
};
|
||||||
|
|
||||||
config = {
|
config = {
|
||||||
@@ -365,10 +359,16 @@ in
|
|||||||
meta l4proto udp ct state new jump routing-udp
|
meta l4proto udp ct state new jump routing-udp
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
# `untrusted` gets the Internet only: colony trusts all home prefixes across the
|
||||||
|
# mesh, and many devices trust anything on the LAN. Runs before `forward`, whose
|
||||||
|
# ICMP rules would otherwise let pings through.
|
||||||
|
chain untrusted-internal {
|
||||||
|
ct state established,related return
|
||||||
|
${lib.my.c.internalNets.nftReject}
|
||||||
|
}
|
||||||
chain filter-untrusted {
|
chain filter-untrusted {
|
||||||
${optionalString (cfg.firewall.untrustedRejectV4 != [ ]) "ip daddr { ${concatStringsSep ", " cfg.firewall.untrustedRejectV4} } reject"}
|
oifname { wan, as211024 } accept
|
||||||
oifname wan accept
|
reject with icmpx admin-prohibited
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
chain forward-early {
|
chain forward-early {
|
||||||
@@ -380,11 +380,13 @@ in
|
|||||||
# More Disney+ discrimination...
|
# More Disney+ discrimination...
|
||||||
# TODO: This prefix could change (random AWS block)
|
# TODO: This prefix could change (random AWS block)
|
||||||
ip6 daddr 2600:9000:2245::/48 drop
|
ip6 daddr 2600:9000:2245::/48 drop
|
||||||
|
|
||||||
|
iifname lan-untrusted jump untrusted-internal
|
||||||
}
|
}
|
||||||
chain forward {
|
chain forward {
|
||||||
${lib.my.c.as211024.nftTrust}
|
${lib.my.c.as211024.nftTrust}
|
||||||
iifname lan-untrusted jump filter-untrusted
|
iifname lan-untrusted jump filter-untrusted
|
||||||
iifname { wan, as211024, lan-untrusted } oifname { lan-hi, lan-lo } jump filter-routing
|
iifname { wan, as211024 } oifname { lan-hi, lan-lo } jump filter-routing
|
||||||
oifname as211024 accept
|
oifname as211024 accept
|
||||||
}
|
}
|
||||||
chain output { }
|
chain output { }
|
||||||
|
|||||||
@@ -203,11 +203,8 @@
|
|||||||
};
|
};
|
||||||
server.enable = true;
|
server.enable = true;
|
||||||
# The modem's management subnet shares the `wan` interface: skip its address when
|
# The modem's management subnet shares the `wan` interface: skip its address when
|
||||||
# picking our own wan A record, and reject untrusted clients from reaching it.
|
# picking our own wan A record
|
||||||
homeRouter = {
|
homeRouter.dns.wanSkipBroadcasts = [ (lib.my.netBroadcast prefixes.modem.v4) ];
|
||||||
dns.wanSkipBroadcasts = [ (lib.my.netBroadcast prefixes.modem.v4) ];
|
|
||||||
firewall.untrustedRejectV4 = [ prefixes.modem.v4 ];
|
|
||||||
};
|
|
||||||
# deploy.node.hostname = "192.168.68.2";
|
# deploy.node.hostname = "192.168.68.2";
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user