Bug 1225556

Summary: docker relabel of volumes is buggy if the mode is "roz"
Product: Red Hat Enterprise Linux 7 Reporter: Laurent Rineau <laurent.rineau__fedora>
Component: dockerAssignee: Daniel Walsh <dwalsh>
Status: CLOSED ERRATA QA Contact: Luwen Su <lsu>
Severity: high Docs Contact:
Priority: unspecified    
Version: 7.1CC: dwalsh, lsm5, lsu, mjenner, sghosh
Target Milestone: rcKeywords: Extras
Target Release: ---   
Hardware: Unspecified   
OS: Linux   
Whiteboard:
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Cause: Docker is not performing relabel, if the volume is specified with more then one object, z: works, roz: fails. Consequence: You can not mount a volume that is both readonly and needs a relabel at the same time. Fix: Fix the labeling check. Result: You can mount a volume that is both readonly and needs relabel at same time.
Story Points: ---
Clone Of: 1225549 Environment:
Last Closed: 2015-06-23 09:30:00 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:
Bug Depends On: 1225549    
Bug Blocks: 1211379    

Description Laurent Rineau 2015-05-27 16:30:48 UTC
Docker version 1.6.0-11.0.1.el7 has been pushed to RHELĀ 7.1 (I am actually using CentOSĀ 7.1). That version contains the relabelling feature for volumes, but the following commit of libcontainer is not is 1.6.0-11.0.1.el7:

https://github.com/docker/libcontainer/commit/4518bce5bb440fc6bed37e658c2aad7855633ced

The bug is in label/label_selinux.go of libcontainer, in the function `func Relabel(path string, fileLabel string, relabel string)`. If the volume is suffixed with `:roz` for the mode, then the `relabel` variable value is `roz`. As the value is not 'z', the volume is relabelled using a private label, instead of being shared. The quoted commit clearly fixes the bug.

Daniel J. Walsh already said that the bug would be fixed in docker-1.6.2 (see the comments at the bottom of the Github page for the commit). I fill this bug report for the record.

Comment 1 Laurent Rineau 2015-05-27 16:33:38 UTC
I set the severity to "high" because that bug prevents the possibility to share read-only volumes between several containers. I had to downgrade to 
1.5.0-28.el7 so that my containers work again.

Comment 2 Daniel Walsh 2015-05-27 16:44:15 UTC
Fixed in docker 1.6.2

Comment 3 Laurent Rineau 2015-06-02 15:16:41 UTC
Is there somewhere I can get access to the sources of the docker-1.6.2 RPM? I would like to test it even before it is released. I read somewhere that the Git for RHEL is shared on CentOS here: git.centos.org, but it must be wrong because all I see at https://git.centos.org/forks/rpms!docker is about CentOS, and not RHEL.

Comment 7 Lokesh Mandvekar 2015-06-15 16:02:25 UTC
Laurent, could you try this please:

'yum install https://lsm5.fedorapeople.org/docker-1.6.2-12.el7.x86_64.rpm https://lsm5.fedorapeople.org/docker-selinux-1.6.2-12.el7.x86_64.rpm'

Comment 8 Laurent Rineau 2015-06-15 16:19:44 UTC
I have the impression that it is not fixed.

cgal ~/Git/cgal-testsuite-dockerfiles $ rpm -q docker docker-selinux
docker-1.6.2-12.el7.x86_64
docker-selinux-1.6.2-12.el7.x86_64
cgal ~/Git/cgal-testsuite-dockerfiles $ docker version
Client version: 1.6.2
Client API version: 1.18
Go version (client): go1.4.2
Git commit (client): eb12bd2-dirty
OS/Arch (client): linux/amd64
Server version: 1.6.2
Server API version: 1.18
Go version (server): go1.4.2
Git commit (server): eb12bd2-dirty
OS/Arch (server): linux/amd64
cgal ~/Git/cgal-testsuite-dockerfiles $ ls -lZd test*/
drwxr-xr-x. lrineau geometryfactory system_u:object_r:svirt_sandbox_file_t:s0 testresults/
drwxr-xr-x. lrineau geometryfactory system_u:object_r:svirt_sandbox_file_t:s0 testsuite/
cgal ~/Git/cgal-testsuite-dockerfiles $ docker run --rm -v $PWD/testsuite:/testsuite:roz -v $PWD/testresults:/testresults:rwz fedora /bin/bash -c 'ls -lZd /test*'
drwxr-xr-x. 500 501 system_u:object_r:svirt_sandbox_file_t:s0:c200,c705 /testresults
drwxr-xr-x. 500 501 system_u:object_r:svirt_sandbox_file_t:s0:c200,c705 /testsuite

One volume was declared with :roz and the other with :rwz, and both have been relabeled to the private security level s0:c200,c705.

Is there something wrong in my command line to create/launch the container?

Comment 11 Luwen Su 2015-06-16 03:37:41 UTC
(In reply to Lokesh Mandvekar from comment #10)
> sorry my bad, please try: yum install
> https://lsm5.fedorapeople.org/docker-1.6.2-14.el7.x86_64.rpm
> https://lsm5.fedorapeople.org/docker-selinux-1.6.2-14.el7.x86_64.rpm

Thanks! It works fine for me
# docker run -v /root/test:/test:z --rm rhel7 ls -aZ / | grep test
drwxr-xr-x. root root system_u:object_r:svirt_sandbox_file_t:s0 test

# docker run -v /root/test:/test:roz --rm rhel7 ls -aZ / | grep test
drwxr-xr-x. root root system_u:object_r:svirt_sandbox_file_t:s0 test

Move to verified

Comment 12 Laurent Rineau 2015-06-22 12:12:31 UTC
(In reply to Lokesh Mandvekar from comment #10)
> sorry my bad, please try: yum install
> https://lsm5.fedorapeople.org/docker-1.6.2-14.el7.x86_64.rpm
> https://lsm5.fedorapeople.org/docker-selinux-1.6.2-14.el7.x86_64.rpm

I confirm those builds fix the bug. Thanks.

Comment 14 errata-xmlrpc 2015-06-23 09:30:00 UTC
Since the problem described in this bug report should be
resolved in a recent advisory, it has been closed with a
resolution of ERRATA.

For information on the advisory, and where to find the updated
files, follow the link below.

If the solution does not work for you, open a new bug report.

https://rhn.redhat.com/errata/RHBA-2015-1167.html

Comment 15 Laurent Rineau 2015-06-28 16:04:24 UTC
The new build is now officially on CentOS 7. Thanks a lot for the fix!