Note: This is a public test instance of Red Hat Bugzilla. The data contained within is a snapshot of the live data so any changes you make will not be reflected in the production Bugzilla. Email is disabled so feel free to test any aspect of the site that you want. File any problems you find or give feedback at bugzilla.redhat.com.

Bug 1512783

Summary: Docker embedded DNS doesn't function when running with SELinux and --userns-remap
Product: [Fedora] Fedora Reporter: Lars Becker <lars+bugzilla.redhat.com>
Component: selinux-policyAssignee: Lukas Vrabec <lvrabec>
Status: CLOSED ERRATA QA Contact: Fedora Extras Quality Assurance <extras-qa>
Severity: high Docs Contact:
Priority: unspecified    
Version: 27CC: dwalsh, lvrabec, mgrepl, plautrba, pmoore
Target Milestone: ---   
Target Release: ---   
Hardware: Unspecified   
OS: Linux   
Whiteboard:
Fixed In Version: selinux-policy-3.13.1-283.16.fc27 Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2017-11-20 16:55:43 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:

Description Lars Becker 2017-11-14 05:34:12 UTC
Description of problem:

Version-Release number of selected component (if applicable):

docker (Release: 26.gitb5e3294.fc27)
selinux-policy-targeted (Release: 283.14.fc27)
iptables 1.6.1


How reproducible:
deterministic / always

Problem: Embedded DNS doesn't work since docker can't set up the required iptables rules.
Workaround: manual setup of iptables / firewalld.
Fix: Change the selinux policy as below (probably to unspecific)

Steps to Reproduce:

1. Configure Docker to use SELinux and user namespaces in /etc/sysconfig/docker with OPTIONS='--selinux-enabled --log-driver=journald --userns-remap="dockremap:dockremap"'

2. create docker-compose.yml with a nginx reverse proxy container and a nginx test container named "nginx1" which is used as upstream in the proxy. 

3. docker-compose up fails in starting the reverse proxy with the following error "nginx: [emerg] host not found in upstream "nginx1" in /etc/nginx.conf..."

4. "journalctl -u docker" shows 
 dockerd-current TIMESTAMP level=error msg="setting up rule failed, [-t nat -I DOCKER_OUTPUT -d 127.0.0.11 -p udp --dport 53 -j DNAT --to-destination 127.0.0.11:49285]"
 dockerd-current TIMESTAMP  level=error msg="setting up rule failed, [-t nat -I DOCKER_POSTROUTING -s 127.0.0.11 -p udp --sport 49285 -j SNAT --to-source :53]"
 dockerd-current TIMESTAMP  level=error msg="setting up rule failed, [-t nat -I DOCKER_OUTPUT -d 127.0.0.11 -p tcp --dport 53 -j DNAT --to-destination 127.0.0.11:33531]"
 dockerd-current TIMESTAMP  level=error msg="setting up rule failed, [-t nat -I DOCKER_POSTROUTING -s 127.0.0.11 -p tcp --sport 33531 -j SNAT --to-source :53]"

5. "ausearch -m avc -ts recent" shows 
> type=AVC msg=audit(1510635119.652:3303): avc:  denied  { net_raw } for  pid=14264 comm="iptables" capability=13 scontext=system_u:system_r:iptables_t:s0 tcontext=system_u:system_r:iptables_t:s0 tclass=cap_userns permissive=0

6. "grep iptables /var/log/audit/audit.log | audit2allow -M firewall" and "semodule -i firewall.pp" only helps a bit. New aursearch log shows:

> type=AVC msg=audit(1510635770.377:3714): avc:  denied  { net_admin } for  pid=15826 comm="iptables" capability=12 scontext=system_u:system_r:iptables_t:s0 tcontext=system_u:system_r:iptables_t:s0 tclass=cap_userns permissive=0 

7. "grep iptables /var/log/audit/audit.log | audit2allow -M firewall2" and "semodule -i firewall2.pp" fixes the problem. The containers work as expected since docker sets up the required masquerading for the embedded dns.

Comment 1 Lars Becker 2017-11-14 05:42:41 UTC
Ah, sorry, I missed to include the policy which helped me to work around this problem. Here is it:

module firewall2 1.0;        

require {                    
        type iptables_t;     
        class cap_userns { net_admin net_raw };            
}                            

#============= iptables_t ==============                   
          
allow iptables_t self:cap_userns net_raw;                  
allow iptables_t self:cap_userns net_admin;

Comment 2 Daniel Walsh 2017-11-15 13:46:22 UTC
So this looks like iptables is running within the user namespace?

Comment 3 Daniel Walsh 2017-11-15 13:58:42 UTC
https://github.com/fedora-selinux/selinux-policy/pull/205
Should fix this issue.

Comment 4 Fedora Update System 2017-11-16 15:10:52 UTC
selinux-policy-3.13.1-283.16.fc27 has been submitted as an update to Fedora 27. https://bodhi.fedoraproject.org/updates/FEDORA-2017-5178e6a393

Comment 5 Fedora Update System 2017-11-17 18:55:28 UTC
selinux-policy-3.13.1-283.16.fc27 has been pushed to the Fedora 27 testing repository. If problems still persist, please make note of it in this bug report.
See https://fedoraproject.org/wiki/QA:Updates_Testing for
instructions on how to install test updates.
You can provide feedback for this update here: https://bodhi.fedoraproject.org/updates/FEDORA-2017-5178e6a393

Comment 6 Lars Becker 2017-11-17 20:48:34 UTC
I uninstalled my self build firewall2.pp file with `semodule -r` and installed selinux-policy-3.13.1-283.16.fc27.noarch.rpm and selinux-policy-targeted-3.13.1-283.16.fc27.noarch.rpm from testing. I can confirm that the installation of those two packages fix my problem. Thanks!

Comment 7 Fedora Update System 2017-11-20 16:55:43 UTC
selinux-policy-3.13.1-283.16.fc27 has been pushed to the Fedora 27 stable repository. If problems still persist, please make note of it in this bug report.