]> Git — Sourcephile - sourcephile-nix.git/blob - machines/losurdo/networking/nftables.nix
wireguard: setup intranet
[sourcephile-nix.git] / machines / losurdo / networking / nftables.nix
1 { pkgs, lib, config, machines, ... }:
2 let
3 inherit (builtins) hasAttr readFile;
4 inherit (pkgs.lib) unlinesAttrs;
5 inherit (config.users) users groups;
6 in
7 {
8 networking.firewall.enable = false;
9 security.lockKernelModules = false;
10 systemd.services.disable-kernel-module-loading.after = [ "nftables.service" ];
11 # echo -e "$(nix eval machines.losurdo.config.networking.nftables.ruleset)"
12 # nft list ruleset
13 networking.nftables = {
14 enable = true;
15 ruleset = lib.mkBefore ''
16 table inet filter {
17 chain net2fw {
18 # Some .nix append rules here with: add rule inet filter net2fw ...
19 }
20 chain fw2net {
21 tcp dport {80,443} counter accept comment "HTTP"
22 udp dport 123 skuid ${users.systemd-timesync.name} counter accept comment "NTP"
23 tcp dport 9418 counter accept comment "Git"
24
25 # Some .nix append rules here with: add rule inet filter fw2net ...
26 }
27 chain intra2fw {
28 # Some .nix append rules here with: add rule inet filter intra2fw ...
29 }
30 chain fw2intra {
31 # Some .nix append rules here with: add rule inet filter fw2intra ...
32 }
33
34 chain input {
35 type filter hook input priority 0
36 policy drop
37
38 iifname lo accept
39
40 # accept traffic already established
41 ct state {established, related} accept
42 ct state invalid drop
43
44 # admin services
45 tcp dport 22 counter accept comment "SSH"
46 udp dport 60000-61000 counter accept comment "Mosh"
47
48 # ICMP
49 ip6 nexthdr icmpv6 icmpv6 type { destination-unreachable, packet-too-big, time-exceeded, parameter-problem, nd-router-advert, nd-neighbor-solicit, nd-neighbor-advert, mld-listener-query, nd-router-solicit } accept
50 ip protocol icmp icmp type { destination-unreachable, router-advertisement, time-exceeded, parameter-problem } accept
51
52 # allow "ping"
53 ip6 nexthdr icmpv6 icmpv6 type echo-request accept
54 ip protocol icmp icmp type echo-request accept
55
56 # Some .nix append gotos here with: add rule inet filter input iffname ... goto ...
57 }
58 chain output {
59 type filter hook output priority 0
60 policy drop
61
62 oifname lo accept
63
64 ct state {related,established} accept
65 ct state invalid drop
66
67 icmp type echo-request counter accept comment "Ping"
68 tcp dport 22 counter accept comment "SSH"
69
70 # Some .nix append gotos here with: add rule inet filter output oifname ... goto ...
71 }
72 chain forward {
73 type filter hook forward priority 0
74 policy drop
75 drop
76 }
77 }
78 '';
79 };
80 }