canonical / lxd

Powerful system container and virtual machine manager
https://canonical.com/lxd
GNU Affero General Public License v3.0
4.32k stars 926 forks source link

LXD snap fails to load xtables firewall driver on system without nftables #11697

Closed antonc42 closed 1 year ago

antonc42 commented 1 year ago

Required information

Issue description

On a new Kubuntu 22.04 install, I disabled and removed nftables and ufw. I'm using plain iptables. After installing the LXD snap, it is not implementing any automatic iptables rules. Therefor the containers do not get DHCP addresses or get NATed and cannot communicate on the network. It appears that for some reason LXD is chosing the 'nftables' firewall driver instead of 'xtables'. From looking at some other discussion threads and the driver code, it appears that it should not do this if the 'nft' command is not available on the system, which it is not.

Steps to reproduce

  1. Ensure nftables is not installed.
    nft
    bash: nft: command not found
    sudo update-alternatives --display iptables
    iptables - manual mode
    link best version is /usr/sbin/iptables-nft
    link currently points to /usr/sbin/iptables-legacy
    link iptables is /usr/sbin/iptables
    slave iptables-restore is /usr/sbin/iptables-restore
    slave iptables-save is /usr/sbin/iptables-save
    /usr/sbin/iptables-legacy - priority 10
    slave iptables-restore: /usr/sbin/iptables-legacy-restore
    slave iptables-save: /usr/sbin/iptables-legacy-save
    /usr/sbin/iptables-nft - priority 20
    slave iptables-restore: /usr/sbin/iptables-nft-restore
    slave iptables-save: /usr/sbin/iptables-nft-save
  2. There are iptables-legacy rules present
    
    sudo iptables -nvL
    Chain INPUT (policy DROP 0 packets, 0 bytes)
    pkts bytes target     prot opt in     out     source               destination         
    122K  108M PREEMT     all  --  *      *       0.0.0.0/0            0.0.0.0/0           
    122K  108M PREPROC    all  --  *      *       0.0.0.0/0            0.0.0.0/0           
    724  142K MAIN       all  --  *      *       0.0.0.0/0            0.0.0.0/0           
    706  140K REJECT     udp  --  *      *       0.0.0.0/0            0.0.0.0/0            /* reject all other UDP */ reject-with icmp-port-unreachable
    18  1899 REJECT     tcp  --  *      *       0.0.0.0/0            0.0.0.0/0            /* reject all other TCP */ reject-with tcp-reset
    0     0 REJECT     all  --  *      *       0.0.0.0/0            0.0.0.0/0            /* reject all other packets */ reject-with icmp-proto-unreachable

Chain FORWARD (policy DROP 0 packets, 0 bytes) pkts bytes target prot opt in out source destination

Chain OUTPUT (policy ACCEPT 112K packets, 31M bytes) pkts bytes target prot opt in out source destination

(rest of tables redacted)

 5. LXD still chooses 'nftables' firewall driver and fails to put automatic rules in iptables.

lxc info | grep firewall: firewall: nftables

 6. It appears that the 'nft' command exists inside the snap. Could this be affecting how the driver is detected?

sudo find / -name nft /snap/lxd/24846/bin/nft


# Information to attach

sudo snap set lxd daemon.debug=true sudo systemctl reload snap.lxd.daemon


[/var/snap/lxd/common/lxd/logs/lxd.log](https://github.com/lxc/lxd/files/11500817/lxd.log)
tomponline commented 1 year ago

What does iptables-save show and what does iptables -v show?

tomponline commented 1 year ago

Also if you reinstall nft temporarily what does "nft list ruleset" show? I suspect you have nft rules still active (either from nft or from the iptables-nft shim)

antonc42 commented 1 year ago

You were correct. There were some IPv6 rules in the nft ruleset. I forgot to do update-alternatives on ip6tables. Everything appears to be working now. Sorry for the trouble, and thanks for all the great work on LXD!