Podman & nftables
-
Ich habe ja hier berichtet, wie man einen Forgejo Server aufsetzen kann.
Forgejo Installation mit Podman Quadlet auf Hetzner VM
Meinen ersten Versuch findet man hier. Mittlerweile habe ich das Setup verfeinert und bin zufrieden. Das wollte ich hier teilen. Der Plan ist es einen Forgej...
linux-nerds.org (linux-nerds.org)
Da ich da sehr lange dran rum gewerkelt habe, habe ich am Anfang mal die Firewall in der Hetzner Cloud Software aktiviert mit den Standard Ports, die man so braucht.
- 22
- 80
- 443
Eine Kontrolle mit nmap ergibt dann auch nur folgende Ports.
PORT STATE SERVICE 22/tcp open ssh 80/tcp open http 443/tcp open https
Ich hatte am Anfang ziemlich viele Probleme mit meinen Podman Containern, bis ich gelernt hatte, das mit nftables sich vieles von alleine erledigt. Warum? Es gibt auf einer Debian Trixie Installation folgendes Paket.
root@forgejo:/etc/containers/systemd# apt search netavark aardvark-dns/testing 1.14.0-3 amd64 Container-focused DNS server netavark/testing,now 1.14.0-2 amd64 [installed,automatic] Rust based network stack for containers podman/testing,now 5.4.2+ds1-1+b3 amd64 [installed] tool to manage containers and pods podman-docker/testing 5.4.2+ds1-1+b3 amd64 tool to manage containers and pods (Docker CLI) podman-remote/testing 5.4.2+ds1-1+b3 amd64 tool to manage containers and pods (remote CLI)
Ich spreche von netavark. Dieses Paket ist auf Debian Trixie 13 eine Abhängigkeit von Podman, wird also mitinstalliert.
Netavark is a rust based network stack for containers. It is being designed to work with Podman but is also applicable for other OCI container management applications.
Und dieses Tool trägt dann in Zusammenhang alle Regeln die man braucht, in nftables ein. Vollautomatisch!
Ein Beispiel ist DNAT
chain NETAVARK-HOSTPORT-DNAT { tcp dport 80 jump nv_1126fa6c_10_89_0_0_nm16_dnat tcp dport 222 jump nv_1126fa6c_10_89_0_0_nm16_dnat tcp dport 443 jump nv_1126fa6c_10_89_0_0_nm16_dnat tcp dport 3000 jump nv_1126fa6c_10_89_0_0_nm16_dnat }
Nachdem ich das alles wusste, war es auch relativ simpel, die Container dazu bewegen sinnvolles zu machen
Für die Installation von nftables macht man wie gewohnt
apt install nftables
systemd Kontrolle
systemd enable nftables # Erst einschalten, wenn ihr wisst das ihr noch auf die Kiste kommt! systemctl start nftables systemctl status nftables
Wann man was standardmäßig in die Konfiguration eintragen möchte, geht das mit
nano /etc/nftables.conf
Konfiguration testen
nft -f /etc/nftables.conf
Die Liste, der Regeln, kann man sich so anschauen
nft list ruleset
Ausgabe (gekürzt)
table inet filter { chain input { type filter hook input priority filter; policy accept; } chain forward { type filter hook forward priority filter; policy accept; } chain output { type filter hook output priority filter; policy accept; } } table inet netavark { chain INPUT { type filter hook input priority filter; policy accept; ip saddr 10.92.0.0/16 meta l4proto { tcp, udp } th dport 53 accept }
Das schöne ist, das man nun auch fail2ban dazu bewegen kann seine Bans vollautomatisch in diese Liste einzutragen, dazu gibt es einen eigene Beitrag.
table inet f2b-table { set addr-set-sshd { type ipv4_addr elements = { 13.67.94.200, 14.22.88.255, 14.103.119.118, 14.103.123.75, 14.103.236.35, 36.133.184.250, 36.134.2.209, 41.58.186.132, 46.101.8.63, 64.226.119.233, 64.227.110.144, 94.182.227.191, 101.126.135.80, 103.56.114.54, 117.149.247.143, 119.45.128.125, 125.124.106.113, 125.164.14.241, 128.199.33.46, 142.93.204.139, 157.245.71.30, 157.245.144.151, 161.132.43.198, 180.76.105.165, 185.93.89.118, 185.213.165.36, 193.32.162.146, 193.168.173.177, 199.188.103.179, 202.179.66.26, 220.80.197.180 } }
Man, da sind aber schon wieder viele Script Kiddies unterwegs