Closed
Description
Description
firewall-cmd --reload on centos 7.4.1708 removes the DOCKER-USER iptables chain.
The reload keeps the two other chains DOCKER and DOCKER-ISOLATION.
Steps to reproduce the issue:
- install CentOS 7
- enable firewalld
- install docker-ce-17.06.2.ce-1.el7.centos.x86_64 from download.docker.com
- start docker engine
- iptables -L -n -v > /tmp/iptables_before_firewalld_reload
- run firewall-cmd --reload
- iptables -L -n -v > /tmp/iptables_after_firewalld_reload
- diff -u /tmp/iptables_before_firewalld_reload /tmp/iptables_after_firewalld_reload
Describe the results you received:
DOCKER-USER chain has disappeared.
Describe the results you expected:
DOCKER-USER chain shouldn't have disappeared.
Additional information you deem important (e.g. issue happens only occasionally):
I entered this bug report to CentOS bug tracker at https://bugs.centos.org/view.php?id=13879
but there was no resolution there. They suggested I file a bug report here.
Output of docker version
:
Client:
Version: 17.06.2-ce
API version: 1.30
Go version: go1.8.3
Git commit: cec0b72
Built: Tue Sep 5 19:59:06 2017
OS/Arch: linux/amd64
Server:
Version: 17.06.2-ce
API version: 1.30 (minimum version 1.12)
Go version: go1.8.3
Git commit: cec0b72
Built: Tue Sep 5 20:00:25 2017
OS/Arch: linux/amd64
Experimental: false
Output of docker info
:
Containers: 0
Running: 0
Paused: 0
Stopped: 0
Images: 0
Server Version: 17.06.2-ce
Storage Driver: overlay2
Backing Filesystem: extfs
Supports d_type: true
Native Overlay Diff: true
Logging Driver: json-file
Cgroup Driver: cgroupfs
Plugins:
Volume: local
Network: bridge host macvlan null overlay
Log: awslogs fluentd gcplogs gelf journald json-file logentries splunk syslog
Swarm: inactive
Runtimes: runc
Default Runtime: runc
Init Binary: docker-init
containerd version: 6e23458c129b551d5c9871e5174f6b1b7f6d1170
runc version: 810190ceaa507aa2727d7ae6f4790c76ec150bd2
init version: 949e6fa
Security Options:
seccomp
Profile: default
Kernel Version: 4.13.4-1.el7.elrepo.x86_64
Operating System: CentOS Linux 7 (Core)
OSType: linux
Architecture: x86_64
CPUs: 2
Total Memory: 1.952GiB
Name: deadbeef.internal
ID: 3SP2:GWZC:Q3ZG:USFU:77DC:MPJ3:NHJR:RD7U:MCO6:FV4U:SCAI:TUUW
Docker Root Dir: /var/lib/docker
Debug Mode (client): false
Debug Mode (server): false
Registry: https://index.docker.io/v1/
Experimental: false
Insecure Registries:
127.0.0.0/8
Live Restore Enabled: false
Additional environment details (AWS, VirtualBox, physical, etc.):
I'm testing this on KVM.
Activity
phlegx commentedon Oct 3, 2017
Yes this happens to me too on
ubuntu
when I re-setup my firewall rules with iptable (ansible raw_iptables). I then need to restart docker daemon to get them back completely.it would be very nice if there would be a
docker reload iptables
for to get the iptables back into the system iptables. Restarting the docker daemon everytime I re-setup the firewall rules is not a nice option.antoinetran commentedon Oct 23, 2017
Strange, it does not happen to me with docker-ce-17.06.0, CentOs 7.3. Reloading firewalld has no impact on docker rules. Maybe a regression of docker-ce?
Yashiroo commentedon Jan 7, 2018
I have the same machine as OP. I'm also having this same issue.
I could not see this behavior on a similar machine (CentOS 7.2 and Docker-CE v17).
Is this related to how firewalld manages rules, or to how Docker saves rules to iptables?
brianbolt commentedon Jan 8, 2018
I also have been hunt this down for a while and here is what seems to be working for me:
TLDR first; If you add the DOCKER-USER chain to firewalld so that it is present in iptables before docker starts then you should be able to apply rules.
Longer story; Firewalld and Docker both use iptables to route traffic. Firewalld always flushes iptables rules and only reinstates rules that have been configured with firewalld. Docker, when it starts, adds a number of chains to the iptables that can possibly conflict with your rules. However, Docker does respect a special "DOCKER-USER" chain that you can configure to filter traffic. If the "DOCKER-USER" chain is not present when Docker starts, Docker will add it and allow all connections being passed to it. However, if the DOCKER-USER chain already exists, it will not do anything to it (except add an "ACCEPT ALL rule" to the END of the chain (which won't do anything if you configure the previous rules in the chain cover all traffic cases).
Here is a sequence of commands I have used over and over again to get my firewalld settings correct. My goal was to only allow traffic to http and https from a few ip addresses:
aki-k commentedon Jan 12, 2018
@brianbolt
I have a problem with the fact that Docker devs haven't commented on this issue report. Even though your solution works now, it might not work in the future if the CentOS and Docker devs don't agree on the correct method on doing this.
cpuguy83 commentedon Jan 12, 2018
I think the main issue here is that docker does not manager the
DOCKER-USER
chain.Perhaps it should re-add the chain when firewalld is reloaded but none of the rules in that chain will be reloaded because these aren't docker's rules.
cpuguy83 commentedon Jan 12, 2018
I think @brianbolt's response is exactly the correct way to deal with this since they are user defined rules.
aki-k commentedon Jan 12, 2018
@cpuguy83
Do you mean the DOCKER-USER chain is created by some CentOS service and not by the docker engine?
cpuguy83 commentedon Jan 12, 2018
@aki-k The
DOCKER-USER
chain itself is created by docker along with the main jump rule, but that is all. The chain is expected to be managed by users.I'll open a PR to ensure that the chain and the initial rule is re-created on firewalld reload.
Reload DOCKER-USER chain on frewalld reload.
cpuguy83 commentedon Jan 12, 2018
opened moby/libnetwork#2053 to ensure the chain is re-created on firewalld reload, but again any user rules will need to be reloaded by the user.
Reload DOCKER-USER chain on frewalld reload.
Reload DOCKER-USER chain on frewalld reload.
vodolaz095 commentedon Nov 5, 2022
Seems like @brianbolt 's solution is still working on centos 8 stream with