mirror of
https://github.com/GrapheneOS/infrastructure.git
synced 2025-12-10 06:05:45 -05:00
move nftables configuration to a directory
This commit is contained in:
parent
c412fec336
commit
bd6f127acf
9 changed files with 0 additions and 0 deletions
139
nftables/nftables-attestation.conf
Normal file
139
nftables/nftables-attestation.conf
Normal file
|
|
@ -0,0 +1,139 @@
|
|||
#!/usr/bin/nft -f
|
||||
|
||||
flush ruleset
|
||||
|
||||
table inet filter {
|
||||
define ip-allowlist-ssh = {
|
||||
127.0.0.1,
|
||||
}
|
||||
|
||||
define ip6-allowlist-ssh = {
|
||||
::1,
|
||||
}
|
||||
|
||||
set ip-connlimit-ssh {
|
||||
type ipv4_addr
|
||||
flags dynamic
|
||||
}
|
||||
|
||||
set ip6-connlimit-ssh {
|
||||
type ipv6_addr
|
||||
flags dynamic
|
||||
}
|
||||
|
||||
set ip-connlimit-main {
|
||||
type ipv4_addr
|
||||
flags dynamic
|
||||
}
|
||||
|
||||
set ip6-connlimit-main {
|
||||
type ipv6_addr
|
||||
flags dynamic
|
||||
}
|
||||
|
||||
chain prerouting-raw {
|
||||
type filter hook prerouting priority raw
|
||||
|
||||
# drop packets without a reverse path (strict reverse path filtering)
|
||||
fib saddr . iif oif missing counter drop
|
||||
|
||||
iif lo notrack accept
|
||||
|
||||
# drop packets to address not configured on incoming interface (strong host model)
|
||||
#
|
||||
# ordered after accepting loopback to permit using external IPs via loopback
|
||||
fib daddr . iif type != { local, broadcast, multicast } counter drop
|
||||
|
||||
# handle new TCP connections beyond rate limit via synproxy to avoid conntrack table exhaustion
|
||||
tcp dport { 22, 80, 443 } tcp flags syn limit rate over 1024/second burst 128 packets counter notrack accept
|
||||
|
||||
meta l4proto { icmp, ipv6-icmp } notrack accept
|
||||
}
|
||||
|
||||
chain input {
|
||||
type filter hook input priority filter
|
||||
policy drop
|
||||
|
||||
tcp dport { 22, 80, 443 } goto input-tcp-service
|
||||
iif lo accept
|
||||
meta l4proto { icmp, ipv6-icmp } accept
|
||||
ct state vmap { new : goto graceful-reject, established : accept, related : accept }
|
||||
}
|
||||
|
||||
chain input-tcp-service {
|
||||
iif lo goto input-tcp-service-loopback
|
||||
|
||||
# for synproxy, SYN is untracked and first ACK is invalid which are handled via fallthrough
|
||||
ct state vmap { new : goto input-tcp-service-new, established : goto input-tcp-service-established, related : accept }
|
||||
|
||||
tcp dport 22 ip saddr @ip-connlimit-ssh counter reject with tcp reset
|
||||
tcp dport 22 ip6 saddr and ffff:ffff:ffff:ffff:ffff:: @ip6-connlimit-ssh counter reject with tcp reset
|
||||
tcp dport { 80, 443 } ip saddr @ip-connlimit-main counter reject with tcp reset
|
||||
tcp dport { 80, 443 } ip6 saddr and ffff:ffff:ffff:ffff:: @ip6-connlimit-main counter reject with tcp reset
|
||||
synproxy mss 1460 wscale 7 timestamp sack-perm
|
||||
}
|
||||
|
||||
chain input-tcp-service-new {
|
||||
tcp dport 22 ip saddr @ip-connlimit-ssh counter reject with tcp reset
|
||||
tcp dport 22 ip6 saddr and ffff:ffff:ffff:ffff:ffff:: @ip6-connlimit-ssh counter reject with tcp reset
|
||||
tcp dport { 80, 443 } ip saddr @ip-connlimit-main counter reject with tcp reset
|
||||
tcp dport { 80, 443 } ip6 saddr and ffff:ffff:ffff:ffff:: @ip6-connlimit-main counter reject with tcp reset
|
||||
accept
|
||||
}
|
||||
|
||||
# add connections established without synproxy to connection limit sets with limits enforced
|
||||
chain input-tcp-service-established {
|
||||
ct mark 0x1 accept
|
||||
tcp dport 22 ip saddr != $ip-allowlist-ssh add @ip-connlimit-ssh { ip saddr ct count over 1 } counter reject with tcp reset
|
||||
tcp dport 22 ip6 saddr != $ip6-allowlist-ssh add @ip6-connlimit-ssh { ip6 saddr and ffff:ffff:ffff:ffff:ffff:: ct count over 1 } counter reject with tcp reset
|
||||
tcp dport { 80, 443 } add @ip-connlimit-main { ip saddr ct count over 32 } counter reject with tcp reset
|
||||
tcp dport { 80, 443 } add @ip6-connlimit-main { ip6 saddr and ffff:ffff:ffff:ffff:: ct count over 32 } counter reject with tcp reset
|
||||
ct mark set 0x1 accept
|
||||
}
|
||||
|
||||
# add connections established with synproxy to connection limit sets with limits enforced
|
||||
chain input-tcp-service-loopback {
|
||||
tcp flags != syn accept
|
||||
tcp dport 22 ip saddr != $ip-allowlist-ssh add @ip-connlimit-ssh { ip saddr ct count over 1 } counter reject with tcp reset
|
||||
tcp dport 22 ip6 saddr != $ip6-allowlist-ssh add @ip6-connlimit-ssh { ip6 saddr and ffff:ffff:ffff:ffff:ffff:: ct count over 1 } counter reject with tcp reset
|
||||
tcp dport { 80, 443 } add @ip-connlimit-main { ip saddr ct count over 32 } counter reject with tcp reset
|
||||
tcp dport { 80, 443 } add @ip6-connlimit-main { ip6 saddr and ffff:ffff:ffff:ffff:: ct count over 32 } counter reject with tcp reset
|
||||
ct mark set 0x1 accept
|
||||
}
|
||||
|
||||
chain forward {
|
||||
type filter hook forward priority filter
|
||||
policy drop
|
||||
}
|
||||
|
||||
chain output-raw {
|
||||
type filter hook output priority raw
|
||||
|
||||
oif lo notrack accept
|
||||
meta l4proto { icmp, ipv6-icmp } notrack accept
|
||||
}
|
||||
|
||||
chain output {
|
||||
type filter hook output priority filter
|
||||
|
||||
oif lo goto output-loopback
|
||||
skuid != { root, systemd-network, unbound, chrony, http, attestation } counter goto graceful-reject
|
||||
}
|
||||
|
||||
chain output-loopback {
|
||||
skuid unbound meta l4proto { tcp, udp } th sport 53 th dport >= 1024 th dport != 8080 accept
|
||||
skuid { chrony, attestation } meta l4proto { tcp, udp } th sport >= 1024 th sport != 8080 th dport 53 accept
|
||||
|
||||
skuid attestation tcp sport 8080 tcp dport >= 1024 tcp dport != 8080 accept
|
||||
skuid http tcp sport >= 1024 tcp sport != 8080 tcp dport 8080 accept
|
||||
|
||||
skuid != root counter goto graceful-reject
|
||||
accept
|
||||
}
|
||||
|
||||
chain graceful-reject {
|
||||
meta l4proto udp reject
|
||||
meta l4proto tcp reject with tcp reset
|
||||
reject
|
||||
}
|
||||
}
|
||||
136
nftables/nftables-discuss.conf
Normal file
136
nftables/nftables-discuss.conf
Normal file
|
|
@ -0,0 +1,136 @@
|
|||
#!/usr/bin/nft -f
|
||||
|
||||
flush ruleset
|
||||
|
||||
table inet filter {
|
||||
define ip-allowlist-ssh = {
|
||||
127.0.0.1,
|
||||
}
|
||||
|
||||
define ip6-allowlist-ssh = {
|
||||
::1,
|
||||
}
|
||||
|
||||
set ip-connlimit-ssh {
|
||||
type ipv4_addr
|
||||
flags dynamic
|
||||
}
|
||||
|
||||
set ip6-connlimit-ssh {
|
||||
type ipv6_addr
|
||||
flags dynamic
|
||||
}
|
||||
|
||||
set ip-connlimit-main {
|
||||
type ipv4_addr
|
||||
flags dynamic
|
||||
}
|
||||
|
||||
set ip6-connlimit-main {
|
||||
type ipv6_addr
|
||||
flags dynamic
|
||||
}
|
||||
|
||||
chain prerouting-raw {
|
||||
type filter hook prerouting priority raw
|
||||
|
||||
# drop packets without a reverse path (strict reverse path filtering)
|
||||
fib saddr . iif oif missing counter drop
|
||||
|
||||
iif lo notrack accept
|
||||
|
||||
# drop packets to address not configured on incoming interface (strong host model)
|
||||
#
|
||||
# ordered after accepting loopback to permit using external IPs via loopback
|
||||
fib daddr . iif type != { local, broadcast, multicast } counter drop
|
||||
|
||||
# handle new TCP connections beyond rate limit via synproxy to avoid conntrack table exhaustion
|
||||
tcp dport { 22, 80, 443 } tcp flags syn limit rate over 1024/second burst 128 packets counter notrack accept
|
||||
|
||||
meta l4proto { icmp, ipv6-icmp } notrack accept
|
||||
}
|
||||
|
||||
chain input {
|
||||
type filter hook input priority filter
|
||||
policy drop
|
||||
|
||||
tcp dport { 22, 80, 443 } goto input-tcp-service
|
||||
iif lo accept
|
||||
meta l4proto { icmp, ipv6-icmp } accept
|
||||
ct state vmap { new : goto graceful-reject, established : accept, related : accept }
|
||||
}
|
||||
|
||||
chain input-tcp-service {
|
||||
iif lo goto input-tcp-service-loopback
|
||||
|
||||
# for synproxy, SYN is untracked and first ACK is invalid which are handled via fallthrough
|
||||
ct state vmap { new : goto input-tcp-service-new, established : goto input-tcp-service-established, related : accept }
|
||||
|
||||
tcp dport 22 ip saddr @ip-connlimit-ssh counter reject with tcp reset
|
||||
tcp dport 22 ip6 saddr and ffff:ffff:ffff:ffff:ffff:: @ip6-connlimit-ssh counter reject with tcp reset
|
||||
tcp dport { 80, 443 } ip saddr @ip-connlimit-main counter reject with tcp reset
|
||||
tcp dport { 80, 443 } ip6 saddr and ffff:ffff:ffff:ffff:: @ip6-connlimit-main counter reject with tcp reset
|
||||
synproxy mss 1460 wscale 7 timestamp sack-perm
|
||||
}
|
||||
|
||||
chain input-tcp-service-new {
|
||||
tcp dport 22 ip saddr @ip-connlimit-ssh counter reject with tcp reset
|
||||
tcp dport 22 ip6 saddr and ffff:ffff:ffff:ffff:ffff:: @ip6-connlimit-ssh counter reject with tcp reset
|
||||
tcp dport { 80, 443 } ip saddr @ip-connlimit-main counter reject with tcp reset
|
||||
tcp dport { 80, 443 } ip6 saddr and ffff:ffff:ffff:ffff:: @ip6-connlimit-main counter reject with tcp reset
|
||||
accept
|
||||
}
|
||||
|
||||
# add connections established without synproxy to connection limit sets with limits enforced
|
||||
chain input-tcp-service-established {
|
||||
ct mark 0x1 accept
|
||||
tcp dport 22 ip saddr != $ip-allowlist-ssh add @ip-connlimit-ssh { ip saddr ct count over 1 } counter reject with tcp reset
|
||||
tcp dport 22 ip6 saddr != $ip6-allowlist-ssh add @ip6-connlimit-ssh { ip6 saddr and ffff:ffff:ffff:ffff:ffff:: ct count over 1 } counter reject with tcp reset
|
||||
tcp dport { 80, 443 } add @ip-connlimit-main { ip saddr ct count over 32 } counter reject with tcp reset
|
||||
tcp dport { 80, 443 } add @ip6-connlimit-main { ip6 saddr and ffff:ffff:ffff:ffff:: ct count over 32 } counter reject with tcp reset
|
||||
ct mark set 0x1 accept
|
||||
}
|
||||
|
||||
# add connections established with synproxy to connection limit sets with limits enforced
|
||||
chain input-tcp-service-loopback {
|
||||
tcp flags != syn accept
|
||||
tcp dport 22 ip saddr != $ip-allowlist-ssh add @ip-connlimit-ssh { ip saddr ct count over 1 } counter reject with tcp reset
|
||||
tcp dport 22 ip6 saddr != $ip6-allowlist-ssh add @ip6-connlimit-ssh { ip6 saddr and ffff:ffff:ffff:ffff:ffff:: ct count over 1 } counter reject with tcp reset
|
||||
tcp dport { 80, 443 } add @ip-connlimit-main { ip saddr ct count over 32 } counter reject with tcp reset
|
||||
tcp dport { 80, 443 } add @ip6-connlimit-main { ip6 saddr and ffff:ffff:ffff:ffff:: ct count over 32 } counter reject with tcp reset
|
||||
ct mark set 0x1 accept
|
||||
}
|
||||
|
||||
chain forward {
|
||||
type filter hook forward priority filter
|
||||
policy drop
|
||||
}
|
||||
|
||||
chain output-raw {
|
||||
type filter hook output priority raw
|
||||
|
||||
oif lo notrack accept
|
||||
meta l4proto { icmp, ipv6-icmp } notrack accept
|
||||
}
|
||||
|
||||
chain output {
|
||||
type filter hook output priority filter
|
||||
|
||||
oif lo goto output-loopback
|
||||
skuid != { root, systemd-network, unbound, chrony, http, flarum, flarum-admin, geoipupdate } counter goto graceful-reject
|
||||
}
|
||||
|
||||
chain output-loopback {
|
||||
skuid unbound meta l4proto { tcp, udp } th sport 53 th dport >= 1024 accept
|
||||
skuid { chrony, http, flarum, flarum-admin, geoipupdate } meta l4proto { tcp, udp } th sport >= 1024 th dport 53 accept
|
||||
|
||||
skuid != root counter goto graceful-reject
|
||||
accept
|
||||
}
|
||||
|
||||
chain graceful-reject {
|
||||
meta l4proto udp reject
|
||||
meta l4proto tcp reject with tcp reset
|
||||
reject
|
||||
}
|
||||
}
|
||||
136
nftables/nftables-mail.conf
Normal file
136
nftables/nftables-mail.conf
Normal file
|
|
@ -0,0 +1,136 @@
|
|||
#!/usr/bin/nft -f
|
||||
|
||||
flush ruleset
|
||||
|
||||
table inet filter {
|
||||
define ip-allowlist-ssh = {
|
||||
127.0.0.1,
|
||||
}
|
||||
|
||||
define ip6-allowlist-ssh = {
|
||||
::1,
|
||||
}
|
||||
|
||||
set ip-connlimit-ssh {
|
||||
type ipv4_addr
|
||||
flags dynamic
|
||||
}
|
||||
|
||||
set ip6-connlimit-ssh {
|
||||
type ipv6_addr
|
||||
flags dynamic
|
||||
}
|
||||
|
||||
set ip-connlimit-main {
|
||||
type ipv4_addr
|
||||
flags dynamic
|
||||
}
|
||||
|
||||
set ip6-connlimit-main {
|
||||
type ipv6_addr
|
||||
flags dynamic
|
||||
}
|
||||
|
||||
chain prerouting-raw {
|
||||
type filter hook prerouting priority raw
|
||||
|
||||
# drop packets without a reverse path (strict reverse path filtering)
|
||||
fib saddr . iif oif missing counter drop
|
||||
|
||||
iif lo notrack accept
|
||||
|
||||
# drop packets to address not configured on incoming interface (strong host model)
|
||||
#
|
||||
# ordered after accepting loopback to permit using external IPs via loopback
|
||||
fib daddr . iif type != { local, broadcast, multicast } counter drop
|
||||
|
||||
# handle new TCP connections beyond rate limit via synproxy to avoid conntrack table exhaustion
|
||||
tcp dport { 22, 25, 80, 443, 465, 993 } tcp flags syn limit rate over 1024/second burst 128 packets counter notrack accept
|
||||
|
||||
meta l4proto { icmp, ipv6-icmp } notrack accept
|
||||
}
|
||||
|
||||
chain input {
|
||||
type filter hook input priority filter
|
||||
policy drop
|
||||
|
||||
tcp dport { 22, 25, 80, 443, 465, 993 } goto input-tcp-service
|
||||
iif lo accept
|
||||
meta l4proto { icmp, ipv6-icmp } accept
|
||||
ct state vmap { new : goto graceful-reject, established : accept, related : accept }
|
||||
}
|
||||
|
||||
chain input-tcp-service {
|
||||
iif lo goto input-tcp-service-loopback
|
||||
|
||||
# for synproxy, SYN is untracked and first ACK is invalid which are handled via fallthrough
|
||||
ct state vmap { new : goto input-tcp-service-new, established : goto input-tcp-service-established, related : accept }
|
||||
|
||||
tcp dport 22 ip saddr @ip-connlimit-ssh counter reject with tcp reset
|
||||
tcp dport 22 ip6 saddr and ffff:ffff:ffff:ffff:ffff:: @ip6-connlimit-ssh counter reject with tcp reset
|
||||
tcp dport { 25, 80, 443, 465, 993 } ip saddr @ip-connlimit-main counter reject with tcp reset
|
||||
tcp dport { 25, 80, 443, 465, 993 } ip6 saddr and ffff:ffff:ffff:ffff:: @ip6-connlimit-main counter reject with tcp reset
|
||||
synproxy mss 1460 wscale 7 timestamp sack-perm
|
||||
}
|
||||
|
||||
chain input-tcp-service-new {
|
||||
tcp dport 22 ip saddr @ip-connlimit-ssh counter reject with tcp reset
|
||||
tcp dport 22 ip6 saddr and ffff:ffff:ffff:ffff:ffff:: @ip6-connlimit-ssh counter reject with tcp reset
|
||||
tcp dport { 25, 80, 443, 465, 993 } ip saddr @ip-connlimit-main counter reject with tcp reset
|
||||
tcp dport { 25, 80, 443, 465, 993 } ip6 saddr and ffff:ffff:ffff:ffff:: @ip6-connlimit-main counter reject with tcp reset
|
||||
accept
|
||||
}
|
||||
|
||||
# add connections established without synproxy to connection limit sets with limits enforced
|
||||
chain input-tcp-service-established {
|
||||
ct mark 0x1 accept
|
||||
tcp dport 22 ip saddr != $ip-allowlist-ssh add @ip-connlimit-ssh { ip saddr ct count over 1 } counter reject with tcp reset
|
||||
tcp dport 22 ip6 saddr != $ip6-allowlist-ssh add @ip6-connlimit-ssh { ip6 saddr and ffff:ffff:ffff:ffff:ffff:: ct count over 1 } counter reject with tcp reset
|
||||
tcp dport { 25, 80, 443, 465, 993 } add @ip-connlimit-main { ip saddr ct count over 32 } counter reject with tcp reset
|
||||
tcp dport { 25, 80, 443, 465, 993 } add @ip6-connlimit-main { ip6 saddr and ffff:ffff:ffff:ffff:: ct count over 32 } counter reject with tcp reset
|
||||
ct mark set 0x1 accept
|
||||
}
|
||||
|
||||
# add connections established with synproxy to connection limit sets with limits enforced
|
||||
chain input-tcp-service-loopback {
|
||||
tcp flags != syn accept
|
||||
tcp dport 22 ip saddr != $ip-allowlist-ssh add @ip-connlimit-ssh { ip saddr ct count over 1 } counter reject with tcp reset
|
||||
tcp dport 22 ip6 saddr != $ip6-allowlist-ssh add @ip6-connlimit-ssh { ip6 saddr and ffff:ffff:ffff:ffff:ffff:: ct count over 1 } counter reject with tcp reset
|
||||
tcp dport { 25, 80, 443, 465, 993 } add @ip-connlimit-main { ip saddr ct count over 32 } counter reject with tcp reset
|
||||
tcp dport { 25, 80, 443, 465, 993 } add @ip6-connlimit-main { ip6 saddr and ffff:ffff:ffff:ffff:: ct count over 32 } counter reject with tcp reset
|
||||
ct mark set 0x1 accept
|
||||
}
|
||||
|
||||
chain forward {
|
||||
type filter hook forward priority filter
|
||||
policy drop
|
||||
}
|
||||
|
||||
chain output-raw {
|
||||
type filter hook output priority raw
|
||||
|
||||
oif lo notrack accept
|
||||
meta l4proto { icmp, ipv6-icmp } notrack accept
|
||||
}
|
||||
|
||||
chain output {
|
||||
type filter hook output priority filter
|
||||
|
||||
oif lo goto output-loopback
|
||||
skuid != { root, systemd-network, unbound, chrony, postfix, dovecot, dovenull, http } counter goto graceful-reject
|
||||
}
|
||||
|
||||
chain output-loopback {
|
||||
skuid unbound meta l4proto { tcp, udp } th sport 53 th dport >= 1024 accept
|
||||
skuid { chrony, postfix, opendkim, opendmarc, policyd-spf } meta l4proto { tcp, udp } th sport >= 1024 th dport 53 accept
|
||||
|
||||
skuid != root counter goto graceful-reject
|
||||
accept
|
||||
}
|
||||
|
||||
chain graceful-reject {
|
||||
meta l4proto udp reject
|
||||
meta l4proto tcp reject with tcp reset
|
||||
reject
|
||||
}
|
||||
}
|
||||
146
nftables/nftables-matrix.conf
Normal file
146
nftables/nftables-matrix.conf
Normal file
|
|
@ -0,0 +1,146 @@
|
|||
#!/usr/bin/nft -f
|
||||
|
||||
flush ruleset
|
||||
|
||||
table inet filter {
|
||||
define ip-allowlist-ssh = {
|
||||
127.0.0.1,
|
||||
}
|
||||
|
||||
define ip6-allowlist-ssh = {
|
||||
::1,
|
||||
}
|
||||
|
||||
set ip-connlimit-ssh {
|
||||
type ipv4_addr
|
||||
flags dynamic
|
||||
}
|
||||
|
||||
set ip6-connlimit-ssh {
|
||||
type ipv6_addr
|
||||
flags dynamic
|
||||
}
|
||||
|
||||
set ip-connlimit-main {
|
||||
type ipv4_addr
|
||||
flags dynamic
|
||||
}
|
||||
|
||||
set ip6-connlimit-main {
|
||||
type ipv6_addr
|
||||
flags dynamic
|
||||
}
|
||||
|
||||
chain prerouting-raw {
|
||||
type filter hook prerouting priority raw
|
||||
|
||||
# drop packets without a reverse path (strict reverse path filtering)
|
||||
fib saddr . iif oif missing counter drop
|
||||
|
||||
iif lo notrack accept
|
||||
|
||||
# drop packets to address not configured on incoming interface (strong host model)
|
||||
#
|
||||
# ordered after accepting loopback to permit using external IPs via loopback
|
||||
fib daddr . iif type != { local, broadcast, multicast } counter drop
|
||||
|
||||
# handle new TCP connections beyond rate limit via synproxy to avoid conntrack table exhaustion
|
||||
tcp dport { 22, 80, 443 } tcp flags syn limit rate over 1024/second burst 128 packets counter notrack accept
|
||||
|
||||
meta l4proto { icmp, ipv6-icmp } notrack accept
|
||||
}
|
||||
|
||||
chain input {
|
||||
type filter hook input priority filter
|
||||
policy drop
|
||||
|
||||
tcp dport { 22, 80, 443 } goto input-tcp-service
|
||||
iif lo accept
|
||||
meta l4proto { icmp, ipv6-icmp } accept
|
||||
ct state vmap { new : goto graceful-reject, established : accept, related : accept }
|
||||
}
|
||||
|
||||
chain input-tcp-service {
|
||||
iif lo goto input-tcp-service-loopback
|
||||
|
||||
# for synproxy, SYN is untracked and first ACK is invalid which are handled via fallthrough
|
||||
ct state vmap { new : goto input-tcp-service-new, established : goto input-tcp-service-established, related : accept }
|
||||
|
||||
tcp dport 22 ip saddr @ip-connlimit-ssh counter reject with tcp reset
|
||||
tcp dport 22 ip6 saddr and ffff:ffff:ffff:ffff:ffff:: @ip6-connlimit-ssh counter reject with tcp reset
|
||||
tcp dport { 80, 443 } ip saddr @ip-connlimit-main counter reject with tcp reset
|
||||
tcp dport { 80, 443 } ip6 saddr and ffff:ffff:ffff:ffff:: @ip6-connlimit-main counter reject with tcp reset
|
||||
synproxy mss 1460 wscale 7 timestamp sack-perm
|
||||
}
|
||||
|
||||
chain input-tcp-service-new {
|
||||
tcp dport 22 ip saddr @ip-connlimit-ssh counter reject with tcp reset
|
||||
tcp dport 22 ip6 saddr and ffff:ffff:ffff:ffff:ffff:: @ip6-connlimit-ssh counter reject with tcp reset
|
||||
tcp dport { 80, 443 } ip saddr @ip-connlimit-main counter reject with tcp reset
|
||||
tcp dport { 80, 443 } ip6 saddr and ffff:ffff:ffff:ffff:: @ip6-connlimit-main counter reject with tcp reset
|
||||
accept
|
||||
}
|
||||
|
||||
# add connections established without synproxy to connection limit sets with limits enforced
|
||||
chain input-tcp-service-established {
|
||||
ct mark 0x1 accept
|
||||
tcp dport 22 ip saddr != $ip-allowlist-ssh add @ip-connlimit-ssh { ip saddr ct count over 1 } counter reject with tcp reset
|
||||
tcp dport 22 ip6 saddr != $ip6-allowlist-ssh add @ip6-connlimit-ssh { ip6 saddr and ffff:ffff:ffff:ffff:ffff:: ct count over 1 } counter reject with tcp reset
|
||||
tcp dport { 80, 443 } add @ip-connlimit-main { ip saddr ct count over 32 } counter reject with tcp reset
|
||||
tcp dport { 80, 443 } add @ip6-connlimit-main { ip6 saddr and ffff:ffff:ffff:ffff:: ct count over 32 } counter reject with tcp reset
|
||||
ct mark set 0x1 accept
|
||||
}
|
||||
|
||||
# add connections established with synproxy to connection limit sets with limits enforced
|
||||
chain input-tcp-service-loopback {
|
||||
tcp flags != syn accept
|
||||
tcp dport 22 ip saddr != $ip-allowlist-ssh add @ip-connlimit-ssh { ip saddr ct count over 1 } counter reject with tcp reset
|
||||
tcp dport 22 ip6 saddr != $ip6-allowlist-ssh add @ip6-connlimit-ssh { ip6 saddr and ffff:ffff:ffff:ffff:ffff:: ct count over 1 } counter reject with tcp reset
|
||||
tcp dport { 80, 443 } add @ip-connlimit-main { ip saddr ct count over 32 } counter reject with tcp reset
|
||||
tcp dport { 80, 443 } add @ip6-connlimit-main { ip6 saddr and ffff:ffff:ffff:ffff:: ct count over 32 } counter reject with tcp reset
|
||||
ct mark set 0x1 accept
|
||||
}
|
||||
|
||||
chain forward {
|
||||
type filter hook forward priority filter
|
||||
policy drop
|
||||
}
|
||||
|
||||
chain output-raw {
|
||||
type filter hook output priority raw
|
||||
|
||||
oif lo notrack accept
|
||||
meta l4proto { icmp, ipv6-icmp } notrack accept
|
||||
}
|
||||
|
||||
chain output {
|
||||
type filter hook output priority filter
|
||||
|
||||
oif lo goto output-loopback
|
||||
skuid != { root, systemd-network, unbound, chrony, http, synapse, matterbridge } counter goto graceful-reject
|
||||
}
|
||||
|
||||
chain output-loopback {
|
||||
skuid unbound meta l4proto { tcp, udp } th sport 53 th dport >= 1024 th dport != 8008 accept
|
||||
skuid { chrony, synapse, matterbridge } meta l4proto { tcp, udp } th sport >= 1024 th sport != 8008 th dport 53 accept
|
||||
|
||||
skuid postgres udp sport >= 1024 udp sport != 8008 udp dport >= 1024 udp dport != 8008 accept
|
||||
|
||||
skuid synapse tcp sport 8008 tcp dport >= 1024 tcp dport != 8008 accept
|
||||
skuid http tcp sport >= 1024 tcp sport != 8008 tcp dport 8008 accept
|
||||
skuid mjolnir tcp sport >= 1024 tcp sport != 8008 tcp dport 8008 accept
|
||||
|
||||
skuid http tcp sport 443 tcp dport >= 1024 tcp dport != 8008 accept
|
||||
skuid matterbridge tcp sport >= 1024 tcp sport != 8008 tcp dport 443 accept
|
||||
skuid synapse tcp sport >= 1024 tcp sport != 8008 tcp dport 443 accept
|
||||
|
||||
skuid != root counter goto graceful-reject
|
||||
accept
|
||||
}
|
||||
|
||||
chain graceful-reject {
|
||||
meta l4proto udp reject
|
||||
meta l4proto tcp reject with tcp reset
|
||||
reject
|
||||
}
|
||||
}
|
||||
141
nftables/nftables-network.conf
Normal file
141
nftables/nftables-network.conf
Normal file
|
|
@ -0,0 +1,141 @@
|
|||
#!/usr/bin/nft -f
|
||||
|
||||
flush ruleset
|
||||
|
||||
table inet filter {
|
||||
define ip-allowlist-ssh = {
|
||||
127.0.0.1,
|
||||
51.222.159.116, # 0.grapheneos.network
|
||||
}
|
||||
|
||||
define ip6-allowlist-ssh = {
|
||||
::1,
|
||||
2607:5300:205:200::2584, # 0.grapheneos.network
|
||||
}
|
||||
|
||||
set ip-connlimit-ssh {
|
||||
type ipv4_addr
|
||||
flags dynamic
|
||||
}
|
||||
|
||||
set ip6-connlimit-ssh {
|
||||
type ipv6_addr
|
||||
flags dynamic
|
||||
}
|
||||
|
||||
set ip-connlimit-main {
|
||||
type ipv4_addr
|
||||
flags dynamic
|
||||
}
|
||||
|
||||
set ip6-connlimit-main {
|
||||
type ipv6_addr
|
||||
flags dynamic
|
||||
}
|
||||
|
||||
chain prerouting-raw {
|
||||
type filter hook prerouting priority raw
|
||||
|
||||
# drop packets without a reverse path (strict reverse path filtering)
|
||||
fib saddr . iif oif missing counter drop
|
||||
|
||||
iif lo notrack accept
|
||||
|
||||
# drop packets to address not configured on incoming interface (strong host model)
|
||||
#
|
||||
# ordered after accepting loopback to permit using external IPs via loopback
|
||||
fib daddr . iif type != { local, broadcast, multicast } counter drop
|
||||
|
||||
# handle new TCP connections beyond rate limit via synproxy to avoid conntrack table exhaustion
|
||||
tcp dport { 22, 80, 443, 7275 } tcp flags syn limit rate over 1024/second burst 128 packets counter notrack accept
|
||||
|
||||
udp dport 123 notrack accept
|
||||
meta l4proto { icmp, ipv6-icmp } notrack accept
|
||||
}
|
||||
|
||||
chain input {
|
||||
type filter hook input priority filter
|
||||
policy drop
|
||||
|
||||
tcp dport { 22, 80, 443, 7275 } goto input-tcp-service
|
||||
iif lo accept
|
||||
udp dport 123 accept
|
||||
meta l4proto { icmp, ipv6-icmp } accept
|
||||
ct state vmap { new : goto graceful-reject, established : accept, related : accept }
|
||||
}
|
||||
|
||||
chain input-tcp-service {
|
||||
iif lo goto input-tcp-service-loopback
|
||||
|
||||
# for synproxy, SYN is untracked and first ACK is invalid which are handled via fallthrough
|
||||
ct state vmap { new : goto input-tcp-service-new, established : goto input-tcp-service-established, related : accept }
|
||||
|
||||
tcp dport 22 ip saddr @ip-connlimit-ssh counter reject with tcp reset
|
||||
tcp dport 22 ip6 saddr and ffff:ffff:ffff:ffff:ffff:: @ip6-connlimit-ssh counter reject with tcp reset
|
||||
tcp dport { 80, 443, 7275 } ip saddr @ip-connlimit-main counter reject with tcp reset
|
||||
tcp dport { 80, 443, 7275 } ip6 saddr and ffff:ffff:ffff:ffff:: @ip6-connlimit-main counter reject with tcp reset
|
||||
synproxy mss 1460 wscale 7 timestamp sack-perm
|
||||
}
|
||||
|
||||
chain input-tcp-service-new {
|
||||
tcp dport 22 ip saddr @ip-connlimit-ssh counter reject with tcp reset
|
||||
tcp dport 22 ip6 saddr and ffff:ffff:ffff:ffff:ffff:: @ip6-connlimit-ssh counter reject with tcp reset
|
||||
tcp dport { 80, 443, 7275 } ip saddr @ip-connlimit-main counter reject with tcp reset
|
||||
tcp dport { 80, 443, 7275 } ip6 saddr and ffff:ffff:ffff:ffff:: @ip6-connlimit-main counter reject with tcp reset
|
||||
accept
|
||||
}
|
||||
|
||||
# add connections established without synproxy to connection limit sets with limits enforced
|
||||
chain input-tcp-service-established {
|
||||
ct mark 0x1 accept
|
||||
tcp dport 22 ip saddr != $ip-allowlist-ssh add @ip-connlimit-ssh { ip saddr ct count over 1 } counter reject with tcp reset
|
||||
tcp dport 22 ip6 saddr != $ip6-allowlist-ssh add @ip6-connlimit-ssh { ip6 saddr and ffff:ffff:ffff:ffff:ffff:: ct count over 1 } counter reject with tcp reset
|
||||
tcp dport { 80, 443, 7275 } add @ip-connlimit-main { ip saddr ct count over 32 } counter reject with tcp reset
|
||||
tcp dport { 80, 443, 7275 } add @ip6-connlimit-main { ip6 saddr and ffff:ffff:ffff:ffff:: ct count over 32 } counter reject with tcp reset
|
||||
ct mark set 0x1 accept
|
||||
}
|
||||
|
||||
# add connections established with synproxy to connection limit sets with limits enforced
|
||||
chain input-tcp-service-loopback {
|
||||
tcp flags != syn accept
|
||||
tcp dport 22 ip saddr != $ip-allowlist-ssh add @ip-connlimit-ssh { ip saddr ct count over 1 } counter reject with tcp reset
|
||||
tcp dport 22 ip6 saddr != $ip6-allowlist-ssh add @ip6-connlimit-ssh { ip6 saddr and ffff:ffff:ffff:ffff:ffff:: ct count over 1 } counter reject with tcp reset
|
||||
tcp dport { 80, 443, 7275 } add @ip-connlimit-main { ip saddr ct count over 32 } counter reject with tcp reset
|
||||
tcp dport { 80, 443, 7275 } add @ip6-connlimit-main { ip6 saddr and ffff:ffff:ffff:ffff:: ct count over 32 } counter reject with tcp reset
|
||||
ct mark set 0x1 accept
|
||||
}
|
||||
|
||||
chain forward {
|
||||
type filter hook forward priority filter
|
||||
policy drop
|
||||
}
|
||||
|
||||
chain output-raw {
|
||||
type filter hook output priority raw
|
||||
|
||||
oif lo notrack accept
|
||||
udp sport 123 notrack accept
|
||||
meta l4proto { icmp, ipv6-icmp } notrack accept
|
||||
}
|
||||
|
||||
chain output {
|
||||
type filter hook output priority filter
|
||||
|
||||
oif lo goto output-loopback
|
||||
skuid != { root, systemd-network, unbound, chrony, http } counter goto graceful-reject
|
||||
}
|
||||
|
||||
chain output-loopback {
|
||||
skuid unbound meta l4proto { tcp, udp } th sport 53 th dport >= 1024 accept
|
||||
skuid { chrony, http } meta l4proto { tcp, udp } th sport >= 1024 th dport 53 accept
|
||||
|
||||
skuid != root counter goto graceful-reject
|
||||
accept
|
||||
}
|
||||
|
||||
chain graceful-reject {
|
||||
meta l4proto udp reject
|
||||
meta l4proto tcp reject with tcp reset
|
||||
reject
|
||||
}
|
||||
}
|
||||
145
nftables/nftables-ns1.conf
Normal file
145
nftables/nftables-ns1.conf
Normal file
|
|
@ -0,0 +1,145 @@
|
|||
#!/usr/bin/nft -f
|
||||
|
||||
flush ruleset
|
||||
|
||||
table inet filter {
|
||||
define ip-allowlist-ssh = {
|
||||
127.0.0.1,
|
||||
}
|
||||
|
||||
define ip6-allowlist-ssh = {
|
||||
::1,
|
||||
}
|
||||
|
||||
set ip-connlimit-ssh {
|
||||
type ipv4_addr
|
||||
flags dynamic
|
||||
}
|
||||
|
||||
set ip6-connlimit-ssh {
|
||||
type ipv6_addr
|
||||
flags dynamic
|
||||
}
|
||||
|
||||
set ip-connlimit-main {
|
||||
type ipv4_addr
|
||||
flags dynamic
|
||||
}
|
||||
|
||||
set ip6-connlimit-main {
|
||||
type ipv6_addr
|
||||
flags dynamic
|
||||
}
|
||||
|
||||
chain prerouting-raw {
|
||||
type filter hook prerouting priority raw
|
||||
|
||||
# drop packets without a reverse path (strict reverse path filtering)
|
||||
fib saddr . iif oif missing counter drop
|
||||
|
||||
iif lo notrack accept
|
||||
|
||||
# drop packets to address not configured on incoming interface (strong host model)
|
||||
#
|
||||
# ordered after accepting loopback to permit using external IPs via loopback
|
||||
fib daddr . iif type != { local, broadcast, multicast } counter drop
|
||||
|
||||
udp dport 53 notrack accept
|
||||
|
||||
# handle new TCP connections beyond rate limit via synproxy to avoid conntrack table exhaustion
|
||||
tcp dport { 22, 53, 80, 443, 853 } tcp flags syn limit rate over 1024/second burst 128 packets counter notrack accept
|
||||
|
||||
meta l4proto { icmp, ipv6-icmp } notrack accept
|
||||
}
|
||||
|
||||
chain input {
|
||||
type filter hook input priority filter
|
||||
policy drop
|
||||
|
||||
tcp dport { 22, 53, 80, 443, 853 } goto input-tcp-service
|
||||
iif lo accept
|
||||
udp dport 53 accept
|
||||
meta l4proto { icmp, ipv6-icmp } accept
|
||||
ct state vmap { new : goto graceful-reject, established : accept, related : accept }
|
||||
}
|
||||
|
||||
chain input-tcp-service {
|
||||
iif lo goto input-tcp-service-loopback
|
||||
|
||||
# for synproxy, SYN is untracked and first ACK is invalid which are handled via fallthrough
|
||||
ct state vmap { new : goto input-tcp-service-new, established : goto input-tcp-service-established, related : accept }
|
||||
|
||||
tcp dport 22 ip saddr @ip-connlimit-ssh counter reject with tcp reset
|
||||
tcp dport 22 ip6 saddr and ffff:ffff:ffff:ffff:ffff:: @ip6-connlimit-ssh counter reject with tcp reset
|
||||
tcp dport { 53, 80, 443, 853 } ip saddr @ip-connlimit-main counter reject with tcp reset
|
||||
tcp dport { 53, 80, 443, 853 } ip6 saddr and ffff:ffff:ffff:ffff:: @ip6-connlimit-main counter reject with tcp reset
|
||||
synproxy mss 1460 wscale 7 timestamp sack-perm
|
||||
}
|
||||
|
||||
chain input-tcp-service-new {
|
||||
tcp dport 22 ip saddr @ip-connlimit-ssh counter reject with tcp reset
|
||||
tcp dport 22 ip6 saddr and ffff:ffff:ffff:ffff:ffff:: @ip6-connlimit-ssh counter reject with tcp reset
|
||||
tcp dport { 53, 80, 443, 853 } ip saddr @ip-connlimit-main counter reject with tcp reset
|
||||
tcp dport { 53, 80, 443, 853 } ip6 saddr and ffff:ffff:ffff:ffff:: @ip6-connlimit-main counter reject with tcp reset
|
||||
accept
|
||||
}
|
||||
|
||||
# add connections established without synproxy to connection limit sets with limits enforced
|
||||
chain input-tcp-service-established {
|
||||
ct mark 0x1 accept
|
||||
tcp dport 22 ip saddr != $ip-allowlist-ssh add @ip-connlimit-ssh { ip saddr ct count over 1 } counter reject with tcp reset
|
||||
tcp dport 22 ip6 saddr != $ip6-allowlist-ssh add @ip6-connlimit-ssh { ip6 saddr and ffff:ffff:ffff:ffff:ffff:: ct count over 1 } counter reject with tcp reset
|
||||
tcp dport { 53, 80, 443, 853 } add @ip-connlimit-main { ip saddr ct count over 16 } counter reject with tcp reset
|
||||
tcp dport { 53, 80, 443, 853 } add @ip6-connlimit-main { ip6 saddr and ffff:ffff:ffff:ffff:: ct count over 16 } counter reject with tcp reset
|
||||
ct mark set 0x1 accept
|
||||
}
|
||||
|
||||
# add connections established with synproxy to connection limit sets with limits enforced
|
||||
chain input-tcp-service-loopback {
|
||||
tcp flags != syn accept
|
||||
tcp dport 22 ip saddr != $ip-allowlist-ssh add @ip-connlimit-ssh { ip saddr ct count over 1 } counter reject with tcp reset
|
||||
tcp dport 22 ip6 saddr != $ip6-allowlist-ssh add @ip6-connlimit-ssh { ip6 saddr and ffff:ffff:ffff:ffff:ffff:: ct count over 1 } counter reject with tcp reset
|
||||
tcp dport { 53, 80, 443, 853 } add @ip-connlimit-main { ip saddr ct count over 16 } counter reject with tcp reset
|
||||
tcp dport { 53, 80, 443, 853 } add @ip6-connlimit-main { ip6 saddr and ffff:ffff:ffff:ffff:: ct count over 16 } counter reject with tcp reset
|
||||
ct mark set 0x1 accept
|
||||
}
|
||||
|
||||
chain forward {
|
||||
type filter hook forward priority filter
|
||||
policy drop
|
||||
}
|
||||
|
||||
chain output-raw {
|
||||
type filter hook output priority raw
|
||||
|
||||
oif lo notrack accept
|
||||
udp sport 53 notrack accept
|
||||
meta l4proto { icmp, ipv6-icmp } notrack accept
|
||||
}
|
||||
|
||||
chain output {
|
||||
type filter hook output priority filter
|
||||
|
||||
oif lo goto output-loopback
|
||||
skuid != { root, systemd-network, unbound, chrony, http, powerdns, geoipupdate } counter goto graceful-reject
|
||||
}
|
||||
|
||||
chain output-loopback {
|
||||
skuid unbound meta l4proto { tcp, udp } th sport 53 th dport >= 1024 accept
|
||||
skuid { chrony, geoipupdate } meta l4proto { tcp, udp } th sport >= 1024 th dport 53 accept
|
||||
|
||||
skuid powerdns meta l4proto tcp th sport 54 th dport >= 1024 accept
|
||||
skuid http meta l4proto tcp th sport >= 1024 th dport 54 accept
|
||||
|
||||
skuid powerdns meta l4proto tcp th sport 81 th dport >= 1024 accept
|
||||
|
||||
skuid != root counter goto graceful-reject
|
||||
accept
|
||||
}
|
||||
|
||||
chain graceful-reject {
|
||||
meta l4proto udp reject
|
||||
meta l4proto tcp reject with tcp reset
|
||||
reject
|
||||
}
|
||||
}
|
||||
150
nftables/nftables-ns2.conf
Normal file
150
nftables/nftables-ns2.conf
Normal file
|
|
@ -0,0 +1,150 @@
|
|||
#!/usr/bin/nft -f
|
||||
|
||||
flush ruleset
|
||||
|
||||
table inet filter {
|
||||
define ip-allowlist-ssh = {
|
||||
127.0.0.1,
|
||||
198.98.53.141, # 0.ns2.grapheneos.org
|
||||
}
|
||||
|
||||
define ip6-allowlist-ssh = {
|
||||
::1,
|
||||
2605:6400:10:102e:95bc:89ef:2e7f:49bb, # 0.ns2.grapheneos.org
|
||||
}
|
||||
|
||||
set ip-connlimit-ssh {
|
||||
type ipv4_addr
|
||||
flags dynamic
|
||||
}
|
||||
|
||||
set ip6-connlimit-ssh {
|
||||
type ipv6_addr
|
||||
flags dynamic
|
||||
}
|
||||
|
||||
set ip-connlimit-main {
|
||||
type ipv4_addr
|
||||
flags dynamic
|
||||
}
|
||||
|
||||
set ip6-connlimit-main {
|
||||
type ipv6_addr
|
||||
flags dynamic
|
||||
}
|
||||
|
||||
chain prerouting-raw {
|
||||
type filter hook prerouting priority raw
|
||||
|
||||
# drop packets without a reverse path (strict reverse path filtering)
|
||||
fib saddr . iif oif missing counter drop
|
||||
|
||||
iif lo notrack accept
|
||||
|
||||
# drop packets to address not configured on incoming interface (strong host model)
|
||||
#
|
||||
# ordered after accepting loopback to permit using external IPs via loopback
|
||||
fib daddr . iif type != { local, broadcast, multicast } counter drop
|
||||
|
||||
# reject SSH packets via anycast IP
|
||||
tcp dport 22 ip daddr 198.251.90.93 reject with tcp reset
|
||||
|
||||
udp dport 53 notrack accept
|
||||
|
||||
# handle new TCP connections beyond rate limit via synproxy to avoid conntrack table exhaustion
|
||||
tcp dport { 22, 53, 80, 443, 853 } tcp flags syn limit rate over 1024/second burst 128 packets counter notrack accept
|
||||
|
||||
meta l4proto { icmp, ipv6-icmp } notrack accept
|
||||
}
|
||||
|
||||
chain input {
|
||||
type filter hook input priority filter
|
||||
policy drop
|
||||
|
||||
tcp dport { 22, 53, 80, 443, 853 } goto input-tcp-service
|
||||
iif lo accept
|
||||
udp dport 53 accept
|
||||
meta l4proto { icmp, ipv6-icmp } accept
|
||||
ct state vmap { new : goto graceful-reject, established : accept, related : accept }
|
||||
}
|
||||
|
||||
chain input-tcp-service {
|
||||
iif lo goto input-tcp-service-loopback
|
||||
|
||||
# for synproxy, SYN is untracked and first ACK is invalid which are handled via fallthrough
|
||||
ct state vmap { new : goto input-tcp-service-new, established : goto input-tcp-service-established, related : accept }
|
||||
|
||||
tcp dport 22 ip saddr @ip-connlimit-ssh counter reject with tcp reset
|
||||
tcp dport 22 ip6 saddr and ffff:ffff:ffff:ffff:ffff:: @ip6-connlimit-ssh counter reject with tcp reset
|
||||
tcp dport { 53, 80, 443, 853 } ip saddr @ip-connlimit-main counter reject with tcp reset
|
||||
tcp dport { 53, 80, 443, 853 } ip6 saddr and ffff:ffff:ffff:ffff:: @ip6-connlimit-main counter reject with tcp reset
|
||||
synproxy mss 1460 wscale 7 timestamp sack-perm
|
||||
}
|
||||
|
||||
chain input-tcp-service-new {
|
||||
tcp dport 22 ip saddr @ip-connlimit-ssh counter reject with tcp reset
|
||||
tcp dport 22 ip6 saddr and ffff:ffff:ffff:ffff:ffff:: @ip6-connlimit-ssh counter reject with tcp reset
|
||||
tcp dport { 53, 80, 443, 853 } ip saddr @ip-connlimit-main counter reject with tcp reset
|
||||
tcp dport { 53, 80, 443, 853 } ip6 saddr and ffff:ffff:ffff:ffff:: @ip6-connlimit-main counter reject with tcp reset
|
||||
accept
|
||||
}
|
||||
|
||||
# add connections established without synproxy to connection limit sets with limits enforced
|
||||
chain input-tcp-service-established {
|
||||
ct mark 0x1 accept
|
||||
tcp dport 22 ip saddr != $ip-allowlist-ssh add @ip-connlimit-ssh { ip saddr ct count over 1 } counter reject with tcp reset
|
||||
tcp dport 22 ip6 saddr != $ip6-allowlist-ssh add @ip6-connlimit-ssh { ip6 saddr and ffff:ffff:ffff:ffff:ffff:: ct count over 1 } counter reject with tcp reset
|
||||
tcp dport { 53, 80, 443, 853 } add @ip-connlimit-main { ip saddr ct count over 16 } counter reject with tcp reset
|
||||
tcp dport { 53, 80, 443, 853 } add @ip6-connlimit-main { ip6 saddr and ffff:ffff:ffff:ffff:: ct count over 16 } counter reject with tcp reset
|
||||
ct mark set 0x1 accept
|
||||
}
|
||||
|
||||
# add connections established with synproxy to connection limit sets with limits enforced
|
||||
chain input-tcp-service-loopback {
|
||||
tcp flags != syn accept
|
||||
tcp dport 22 ip saddr != $ip-allowlist-ssh add @ip-connlimit-ssh { ip saddr ct count over 1 } counter reject with tcp reset
|
||||
tcp dport 22 ip6 saddr != $ip6-allowlist-ssh add @ip6-connlimit-ssh { ip6 saddr and ffff:ffff:ffff:ffff:ffff:: ct count over 1 } counter reject with tcp reset
|
||||
tcp dport { 53, 80, 443, 853 } add @ip-connlimit-main { ip saddr ct count over 16 } counter reject with tcp reset
|
||||
tcp dport { 53, 80, 443, 853 } add @ip6-connlimit-main { ip6 saddr and ffff:ffff:ffff:ffff:: ct count over 16 } counter reject with tcp reset
|
||||
ct mark set 0x1 accept
|
||||
}
|
||||
|
||||
chain forward {
|
||||
type filter hook forward priority filter
|
||||
policy drop
|
||||
}
|
||||
|
||||
chain output-raw {
|
||||
type filter hook output priority raw
|
||||
|
||||
oif lo notrack accept
|
||||
udp sport 53 notrack accept
|
||||
meta l4proto { icmp, ipv6-icmp } notrack accept
|
||||
}
|
||||
|
||||
chain output {
|
||||
type filter hook output priority filter
|
||||
|
||||
oif lo goto output-loopback
|
||||
skuid != { root, systemd-network, unbound, chrony, http, powerdns, geoipupdate } counter goto graceful-reject
|
||||
}
|
||||
|
||||
chain output-loopback {
|
||||
skuid unbound meta l4proto { tcp, udp } th sport 53 th dport >= 1024 accept
|
||||
skuid { chrony, geoipupdate } meta l4proto { tcp, udp } th sport >= 1024 th dport 53 accept
|
||||
|
||||
skuid powerdns meta l4proto tcp th sport 54 th dport >= 1024 accept
|
||||
skuid http meta l4proto tcp th sport >= 1024 th dport 54 accept
|
||||
|
||||
skuid powerdns meta l4proto tcp th sport 81 th dport >= 1024 accept
|
||||
|
||||
skuid != root counter goto graceful-reject
|
||||
accept
|
||||
}
|
||||
|
||||
chain graceful-reject {
|
||||
meta l4proto udp reject
|
||||
meta l4proto tcp reject with tcp reset
|
||||
reject
|
||||
}
|
||||
}
|
||||
138
nftables/nftables-social.conf
Normal file
138
nftables/nftables-social.conf
Normal file
|
|
@ -0,0 +1,138 @@
|
|||
#!/usr/bin/nft -f
|
||||
|
||||
flush ruleset
|
||||
|
||||
table inet filter {
|
||||
define ip-allowlist-ssh = {
|
||||
127.0.0.1,
|
||||
}
|
||||
|
||||
define ip6-allowlist-ssh = {
|
||||
::1,
|
||||
}
|
||||
|
||||
set ip-connlimit-ssh {
|
||||
type ipv4_addr
|
||||
flags dynamic
|
||||
}
|
||||
|
||||
set ip6-connlimit-ssh {
|
||||
type ipv6_addr
|
||||
flags dynamic
|
||||
}
|
||||
|
||||
set ip-connlimit-main {
|
||||
type ipv4_addr
|
||||
flags dynamic
|
||||
}
|
||||
|
||||
set ip6-connlimit-main {
|
||||
type ipv6_addr
|
||||
flags dynamic
|
||||
}
|
||||
|
||||
chain prerouting-raw {
|
||||
type filter hook prerouting priority raw
|
||||
|
||||
# drop packets without a reverse path (strict reverse path filtering)
|
||||
fib saddr . iif oif missing counter drop
|
||||
|
||||
iif lo notrack accept
|
||||
|
||||
# drop packets to address not configured on incoming interface (strong host model)
|
||||
#
|
||||
# ordered after accepting loopback to permit using external IPs via loopback
|
||||
fib daddr . iif type != { local, broadcast, multicast } counter drop
|
||||
|
||||
# handle new TCP connections beyond rate limit via synproxy to avoid conntrack table exhaustion
|
||||
tcp dport { 22, 80, 443 } tcp flags syn limit rate over 1024/second burst 128 packets counter notrack accept
|
||||
|
||||
meta l4proto { icmp, ipv6-icmp } notrack accept
|
||||
}
|
||||
|
||||
chain input {
|
||||
type filter hook input priority filter
|
||||
policy drop
|
||||
|
||||
tcp dport { 22, 80, 443 } goto input-tcp-service
|
||||
iif lo accept
|
||||
meta l4proto { icmp, ipv6-icmp } accept
|
||||
ct state vmap { new : goto graceful-reject, established : accept, related : accept }
|
||||
}
|
||||
|
||||
chain input-tcp-service {
|
||||
iif lo goto input-tcp-service-loopback
|
||||
|
||||
# for synproxy, SYN is untracked and first ACK is invalid which are handled via fallthrough
|
||||
ct state vmap { new : goto input-tcp-service-new, established : goto input-tcp-service-established, related : accept }
|
||||
|
||||
tcp dport 22 ip saddr @ip-connlimit-ssh counter reject with tcp reset
|
||||
tcp dport 22 ip6 saddr and ffff:ffff:ffff:ffff:ffff:: @ip6-connlimit-ssh counter reject with tcp reset
|
||||
tcp dport { 80, 443 } ip saddr @ip-connlimit-main counter reject with tcp reset
|
||||
tcp dport { 80, 443 } ip6 saddr and ffff:ffff:ffff:ffff:: @ip6-connlimit-main counter reject with tcp reset
|
||||
synproxy mss 1460 wscale 7 timestamp sack-perm
|
||||
}
|
||||
|
||||
chain input-tcp-service-new {
|
||||
tcp dport 22 ip saddr @ip-connlimit-ssh counter reject with tcp reset
|
||||
tcp dport 22 ip6 saddr and ffff:ffff:ffff:ffff:ffff:: @ip6-connlimit-ssh counter reject with tcp reset
|
||||
tcp dport { 80, 443 } ip saddr @ip-connlimit-main counter reject with tcp reset
|
||||
tcp dport { 80, 443 } ip6 saddr and ffff:ffff:ffff:ffff:: @ip6-connlimit-main counter reject with tcp reset
|
||||
accept
|
||||
}
|
||||
|
||||
# add connections established without synproxy to connection limit sets with limits enforced
|
||||
chain input-tcp-service-established {
|
||||
ct mark 0x1 accept
|
||||
tcp dport 22 ip saddr != $ip-allowlist-ssh add @ip-connlimit-ssh { ip saddr ct count over 1 } counter reject with tcp reset
|
||||
tcp dport 22 ip6 saddr != $ip6-allowlist-ssh add @ip6-connlimit-ssh { ip6 saddr and ffff:ffff:ffff:ffff:ffff:: ct count over 1 } counter reject with tcp reset
|
||||
tcp dport { 80, 443 } add @ip-connlimit-main { ip saddr ct count over 32 } counter reject with tcp reset
|
||||
tcp dport { 80, 443 } add @ip6-connlimit-main { ip6 saddr and ffff:ffff:ffff:ffff:: ct count over 32 } counter reject with tcp reset
|
||||
ct mark set 0x1 accept
|
||||
}
|
||||
|
||||
# add connections established with synproxy to connection limit sets with limits enforced
|
||||
chain input-tcp-service-loopback {
|
||||
tcp flags != syn accept
|
||||
tcp dport 22 ip saddr != $ip-allowlist-ssh add @ip-connlimit-ssh { ip saddr ct count over 1 } counter reject with tcp reset
|
||||
tcp dport 22 ip6 saddr != $ip6-allowlist-ssh add @ip6-connlimit-ssh { ip6 saddr and ffff:ffff:ffff:ffff:ffff:: ct count over 1 } counter reject with tcp reset
|
||||
tcp dport { 80, 443 } add @ip-connlimit-main { ip saddr ct count over 32 } counter reject with tcp reset
|
||||
tcp dport { 80, 443 } add @ip6-connlimit-main { ip6 saddr and ffff:ffff:ffff:ffff:: ct count over 32 } counter reject with tcp reset
|
||||
ct mark set 0x1 accept
|
||||
}
|
||||
|
||||
chain forward {
|
||||
type filter hook forward priority filter
|
||||
policy drop
|
||||
}
|
||||
|
||||
chain output-raw {
|
||||
type filter hook output priority raw
|
||||
|
||||
oif lo notrack accept
|
||||
meta l4proto { icmp, ipv6-icmp } notrack accept
|
||||
}
|
||||
|
||||
chain output {
|
||||
type filter hook output priority filter
|
||||
|
||||
oif lo goto output-loopback
|
||||
skuid != { root, systemd-network, unbound, chrony, http, mastodon } counter goto graceful-reject
|
||||
}
|
||||
|
||||
chain output-loopback {
|
||||
skuid unbound meta l4proto { tcp, udp } th sport 53 th dport >= 1024 accept
|
||||
skuid { chrony, mastodon } meta l4proto { tcp, udp } th sport >= 1024 th dport 53 accept
|
||||
|
||||
skuid postgres udp sport >= 1024 udp dport >= 1024 accept
|
||||
|
||||
skuid != root counter goto graceful-reject
|
||||
accept
|
||||
}
|
||||
|
||||
chain graceful-reject {
|
||||
meta l4proto udp reject
|
||||
meta l4proto tcp reject with tcp reset
|
||||
reject
|
||||
}
|
||||
}
|
||||
140
nftables/nftables-web.conf
Normal file
140
nftables/nftables-web.conf
Normal file
|
|
@ -0,0 +1,140 @@
|
|||
#!/usr/bin/nft -f
|
||||
|
||||
flush ruleset
|
||||
|
||||
table inet filter {
|
||||
define ip-allowlist-ssh = {
|
||||
127.0.0.1,
|
||||
51.222.156.101, # 0.grapheneos.org
|
||||
167.114.114.114, # 0.releases.grapheneos.org
|
||||
}
|
||||
|
||||
define ip6-allowlist-ssh = {
|
||||
::1,
|
||||
2607:5300:205:200::29c6, # 0.grapheneos.org
|
||||
2607:5300:201:3100::6210, # 0.releases.grapheneos.org
|
||||
}
|
||||
|
||||
set ip-connlimit-ssh {
|
||||
type ipv4_addr
|
||||
flags dynamic
|
||||
}
|
||||
|
||||
set ip6-connlimit-ssh {
|
||||
type ipv6_addr
|
||||
flags dynamic
|
||||
}
|
||||
|
||||
set ip-connlimit-main {
|
||||
type ipv4_addr
|
||||
flags dynamic
|
||||
}
|
||||
|
||||
set ip6-connlimit-main {
|
||||
type ipv6_addr
|
||||
flags dynamic
|
||||
}
|
||||
|
||||
chain prerouting-raw {
|
||||
type filter hook prerouting priority raw
|
||||
|
||||
# drop packets without a reverse path (strict reverse path filtering)
|
||||
fib saddr . iif oif missing counter drop
|
||||
|
||||
iif lo notrack accept
|
||||
|
||||
# drop packets to address not configured on incoming interface (strong host model)
|
||||
#
|
||||
# ordered after accepting loopback to permit using external IPs via loopback
|
||||
fib daddr . iif type != { local, broadcast, multicast } counter drop
|
||||
|
||||
# handle new TCP connections beyond rate limit via synproxy to avoid conntrack table exhaustion
|
||||
tcp dport { 22, 80, 443 } tcp flags syn limit rate over 1024/second burst 128 packets counter notrack accept
|
||||
|
||||
meta l4proto { icmp, ipv6-icmp } notrack accept
|
||||
}
|
||||
|
||||
chain input {
|
||||
type filter hook input priority filter
|
||||
policy drop
|
||||
|
||||
tcp dport { 22, 80, 443 } goto input-tcp-service
|
||||
iif lo accept
|
||||
meta l4proto { icmp, ipv6-icmp } accept
|
||||
ct state vmap { new : goto graceful-reject, established : accept, related : accept }
|
||||
}
|
||||
|
||||
chain input-tcp-service {
|
||||
iif lo goto input-tcp-service-loopback
|
||||
|
||||
# for synproxy, SYN is untracked and first ACK is invalid which are handled via fallthrough
|
||||
ct state vmap { new : goto input-tcp-service-new, established : goto input-tcp-service-established, related : accept }
|
||||
|
||||
tcp dport 22 ip saddr @ip-connlimit-ssh counter reject with tcp reset
|
||||
tcp dport 22 ip6 saddr and ffff:ffff:ffff:ffff:ffff:: @ip6-connlimit-ssh counter reject with tcp reset
|
||||
tcp dport { 80, 443 } ip saddr @ip-connlimit-main counter reject with tcp reset
|
||||
tcp dport { 80, 443 } ip6 saddr and ffff:ffff:ffff:ffff:: @ip6-connlimit-main counter reject with tcp reset
|
||||
synproxy mss 1460 wscale 7 timestamp sack-perm
|
||||
}
|
||||
|
||||
chain input-tcp-service-new {
|
||||
tcp dport 22 ip saddr @ip-connlimit-ssh counter reject with tcp reset
|
||||
tcp dport 22 ip6 saddr and ffff:ffff:ffff:ffff:ffff:: @ip6-connlimit-ssh counter reject with tcp reset
|
||||
tcp dport { 80, 443 } ip saddr @ip-connlimit-main counter reject with tcp reset
|
||||
tcp dport { 80, 443 } ip6 saddr and ffff:ffff:ffff:ffff:: @ip6-connlimit-main counter reject with tcp reset
|
||||
accept
|
||||
}
|
||||
|
||||
# add connections established without synproxy to connection limit sets with limits enforced
|
||||
chain input-tcp-service-established {
|
||||
ct mark 0x1 accept
|
||||
tcp dport 22 ip saddr != $ip-allowlist-ssh add @ip-connlimit-ssh { ip saddr ct count over 1 } counter reject with tcp reset
|
||||
tcp dport 22 ip6 saddr != $ip6-allowlist-ssh add @ip6-connlimit-ssh { ip6 saddr and ffff:ffff:ffff:ffff:ffff:: ct count over 1 } counter reject with tcp reset
|
||||
tcp dport { 80, 443 } add @ip-connlimit-main { ip saddr ct count over 32 } counter reject with tcp reset
|
||||
tcp dport { 80, 443 } add @ip6-connlimit-main { ip6 saddr and ffff:ffff:ffff:ffff:: ct count over 32 } counter reject with tcp reset
|
||||
ct mark set 0x1 accept
|
||||
}
|
||||
|
||||
# add connections established with synproxy to connection limit sets with limits enforced
|
||||
chain input-tcp-service-loopback {
|
||||
tcp flags != syn accept
|
||||
tcp dport 22 ip saddr != $ip-allowlist-ssh add @ip-connlimit-ssh { ip saddr ct count over 1 } counter reject with tcp reset
|
||||
tcp dport 22 ip6 saddr != $ip6-allowlist-ssh add @ip6-connlimit-ssh { ip6 saddr and ffff:ffff:ffff:ffff:ffff:: ct count over 1 } counter reject with tcp reset
|
||||
tcp dport { 80, 443 } add @ip-connlimit-main { ip saddr ct count over 32 } counter reject with tcp reset
|
||||
tcp dport { 80, 443 } add @ip6-connlimit-main { ip6 saddr and ffff:ffff:ffff:ffff:: ct count over 32 } counter reject with tcp reset
|
||||
ct mark set 0x1 accept
|
||||
}
|
||||
|
||||
chain forward {
|
||||
type filter hook forward priority filter
|
||||
policy drop
|
||||
}
|
||||
|
||||
chain output-raw {
|
||||
type filter hook output priority raw
|
||||
|
||||
oif lo notrack accept
|
||||
meta l4proto { icmp, ipv6-icmp } notrack accept
|
||||
}
|
||||
|
||||
chain output {
|
||||
type filter hook output priority filter
|
||||
|
||||
oif lo goto output-loopback
|
||||
skuid != { root, systemd-network, unbound, chrony, http } counter goto graceful-reject
|
||||
}
|
||||
|
||||
chain output-loopback {
|
||||
skuid unbound meta l4proto { tcp, udp } th sport 53 th dport >= 1024 accept
|
||||
skuid chrony meta l4proto { tcp, udp } th sport >= 1024 th dport 53 accept
|
||||
|
||||
skuid != root counter goto graceful-reject
|
||||
accept
|
||||
}
|
||||
|
||||
chain graceful-reject {
|
||||
meta l4proto udp reject
|
||||
meta l4proto tcp reject with tcp reset
|
||||
reject
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue