NOTE: manipulating DOCKER-USER is beyond anyone’s sanity. The information bellow seems to work sometimes (like when I wrote the post) and others not. That is why you will find posts with similar advise on the Net that may or may not work for you. I plan to revisit this and figure out what is wrong, making the following information only temporarily correct.
When you want to run ZooNavigator, the recommendation to get you started is via this docker-compose.yml. However, Docker manages your iptables (unless you go the –iptables=false way) and certain ports will be left wide open. This may not be what you want to do. Docker provides the DOCKER-USER chain for user defined rules that are not affected by service restarts and this is where you want to work. Most of my googling resulted in recipes that did not work, because their final rule was to deny anything from 0.0.0.0/0 after having allowed whatever was to be whitelisted. I solved this in the following example playbook, and the rules worked like a charm. Others that may find themselves in the same situation may want to give it a shot:
---
- name: maintain the DOCKER-USER access list
hosts: zoonavigators
vars:
- wl_hosts:
- "172.31.0.1"
- "172.31.0.2"
- wl_ports:
- "7070"
- "7071"
tasks:
- name: check for iptables-services
yum:
name: iptables-services
state: latest
- name: enable iptables-services
service:
name: iptables
enabled: yes
state: started
- name: flush DOCKER-USER
iptables:
chain: DOCKER-USER
flush: true
- name: whitelist for DOCKER-USER
iptables:
chain: DOCKER-USER
protocol: tcp
ctstate: NEW
syn: match
source: "{{ item[0] }}"
destination_port: "{{ item[1] }}"
jump: ACCEPT
with_nested:
- "{{ wl_hosts }}"
- "{{ wl_ports }}"
- name: drop non whitelisted connections to DOCKER-USER
iptables:
chain: DOCKER-USER
protocol: tcp
#source: "0.0.0.0/0"
destination_port: "{{ item }}"
jump: DROP
with_items:
- "{{ wl_ports }}"
- name: save new iptables
command:
/usr/libexec/iptables/iptables.init save
Line 46 is the key. The obvious choice would have been source: "0.0.0.0/0" but this did not work for me.
Replace the yum module with the package module and you are golden
(some of us have to work with Ubuntu. pity us)
Very useful example !