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
- iptables -t filter -N DOCKER-USER
- systemctl start docker.service
- 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)
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
and 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:
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
on this bridge
after adding rule manually, it works. sudo ip6tables -A DOCKER -p tcp -d container-ipv6 --dport 443 -j ACCEPT
im using
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
iptablespackage 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 packagesiptables,libip4tc2,libip6tc2, andlibxtables12yourself, 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.