Compare commits
2 commits
217b44c3fa
...
e3c12b18e8
Author | SHA1 | Date | |
---|---|---|---|
e3c12b18e8 |
|||
c8fa55fafd |
10 changed files with 121 additions and 2 deletions
|
@ -1 +1,2 @@
|
||||||
systemd_networkd__config_dir: 'resources/chaosknoten/router/systemd_networkd/'
|
systemd_networkd__config_dir: 'resources/chaosknoten/router/systemd_networkd/'
|
||||||
|
nftables__config: "{{ lookup('ansible.builtin.file', 'resources/chaosknoten/router/nftables/nftables.conf') }}"
|
||||||
|
|
|
@ -91,6 +91,9 @@ base_config_hosts:
|
||||||
systemd_networkd_hosts:
|
systemd_networkd_hosts:
|
||||||
hosts:
|
hosts:
|
||||||
router:
|
router:
|
||||||
|
nftables_hosts:
|
||||||
|
hosts:
|
||||||
|
router:
|
||||||
docker_compose_hosts:
|
docker_compose_hosts:
|
||||||
hosts:
|
hosts:
|
||||||
ccchoir:
|
ccchoir:
|
||||||
|
|
|
@ -9,6 +9,11 @@
|
||||||
roles:
|
roles:
|
||||||
- systemd_networkd
|
- systemd_networkd
|
||||||
|
|
||||||
|
- name: Ensure nftables deployment on nftables_hosts
|
||||||
|
hosts: nftables_hosts
|
||||||
|
roles:
|
||||||
|
- nftables
|
||||||
|
|
||||||
- name: Ensure deployment of infrastructure authorized keys
|
- name: Ensure deployment of infrastructure authorized keys
|
||||||
hosts: infrastructure_authorized_keys_hosts
|
hosts: infrastructure_authorized_keys_hosts
|
||||||
roles:
|
roles:
|
||||||
|
|
73
resources/chaosknoten/router/nftables/nftables.conf
Normal file
73
resources/chaosknoten/router/nftables/nftables.conf
Normal file
|
@ -0,0 +1,73 @@
|
||||||
|
#!/usr/sbin/nft -f
|
||||||
|
|
||||||
|
## Variables
|
||||||
|
|
||||||
|
# Interfaces
|
||||||
|
define if_net1_v4_wan = "net1"
|
||||||
|
define if_net2_v6_wan = "net2"
|
||||||
|
define if_net0_2_v4_nat = "net0.2"
|
||||||
|
define if_net0_3_ci_runner = "net0.3"
|
||||||
|
|
||||||
|
# Interface Groups
|
||||||
|
define wan_ifs = { $if_net1_v4_wan,
|
||||||
|
$if_net2_v6_wan }
|
||||||
|
define lan_ifs = { $if_net0_2_v4_nat,
|
||||||
|
$if_net0_3_ci_runner }
|
||||||
|
|
||||||
|
|
||||||
|
## Rules
|
||||||
|
|
||||||
|
table inet reverse-path-forwarding {
|
||||||
|
chain rpf-filter {
|
||||||
|
type filter hook prerouting priority mangle + 10; policy drop;
|
||||||
|
|
||||||
|
# Only allow packets if their source address is routed via their incoming interface.
|
||||||
|
# https://github.com/NixOS/nixpkgs/blob/d9d87c51960050e89c79e4025082ed965e770d68/nixos/modules/services/networking/firewall-nftables.nix#L100
|
||||||
|
fib saddr . mark . iif oif exists accept
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
table inet host {
|
||||||
|
chain input {
|
||||||
|
type filter hook input priority filter; policy drop;
|
||||||
|
|
||||||
|
iifname "lo" accept comment "allow loopback"
|
||||||
|
|
||||||
|
ct state invalid drop
|
||||||
|
ct state established,related accept
|
||||||
|
|
||||||
|
ip protocol icmp accept
|
||||||
|
ip6 nexthdr icmpv6 accept
|
||||||
|
|
||||||
|
# Allow SSH access.
|
||||||
|
tcp dport 22 accept comment "allow ssh access"
|
||||||
|
|
||||||
|
# Allow DHCP server access.
|
||||||
|
iifname $if_net0_3_ci_runner udp dport 67 accept comment "allow dhcp server access"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
table ip v4nat {
|
||||||
|
chain prerouting {
|
||||||
|
type nat hook prerouting priority dstnat; policy accept;
|
||||||
|
}
|
||||||
|
|
||||||
|
chain postrouting {
|
||||||
|
type nat hook postrouting priority srcnat; policy accept;
|
||||||
|
|
||||||
|
oifname $if_net1_v4_wan masquerade
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
table inet forward {
|
||||||
|
chain forward {
|
||||||
|
type filter hook forward priority filter; policy drop;
|
||||||
|
|
||||||
|
ct state invalid drop
|
||||||
|
ct state established,related accept
|
||||||
|
|
||||||
|
# Allow internet access.
|
||||||
|
meta nfproto ipv6 iifname $lan_ifs oifname $if_net2_v6_wan accept comment "allow v6 internet access"
|
||||||
|
meta nfproto ipv4 iifname $lan_ifs oifname $if_net1_v4_wan accept comment "allow v4 internet access"
|
||||||
|
}
|
||||||
|
}
|
|
@ -8,7 +8,7 @@ RequiredForOnline=no
|
||||||
[Network]
|
[Network]
|
||||||
Description=v4-NAT
|
Description=v4-NAT
|
||||||
|
|
||||||
IPMasquerade=ipv4
|
# Masquerading done in nftables (nftables.conf).
|
||||||
IPv6SendRA=yes
|
IPv6SendRA=yes
|
||||||
|
|
||||||
[Address]
|
[Address]
|
||||||
|
|
|
@ -8,7 +8,7 @@ RequiredForOnline=no
|
||||||
[Network]
|
[Network]
|
||||||
Description=ci-runners
|
Description=ci-runners
|
||||||
|
|
||||||
IPMasquerade=ipv4
|
# Masquerading done in nftables (nftables.conf).
|
||||||
IPv6SendRA=yes
|
IPv6SendRA=yes
|
||||||
|
|
||||||
DHCPServer=true
|
DHCPServer=true
|
||||||
|
|
11
roles/nftables/README.md
Normal file
11
roles/nftables/README.md
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
# Role `nftables`
|
||||||
|
|
||||||
|
Deploys nftables.
|
||||||
|
|
||||||
|
## Support Distributions
|
||||||
|
|
||||||
|
Should work on Debian-based distributions.
|
||||||
|
|
||||||
|
## Required Arguments
|
||||||
|
|
||||||
|
- `nftables__config`: nftables configuration to deploy.
|
5
roles/nftables/handlers/main.yaml
Normal file
5
roles/nftables/handlers/main.yaml
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
- name: Restart nftables service
|
||||||
|
ansible.builtin.systemd_service:
|
||||||
|
name: nftables
|
||||||
|
state: restarted
|
||||||
|
become: true
|
6
roles/nftables/meta/argument_specs.yaml
Normal file
6
roles/nftables/meta/argument_specs.yaml
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
argument_specs:
|
||||||
|
main:
|
||||||
|
options:
|
||||||
|
nftables__config:
|
||||||
|
type: str
|
||||||
|
required: true
|
15
roles/nftables/tasks/main.yaml
Normal file
15
roles/nftables/tasks/main.yaml
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
- name: ensure nftables is installed
|
||||||
|
ansible.builtin.apt:
|
||||||
|
name: nftables
|
||||||
|
state: present
|
||||||
|
become: true
|
||||||
|
|
||||||
|
- name: deploy nftables configuration
|
||||||
|
ansible.builtin.copy:
|
||||||
|
content: "{{ nftables__config }}"
|
||||||
|
dest: "/etc/nftables.conf"
|
||||||
|
mode: "0644"
|
||||||
|
owner: root
|
||||||
|
group: root
|
||||||
|
become: true
|
||||||
|
notify: Restart nftables service
|
Loading…
Add table
Add a link
Reference in a new issue