Skip to content

Commit 363588f

Browse files
author
Federico Ceratto
committed
Setup nftables
1 parent e742b45 commit 363588f

File tree

4 files changed

+86
-0
lines changed

4 files changed

+86
-0
lines changed

ansible/roles/nftables/README.adoc

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
Install nftables based firewall
2+
3+
Set up /etc/ooni/nftables/
4+
5+
Rules for specific services are *not* configured by this role
6+
7+
When creating rules to accept TCP traffic from any IPv4/6 address,
8+
files are named with the port number to detect collisions.
9+
10+
Example:
11+
12+
/etc/ooni/nftables/tcp/8080.nft
13+
14+
```
15+
add rule inet filter input tcp dport 8080 counter accept comment "MyService"
16+
```
17+
18+
19+
Otherwise:
20+
21+
/etc/ooni/nftables/tcp/5432_postgres_internal.nft
22+
23+
```
24+
add rule inet filter input ip saddr { 10.0.0.0/8, 192.168.0.0/16 } tcp dport 5432 counter accept comment "Internal PostgreSQL"
25+
```

ansible/roles/nftables/tasks/main.yml

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
---
2+
- name: Install nftables
3+
apt:
4+
cache_valid_time: 86400
5+
name: nftables
6+
7+
- name: create config dir
8+
file:
9+
path: /etc/ooni/nftables/tcp
10+
state: directory
11+
owner: root
12+
group: root
13+
mode: 0755
14+
15+
- name: allow SSH
16+
blockinfile:
17+
path: /etc/ooni/nftables/tcp/22.nft
18+
block: |
19+
add rule inet filter input tcp dport 22 counter accept comment "Incoming SSH"
20+
21+
- name: Enable and start nftables service
22+
systemd:
23+
name: nftables.service
24+
state: started
25+
enabled: yes
26+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#!/usr/sbin/nft -f
2+
#
3+
# Nftables configuration script
4+
#
5+
# Managed by ansible
6+
# roles/nftables/templates/nftables.conf
7+
#
8+
# The ruleset is applied atomically
9+
10+
flush ruleset
11+
12+
table inet filter {
13+
chain input {
14+
type filter hook input priority filter; policy drop;
15+
iif lo accept comment "Accept incoming traffic from localhost"
16+
ct state invalid drop
17+
ct state established,related accept comment "Accept traffic related to outgoing connections"
18+
}
19+
20+
chain forward {
21+
type filter hook forward priority filter; policy accept;
22+
}
23+
24+
chain output {
25+
type filter hook output priority filter; policy accept;
26+
}
27+
}
28+
29+
# Configure TCP traffic rules
30+
include "/etc/ooni/nftables/tcp/*.nft"
31+
32+
# Configure any other rule
33+
include "/etc/ooni/nftables/*.nft"
34+
+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
---
22
dependencies:
33
- role: base-buster
4+
- role: nftables

0 commit comments

Comments
 (0)