-
Notifications
You must be signed in to change notification settings - Fork 802
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
WIP: firewall: add nftables backend #462
Conversation
f2cecbe
to
7a04e16
Compare
@mars1024 , could you please take a look at this PR? 🙏 It is almost ready (pending adding tests), but I did update |
Of course, and you should add some tests later. |
BTW, cc firewall plugin author @dcbw |
e7653d0
to
fc12e49
Compare
@mars1024 , I tried |
756e3fd
to
e30bde3
Compare
|
We need more tests @greenpau |
@mars1024, after thinking about it a bit, it may require its own chain .. for consistency. What would the logic behind naming the individual chains? For example, I see IP masquarade chaing names in the following fashion. I guess, what is the logic behind
|
@mars1024 , running into an issue implementing it as a chain. how many chain would you create for the below rules?
Do you create a chain for interface? e.g. I am still think it could be proper to do it with a subnet match. |
Back on this PR. |
e0dd778
to
1e5820c
Compare
Pivoting from invoking Found decent blog posts on the subject: |
64af31c
to
88bb21e
Compare
@erig0 can you review this one too? thanks! |
@mars1024 , @dcbw , @erig0, it might actually not work due to the fact the |
@greenpau we can certainly bump the required Go version of the CNI plugins repo. Our general policy is Go versions N and N-1, which means we should support Go 1.13 and Go 1.14. If it's possible to support 1.12 that's great, but not required. Anything 1.11 and lower is not supported. pushed as a PR in #521 |
@dcbw , that would be great! |
@greenpau, Another option is to use libnftables. This what |
``` | ||
|
||
Prior to the invocation of CNI `firewall` plugin, the `FORWARD` chain in `filter` | ||
table might be configured be as follows: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not guaranteed to exist. It will likely exist on any machine that uses the iptables-nft
variant of iptables as it implicitly create this table/chain. I would not assume the table/chain exists.
CNI could use its own table and set of chains and thus avoid many interaction issues with iptables-nft
. However, a separate table and chains has its own issue related to netfilter hooks. The tl;dr is nftables allows multiple chains to use the same netfilter hook. A consequence of this is that packets that are accepted are still subject to the rules of other chains hooked into the hook type.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
chain cnins-3-4026550857-dummy0 { | ||
oifname "dummy0" ip daddr 192.168.100.100 ct state established,related counter packets 0 bytes 0 accept | ||
iifname "dummy0" ip saddr 192.168.100.100 counter packets 0 bytes 0 accept | ||
iifname "dummy0" oifname "dummy0" counter packets 0 bytes 0 accept | ||
} | ||
} | ||
table ip6 filter { | ||
chain FORWARD { | ||
type filter hook forward priority filter; policy drop; | ||
jump cnins-3-4026550857-dummy0 | ||
} | ||
|
||
chain cnins-3-4026550857-dummy0 { | ||
oifname "dummy0" ip6 daddr 2001:db8:100:100::1 ct state established,related counter packets 0 bytes 0 accept | ||
iifname "dummy0" ip6 saddr 2001:db8:100:100::1 counter packets 0 bytes 0 accept | ||
iifname "dummy0" oifname "dummy0" counter packets 0 bytes 0 accept | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ideally these would be combined into one chain in a table of family inet
. I don't think there is value in splitting them up. It can probably avoid some duplicate rules.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think there is value in splitting them up. It can probably avoid some duplicate rules.
@erig0, it has a value in a sense that it is easier to delete the rule when you have a jump like this. It would be very hard to parse each rule.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I get the jump to a dedicated chain. That 100% makes sense. I was saying I don't think you need to split the "ip" and "ip6" families. You could use "inet" which covers both IPv4 and IPv6.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I get the jump to a dedicated chain. That 100% makes sense. I was saying I don't think you need to split the "ip" and "ip6" families. You could use "inet" which covers both IPv4 and IPv6.
@erig0, that I could do. 👍 It makes sense because IPv4/6 are all a part of the same construct.
From failed tests:
Now most of the tests pass. Noticed the issue with |
just noticed an issue with |
another issue is with the interface name ... I take the interface name of the container. It should be the interface name of the bridge ... the very first interface of in the list. |
Added working version of nftables plugin in https://github.com/greenpau/cni-plugins#cni-nftables-firewall. Still testing it. |
Why firewall configuration is needed when Podman runs inside a VM container, like WSL2 ? A firewall is always supplied by the Host node. The communication between the Podman network and interface Eth0 provided dynamically by the Virtual switch doesn't need any filtering. In the overlay network, the entire local network can be protected by the router if it runs OpenWRT or Free Balena. |
In this context the firewall plugin is how networking is set up for the containers. This is separate to what you refer to as the "overlay network". You can read up on the CNI firewall plugin here: https://github.com/containernetworking/plugins/blob/master/plugins/meta/firewall/README.md You can already use podman with iptables in WSL2 without this PR, as long as your linux distro still uses iptables. If I got anything wrong here let me know |
Note that this won't always be the first interface... we've struggled with this for other plugins (eg bandwidth) too, and don't have a great answer yet because some plugins might not have a host-side network interface, like VMs that use tap. But in any case, take a look at what the bandwidth plugin does; I think it takes the first non-sandbox interface in the list. If you just look for the first interface, it may be the container interface, so you have to look at the "Sandbox" key. |
@dcbw , I reworked the plugin completely ... please see https://github.com/greenpau/cni-plugins/tree/main/pkg/firewall I was thinking of linking from here to https://github.com/greenpau/cni-plugins/blob/6b7a838e15f159e8695df59b4f4f722ca3f49118/pkg/firewall/cmd.go#L12. Any objections? Also, on a separate note, I found out that |
Has there been any movement on this front? Nftables support (not firewalld) is a necessary need for those using the nftables service on Fedora, for instance. |
Not sure what's going on there since its now closed. @greenpau Any idea? |
@SilverBut , closed it since I implemented it here: https://github.com/greenpau/cni-plugins |
@dcbw @squeed @mars1024 @erig0 Considering that the PR author abandoned getting this merged here and are content with their own fork - what's missing for you (apart from rebasing) to get this PR to a mergable state? nftables support for firewall is a pretty important feature, and getting moreso as more and more migrate to nft. |
I'm using nftables with customized rules, and do not want any part of the system to alter the rules itself, so that all the firewall rules can be managed in one place and easy to check. Is it possible to have an option to disable iptables just like docker? |
I suggest you create a new issue. |
@greenpau What's stopping you from merging this beautiful new feature into Upstream? |
@unknowndevQwQ the same thing stopping you, presumably :p |
Resolves: #461