Add nftables configuration for K3s on Arch Linux#511
Add nftables configuration for K3s on Arch Linux#511cioionut wants to merge 5 commits intok3s-io:mainfrom
Conversation
9730b5a to
b9203c5
Compare
By default on most OSes, the nftables start with no configuration and should not be blocking on any ports. Is this a specific issue to the cloud image? Has ArchLinux started shipping with "default restrictive rules"? |
|
This is what I encountered last week when I tried to upgrade my k3s cluster. Then I tried a fresh setup using the install playbook on the latest archlinux cloud image and have the same restrictions. |
|
Hello! I discovered the code responsible for the current issue. Look at lines 35-64, here the nftables is enabled, and this creates a Here is the proof, I ran the commands manually to test this behaviour that's done in the prereq role. [archuser@w0 ~]$ cat /etc/nftables.conf
cat: /etc/nftables.conf: No such file or directory
[archuser@w0 ~]$ sudo pacman -S iptables-nft nftables
resolving dependencies...
looking for conflicting packages...
:: iptables-nft-1:1.8.11-2 and iptables-1:1.8.11-2 are in conflict. Remove iptables? [y/N] y
Packages (3) iptables-1:1.8.11-2 [removal] iptables-nft-1:1.8.11-2 nftables-1:1.1.6-2
Total Download Size: 0.83 MiB
Total Installed Size: 3.46 MiB
Net Upgrade Size: 1.10 MiB
:: Proceed with installation? [Y/n]
:: Retrieving packages...
nftables-1:1.1.6-2-x86_64 433.9 KiB 1955 KiB/s 00:00 [########################################################] 100%
iptables-nft-1:1.8.11-2-x86_64 417.7 KiB 1536 KiB/s 00:00 [########################################################] 100%
Total (2/2) 851.7 KiB 2.65 MiB/s 00:00 [########################################################] 100%
(2/2) checking keys in keyring [########################################################] 100%
(2/2) checking package integrity [########################################################] 100%
(2/2) loading package files [########################################################] 100%
(2/2) checking for file conflicts [########################################################] 100%
(3/3) checking available disk space [########################################################] 100%
:: Processing package changes...
(1/1) removing iptables [########################################################] 100%
(1/2) installing nftables [########################################################] 100%
Optional dependencies for nftables
python: Python bindings [installed]
python-jsonschema: Python bindings [installed]
(2/2) installing iptables-nft [########################################################] 100%
:: Running post-transaction hooks...
(1/3) Reloading system manager configuration...
(2/3) Restarting marked services...
(3/3) Arming ConditionNeedsUpdate...
[archuser@w0 ~]$ sudo systemctl start nftables
[archuser@w0 ~]$ cat /etc/nftables.conf
#!/usr/bin/nft -f
# vim:set ts=2 sw=2 et:
# IPv4/IPv6 Simple & Safe firewall ruleset.
# More examples in /usr/share/nftables/ and /usr/share/doc/nftables/examples/.
destroy table inet filter
table inet filter {
chain input {
type filter hook input priority filter
policy drop
ct state invalid drop comment "early drop of invalid connections"
ct state {established, related} accept comment "allow tracked connections"
iif lo accept comment "allow from loopback"
ip protocol icmp accept comment "allow icmp"
meta l4proto ipv6-icmp accept comment "allow icmp v6"
tcp dport ssh accept comment "allow sshd"
pkttype host limit rate 5/second counter reject with icmpx type admin-prohibited
counter
}
chain forward {
type filter hook forward priority filter
policy drop
}
}
[archuser@w0 ~]$ uname -r
6.18.7-arch1-1 |
22c379a to
613506a
Compare
|
This was added recently with #486. As a much simpler fix, is it possible to just Also there is also the |
|
I tested with the |
|
So two things are happening:
So there are two parts to your PR that I would ask for changes.
|
|
Hello, nftables is only required for podman/docker with kernel >=6.18. I have a combination of k3s and podman containers in my homelab so I blindly enabled it in the PR, sorry for the regression. The current nftables.conf of this PR will remove any existing rule that could have been configured outside k3s install. Instead of overwriting the default nftables.conf (that will be overwritten with any nftables package update), we should have a file for k3s created in the folder loaded by nftables.conf instead: /etc/nftables.d/ We just need to ensure that the following instruction is in nftables.conf: include "/etc/nftables.d/*.nft" We shouldn't have a flush ruleset in the custom k3s conf, this should only be done in nftables.conf before any custom rule is loaded. |
|
Hi @gillouche ! Good catch! |
3d33262 to
7c148b4
Compare
7c148b4 to
e9e0978
Compare
75b243f to
44286b6
Compare
Signed-off-by: Ionut <ionutnciocoiu@gmail.com>
44286b6 to
8b2a583
Compare
roles/prereq/handlers/main.yml
Outdated
| @@ -0,0 +1,5 @@ | |||
| --- | |||
| - name: Reload nftables | |||
There was a problem hiding this comment.
No need to make this a dedicated handler, its already conditionally controlled via the Block.
Also, don't use systemd we are using the more generic service module for expanded init support unless absolutely required.
Co-authored-by: Derek Nola <derek.nola@suse.com> Signed-off-by: Ionut Ciocoiu <ionutnciocoiu@gmail.com>
Signed-off-by: Ionut <ionutnciocoiu@gmail.com>
Signed-off-by: Ionut <ionutnciocoiu@gmail.com>
|
@cioionut Just need to fix the lint errors:
|
Signed-off-by: Ionut <ionutnciocoiu@gmail.com>
When using Arch Linux with kernel 6.18+, k3s-ansible enables nftables but uses the default restrictive ruleset, which blocks K3s traffic.
This commit adds:
The template allows:
Linked Issues
After running the install playbook or upgrade using the latest ArchLinux cloud image, the connection to the k3s api server (port 6443) is blocked by the nftables firewall. So, for the new install/upgrades will be impossible to manage the cluster via kubectl, k9s, etc without a ssh tunnel (ssh 22 is not blocked by the firewall)