moby: Failure to create correct firewall rules under Debian 12 ("Bookworm")

Description

Docker does create the DOCKER-USER chain along with a jump rule at the top of the FORWARD chain to the aforementioned chain. This does work as expected under Debian 11 and under Debian 12 as long as the DOCKER-USER chain does not yet exist when Docker is being started.

However, if the DOCKER-USER chain already does exist, e.g. because it has been manually created, the Docker services produces an error message during startup, indicating that the chain already exists.

level=warning msg="Failed to create DOCKER-USER IPV4 chain" error="iptables failed: iptables -t filter -N DOCKER-USER: iptables: Chain already exists.\n (exit status 1)"

More importantly, this leads to the knock-on effect that no jump rule at the top of the FORWARD chain is created, leading to a situation where the DOCKER-USER chain is effectively being ignored.

Using the same Docker version and configuration, this issue does not occur under Debian 11 even if the DOCKER-USER chain already exists, it only occurs under Debian 12 if the chain exists already.


The most likely explanation seems to be different behaviour by at least one of the packages on the OS side to which Docker reacts slightly differently, and does not create the jump rule.

Reproduce

  1. iptables -t filter -N DOCKER-USER
  2. systemctl start docker.service
  3. nft list ruleset

-> jump rule in FORWARD chain is missing

Expected behavior

Jump rule to DOCKER-USER at the top of the FORWARD chain exists.

docker version

Client: Docker Engine - Community
 Version:           24.0.5
 API version:       1.43
 Go version:        go1.20.6
 Git commit:        ced0996
 Built:             Fri Jul 21 20:35:35 2023
 OS/Arch:           linux/amd64
 Context:           default

Server: Docker Engine - Community
 Engine:
  Version:          24.0.5
  API version:      1.43 (minimum version 1.12)
  Go version:       go1.20.6
  Git commit:       a61e2b4
  Built:            Fri Jul 21 20:35:35 2023
  OS/Arch:          linux/amd64
  Experimental:     false
 containerd:
  Version:          1.6.22
  GitCommit:        8165feabfdfe38c65b599c4993d227328c231fca
 runc:
  Version:          1.1.8
  GitCommit:        v1.1.8-0-g82f18fe
 docker-init:
  Version:          0.19.0
  GitCommit:        de40ad0

docker info

Client: Docker Engine - Community
 Version:    24.0.5
 Context:    default
 Debug Mode: false
 Plugins:
  buildx: Docker Buildx (Docker Inc.)
    Version:  v0.11.2
    Path:     /usr/libexec/docker/cli-plugins/docker-buildx
  compose: Docker Compose (Docker Inc.)
    Version:  v2.20.2
    Path:     /usr/local/lib/docker/cli-plugins/docker-compose

Server:
 Containers: 5
  Running: 3
  Paused: 0
  Stopped: 2
 Images: 8
 Server Version: 24.0.5
 Storage Driver: overlay2
  Backing Filesystem: extfs
  Supports d_type: true
  Using metacopy: false
  Native Overlay Diff: true
  userxattr: false
 Logging Driver: json-file
 Cgroup Driver: systemd
 Cgroup Version: 2
 Plugins:
  Volume: local
  Network: bridge host ipvlan macvlan null overlay
  Log: awslogs fluentd gcplogs gelf journald json-file local logentries splunk syslog
 Swarm: inactive
 Runtimes: io.containerd.runc.v2 runc
 Default Runtime: runc
 Init Binary: docker-init
 containerd version: 8165feabfdfe38c65b599c4993d227328c231fca
 runc version: v1.1.8-0-g82f18fe
 init version: de40ad0
 Security Options:
  apparmor
  seccomp
   Profile: builtin
  cgroupns
 Kernel Version: 6.1.0-10-amd64
 Operating System: Debian GNU/Linux 12 (bookworm)
 OSType: linux
 Architecture: x86_64
 CPUs: 10
 Total Memory: 31.34GiB
 Name: <MY DOMAIN>
 ID: <MY ID>
 Docker Root Dir: /var/lib/docker
 Debug Mode: false
 Experimental: false
 Insecure Registries:
  127.0.0.0/8
 Live Restore Enabled: false

Additional Info

Debian 12 versions:

  • debian_version: 12.1
  • iptables v1.8.9 (nf_tables)
  • nftables v1.0.6 (Lester Gooch # 5)

Debian 11 versions:

  • debian_version: 11.7
  • iptables v1.8.7 (nf_tables)
  • nftables v0.9.8 (E.D.S.)

About this issue

  • Original URL
  • State: open
  • Created 3 years ago
  • Reactions: 1
  • Comments: 19 (4 by maintainers)

Commits related to this issue

Most upvoted comments

I had the same issue, found this discussion late and found a more easy debian 12 work around as a simple fix:

edit /etc/connman/main.conf add blacklist entries for potential virtual networks

[General]
NetworkInterfaceBlacklist=vmnet,vboxnet,virbr,ifb,docker,veth,eth,wlan

and restart connman

sudo systemctl restart connman

Why: connman may attempt to connect to one of these instead of your physical adapter if the connection drops.

The main discussion, what could be a reason, is found here from the docker/arch community: https://forums.docker.com/t/solved-no-network-when-running-a-container-in-arch-linux/5494/5 https://wiki.archlinux.org/title/ConnMan#Blacklist_interfaces The solution is documented here: https://stackoverflow.com/a/77547445

and the system info on which setup the fix worked out:

# cat /etc/debian_version
12.9

# cat /etc/issue
Debian GNU/Linux 12 

# apt list connman
connman/stable,now 1.41-3 amd64

ive run into a similiar problem, im using a bridge with ipv6 enabled and a prefix delegeted subnet. subnet is /62 and range is /64. it only fails to create dport 443/tcp with the container ip. 443/udp no problem. additionally, i`ve set

 -o com.docker.network.bridge.gateway_mode_ipv6=routed

on this bridge

Chain DOCKER (1 references)
target     prot opt source               destination
ACCEPT     tcp  --  anywhere             2001:db8::2  tcp dpt:http
ACCEPT     udp  --  anywhere             2001:db8::2  udp dpt:https

after adding rule manually, it works. sudo ip6tables -A DOCKER -p tcp -d container-ipv6 --dport 443 -j ACCEPT

im using

sudo iptables --version
iptables v1.8.9 (legacy)
Client: Docker Engine - Community
 Version:    27.4.1
 Context:    default
 Debug Mode: false
 Plugins:
  buildx: Docker Buildx (Docker Inc.)
    Version:  v0.19.3
    Path:     /usr/libexec/docker/cli-plugins/docker-buildx
  compose: Docker Compose (Docker Inc.)
    Version:  v2.32.1
    Path:     /usr/libexec/docker/cli-plugins/docker-compose

Server:
 Containers: 20
  Running: 19
  Paused: 0
  Stopped: 1
 Images: 74
 Server Version: 27.4.1
 Storage Driver: overlay2
  Backing Filesystem: extfs
  Supports d_type: true
  Using metacopy: false
  Native Overlay Diff: true
  userxattr: false
 Logging Driver: json-file
 Cgroup Driver: systemd
 Cgroup Version: 2
 Plugins:
  Volume: local
  Network: bridge host ipvlan macvlan null overlay
  Log: awslogs fluentd gcplogs gelf journald json-file local splunk syslog
 Swarm: inactive
 Runtimes: io.containerd.runc.v2 runc
 Default Runtime: runc
 Init Binary: docker-init
 containerd version: 88bf19b2105c8b17560993bee28a01ddc2f97182
 runc version: v1.2.2-0-g7cb3632
 init version: de40ad0
 Security Options:
  apparmor
  seccomp
   Profile: builtin
  cgroupns
 Kernel Version: 6.11.10+bpo-amd64
 Operating System: Debian GNU/Linux 12 (bookworm)
 OSType: linux
 Architecture: x86_64
 CPUs: 8
 Total Memory: 15.42GiB
 Name: debian-home
 ID: 7464a19e-3e72-4b5e-b6b2-e827227777b9
 Docker Root Dir: /var/lib/docker
 Debug Mode: false
 Experimental: false
 Insecure Registries:
  127.0.0.0/8
 Live Restore Enabled: false

The real problem is that Docker does not currently support nftables directly and instead relies on the nftables-iptables compatibility layer on systems that are using nftables when it is managing the firewall rules. This is what necessitates the workaround with the meta mark rule in the first place. Unfortunately, that workaround is now broken when using version 1.8.9 of the iptables packages. The only other option except for using version 1.8.8 would be to disable Docker’s handling of FW rules and manage them manually.

But the real solution would be for Docker to implement direct support of nftables. Then we would not need the workaround in the first place, and we would not run into this bug. Given that nftables is effectively the designated successor of iptables, it is to be expected that more distributions will make the switch eventually which is a good reason why Docker should be able to work with it.

It’s a problem with the iptables package that was introduced in version 1.8.9. I can’t remember the specific commit, but it had something to do with meta rules, I think. Anyway, the best solution for the time being on Debian 12 seems to be to build the 1.8.8 version of the packages iptables, libip4tc2, libip6tc2, and libxtables12 yourself, install them, and block updates. Hopefully, upstream will eventually get around to fixing this. But even then, it might take Debian some time to update the package, too.

EDIT: They do have a Bugzilla issue open for this, but unfortunately, this is one of those annoying projects that make it really difficult to reach them.