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

Uneeded dependency on iptables modules #6258

Closed simondeziel closed 4 years ago

simondeziel commented 4 years ago

Required information

Issue description

lxd insists on having iptables related modules loaded when editing/creating networks even when ipv{4,6}.firewall: "false". Here are the steps to reproduce the issue with iptable_mangle and ip6table_nat.

Steps to reproduce

  1. Remove modules modprobe -r iptable_mangle ip6table_nat
  2. Prevent automatic module loading sysctl kernel.modprobe=/bin/false
  3. Try to create a network
    lxc network create foo ipv4.address=none ipv4.firewall=false ipv6.address=none ipv6.firewall=false

This will fail with the error:

Error: Failed to list ipv4 rules for LXD network foo (table mangle)
  1. Manually load iptable_mangle /sbin/modprobe iptable_mangle
  2. Try to create a network
    lxc network create foo ipv4.address=none ipv4.firewall=false ipv6.address=none ipv6.firewall=false

This will fail with the error:

Error: Failed to list ipv6 rules for LXD network foo (table nat)

Additional information

I have no use for iptable_mangle nor ip6table_nat modules so they are not part of the short list of modules that are loaded on boot prior to disabling module loading with sysctl kernel.modules_disabled=1. This is how I noticed that lxd insisted on having them loaded.

I believe that lxd should try to list existing firewall rules but fail gracefully if it cannot and no firewall integration was requested for the network being edited/created.

stgraber commented 4 years ago

Right now we can't tell whether a network is getting created for the first time or updated so ignoring cleanup errors can be a problem if you were trying to turn off firewalling rather than creating a new network with it disabled.

It shouldn't be particularly hard to pass that extra data through at which point we can start being a bit smarter with this and other similar cases.