#1090355 libvirt-daemon-driver-network: Switch of firewall backend to nftables breaks NAT for guest machines

Package:
libvirt-daemon-driver-network
Source:
libvirt-daemon-driver-network
Description:
Virtualization daemon network driver
Submitter:
Max Hofer
Date:
2024-12-20 17:39:02 UTC
Severity:
normal
#1090355#5
Date:
2024-12-17 10:39:06 UTC
From:
To:
Upgrading to libvirt breaks the internett access to my guest machines
using NAT forwarding. Default firewalld is installed.

I attached the iptables rules from libvirt 10.10.0-1 (using iptables as
firewall backend) and the new one after the upgrade with the nftables as
backend.

Workaround: enable setting 'firewall_backend = "iptables"' in
/etc/libvirt/network.conf restores the old behavior.

#1090355#10
Date:
2024-12-17 12:51:09 UTC
From:
To:
[...]

Thanks for reaching out.

I'm no firewall expert but I see that there are some Docker rules in
there, so I think you might be hitting the same issue mentioned here:

https://fedoraproject.org/wiki/Changes/LibvirtVirtualNetworkNFTables#Known_issue:_docker

Can you try disabling Docker and checking whether the libvirt
nftables backend works as expected then?

We might need to document this incompatibility more prominently, for
example in the release notes.

#1090355#15
Date:
2024-12-18 11:47:53 UTC
From:
To:
I see the same behavior by simply having ufw installed and enabled, no special
rules, no docker installed. Disabling ufw or manually adding blanket INPUT and
FORWARD rules to enable incoming and outgoing traffic from/to the virbr+
interfaces fixes this, but neither is a good solution.

It seems that libvirt should provide extra firewall rules if it wants to play
nicely with nftables. Having ufw (or docker, or anything else really) installed
should not prevent NAT from working. On the other hand, if for some reason this
is the new intended behavior, then the change should be documented together
with the precise list of rules needed to enable NAT when the default for INPUT
and FORWARD is DROP (i.e. usually whenever a firewall is active).

#1090355#20
Date:
2024-12-18 17:39:24 UTC
From:
To:
[re-added the bug report]

When using the nftables backend, the rules will not be created using
iptables so that tool won't know about them.

If you run "nftables list ruleset" you should see a bunch of
libvirt-related rules.

Note that iptables is using the same kernel API as nftables these
days, at least unless you go out of your way to tell it not to:

  $ update-alternatives --query iptables
  Name: iptables
  Link: /usr/sbin/iptables
  Slaves:
   iptables-restore /usr/sbin/iptables-restore
   iptables-save /usr/sbin/iptables-save
  Status: auto
  Best: /usr/sbin/iptables-nft
  Value: /usr/sbin/iptables-nft

  Alternative: /usr/sbin/iptables-legacy
  Priority: 10
  Slaves:
   iptables-restore /usr/sbin/iptables-legacy-restore
   iptables-save /usr/sbin/iptables-legacy-save

  Alternative: /usr/sbin/iptables-nft
  Priority: 20
  Slaves:
   iptables-restore /usr/sbin/iptables-nft-restore
   iptables-save /usr/sbin/iptables-nft-save

I agree.

#1090355#25
Date:
2024-12-18 21:41:08 UTC
From:
To:
This too is a known issue:

https://fedoraproject.org/wiki/Changes/LibvirtVirtualNetworkNFTables#Known_issue:_non-firewalld_firewall_mgmt_tools

Both this and the Docker incompatibility are probably fine in the
context of a distro such as Fedora, where firewalld and Podman are
the "blessed" solutions in their respective fields, but Debian is
much less opinionated than that.

I need to spend some more time thinking about this, but switching the
default network backend back to iptables might be the most reasonable
solution.

#1090355#30
Date:
2024-12-20 09:28:32 UTC
From:
To:
Package: libvirt-daemon-driver-network
Version: 10.10.0-3
Followup-For: Bug #1090355
X-Debbugs-Cc: noisycoil@tutanota.com

Confirmed. DHCP not working is how I first learned about this issue, and the
behavior I see is that described in [1]. With respect to distros, one of the
libvirt maintainers says:

Debian has no default firewall, but ufw's popcon is 20990 vs firewalld's 5010.


[1] https://gitlab.com/libvirt/libvirt/-/issues/644

#1090355#35
Date:
2024-12-20 17:23:14 UTC
From:
To:
Additional data point. ufw is installed and enabled by default on
Ubuntu server. Docker is one of the documented alternatives among
container runtimes; Podman isn't.

I think it's obvious at this point that the default should go back to
iptables. Users can easily switch to nftables if desired, but things
should work reasonably well out of the box.

I'll prepare a patch and an upload over the next few days.

#1090355#40
Date:
2024-12-20 17:28:37 UTC
From:
To:
Thanks Andrea!