A Fedora user posted a bugzilla complaining about SELinux blocking transfer of socket file descriptors between two docker containers.
Lets look at what happens when a socket file descriptor is created by a process.
When a process accepts a connection from a remote system, the file descriptor is created by a process it automatically gets assigned the same label as the process creating the socket. For example when the docker service (docker_t) listens on /var/run/docker.sock and a client connects the docker service, the docker service end of the connection gets labeled by default with the label of the docker process. On my machine this is:
The client is probably running as unconfined_u:unconfined_r:unconfined_t:s
If this socket descriptor is passed to another process the new process label has to have access to the socket with the "socket label". If it does not SELinux will block the transfer.
In containers, even though by default all container processes have the same SELinux typo, they have different MCS Labels.
If I have a process labeled system_u:system_r:svirt_lxc_net_t:s0:c1,c
The bug reporter was reporting that by default he was not able to pass the descriptor, which is goodness. We would not want to allow a confined container to be able to read/write socket file descriptors from another container by default.
The reporter also figured out that he could get this to work by disabling SELinux either on the host or inside of the container.
Surprisingly he also figured out if he shared IPC namespaces between the containers, SELinux would not block.
The reason for this is when you share the same IPC Namespace, docker automatically caused the containers share the Same SELinux label. If docker did not do this SELinux would block processes from container A access to IPCs created in Container B. With a shared IPC the SELinux labels for both of the reporters containers were the same, and SELinux allowed the passing.
How would I make two containers share the same SELinux labels?
Docker by default launches all containers with the same type field, but different MCS labels. I told the reporter that you could cause two containers to run with the same MCS labels by using the --security-opt label:level:MCSLABEL option.
Something like this will work
docker run -it --rm --security-opt label:level:s0:c1000,c1001 --name server -v myvol:/tmp test /server
docker run -it --rm --security-opt label:level:s0:c1000,c1001 --name client -v myvol:/tmp test /client
These containers would then run with the same MCS labels, which would give the reporter the best security possible and still allow the two containers to pass the socket between containers. These containers would still be locked down with SELInux from the host and other containers, however they would be able to attack each other from an SELinux point of view, however the other container separation security would still be in effect to prevent the attacks.