I just updated my machine today, and when I run an nvidia-docker container, I get the following in /var/log/messages
Aug 30 16:12:35 viola audit[25758]: AVC avc: denied { entrypoint } for pid=25758 comm="nvidia-docker" path="/usr/bin/docker" dev="sdc3" ino=12832289 scontext=unconfined_u:system_r:xserver_t:s0-s0:c0.c1023 tcontext=system_u:object_r:container_runtime_exec_t:s0 tclass=file permissive=0
Same happens with docker-compose
I can change the secontext on nvidia-docker and that fixes it. So the main question I have
semanage fcontext -l | grep nvidia reveals the context rule causing the problem
/usr/bin/nvidia.* regular file system_u:object_r:xserver_exec_t:s0
Which I suspect come from the nvidia cuda driver rpms I get from the official nvidia Fedora 27 cuda repo (Since there is still no Fedora 28 Repo).
If the context for nvidia-docker is indeed wrong, then maybe the nvidia-docker rpms should add a special rule, like
/usr/bin/nvidia-docker regular file system_u:object_r:container_runtime_exec_t:s0
My understanding of selinux is still pretty weak, so I could be way off base here.
nvidia-docker run -it --rm nvidia/cuda nvidia-smi
ls -lZ /usr/bin/docker /usr/bin/nvidia-docker
[root@computer bin]# nvidia-docker run -it --rm nvidia/cuda nvidia-smi
/usr/bin/nvidia-docker: line 34: /usr/bin/docker: Permission denied
/usr/bin/nvidia-docker: line 34: /usr/bin/docker: Success
-rwxr-xr-x. 1 root root system_u:object_r:container_runtime_exec_t:s0 33069424 Aug 21 13:27 /usr/bin/docker
-rwxr-xr-x. 1 root root system_u:object_r:xserver_exec_t:s0 721 Aug 21 20:25 /usr/bin/nvidia-docker
sudo chcon system_u:object_r:container_runtime_exec_t:s0 /usr/bin/nvidia-docker
ls -lZ /usr/bin/docker /usr/bin/nvidia-docker
semanage fcontext -a -f f -t container_runtime_exec_t -s system_u /usr/bin/nvidia-docker
nvidia-docker run -it --rm nvidia/cuda echo hi
-rwxr-xr-x. 1 root root system_u:object_r:container_runtime_exec_t:s0 33069424 Aug 21 13:27 /usr/bin/docker
-rwxr-xr-x. 1 root root system_u:object_r:container_runtime_exec_t:s0 721 Aug 21 20:25 /usr/bin/nvidia-docker
hi
https://fedoraproject.org/wiki/PackagingDrafts/SELinux#File_contexts
This also affects nvidia-docker v1
Had the same issue on CentOS 7
It's on my TODO list to add a PR for this. I've been learning a lot about SE Linux since opening this :(
The workaround is to use semanage fcontext -a -f f -t container_runtime_exec_t -s system_u /usr/bin/nvidia-docker, and this will fix the context issue permanently (the chcon was only temporary, and would be lost if a relabel ever occurred). [[1](https://fedoraproject.org/wiki/PackagingDrafts/SELinux#File_contexts)]
However having semange as a install/uninstall dependency is a little much. And I know most RPMs don't do this. I also can't find any examples of how to handle this correctly... (like in nvidia driver).
Generally, this is what you do in an rpm spec for an selinux package, that you make a separate rpm from the "core" package
A type enforcement file: nvidia_docker.te
policy_module(nvidia_docker 1.0);
A file context file: nvidia_docker.fc
/usr/bin/nvidia-docker -- system_u:object_r:container_runtime_exec_t:s0
And then you build the policy package file: nvidai_docker.pp
make -f %{_datadir}/selinux/devel/Makefile
And when the preinstall step would say semodule -i nvidia_docker.pp
semodule -r nvidia_dockerCouldn't get fixfiles working, so restorecon -F /usr/bin/nvidia-docker if you are running this after install
https://fedoraproject.org/wiki/SELinux_Policy_Modules_Packaging_Draft
nvidia_docker.te
module my_nvidia_docker 1.0;
require {
type container_runtime_exec_t;
}
Same nvidia_docker.fc
checkmodule -M -m -o nvidia_docker.mod nvidia_docker.tesemodule_package -o nvidia_docker.pp -m nvidia_docker.mod -f nvidia_docker.fcsemodule -X 300 -i nvidia_docker.ppTo work around this issue as a user on a machine with SELinux such as CentOS 7 you can run the following commands:
$ sudo semanage fcontext -a -t container_runtime_exec_t /usr/bin/nvidia-docker
$ sudo restorecon -v /usr/bin/nvidia-docker
I look forward to this issue being fixed in the package itself.
I think there is a typo here:
$ sudo semanage fcontext -t container_runtime_exec_t /usr/bin/nvidia-docker
Ah, yes, there was an -a missing. Edited the comment for posterity.
Has this issue been resolved in master?
Not really afaik. However, with the new "native" support, you don't need nvidia-docker anymore, so this path is "deprecated"
Could someone provide a link on how to set up the new implementation?
I wasn't aware this has been integrated either ..
https://github.com/NVIDIA/nvidia-docker/wiki/Installation-(Native-GPU-Support)
Also in the readme..
Note that with the release of Docker 19.03, usage of nvidia-docker2 packages are deprecated since NVIDIA GPUs are now natively supported as devices in the Docker runtime. If you are an existing user of the nvidia-docker2 packages, review the instructions in the “Upgrading with nvidia-docker2” section.
Thank you!
Den fre 20 sep. 2019 kl 15:14 skrev Jason Heffner <[email protected]
:
I wasn't aware this has been integrated either ..
https://github.com/NVIDIA/nvidia-docker/wiki/Installation-(Native-GPU-Support)
Also in the readme..
Note that with the release of Docker 19.03, usage of nvidia-docker2
packages are deprecated since NVIDIA GPUs are now natively supported as
devices in the Docker runtime. If you are an existing user of the
nvidia-docker2 packages, review the instructions in the “Upgrading with
nvidia-docker2” section.—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
https://github.com/NVIDIA/nvidia-docker/issues/814?email_source=notifications&email_token=AAE2PR67RFWKTCQU3WMNPV3QKTEELA5CNFSM4FSQZJD2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD7GVAQI#issuecomment-533549121,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AAE2PRZ2PLNPPN7HTAPTMV3QKTEELANCNFSM4FSQZJDQ
.
another workaround:
sudo mv nvidia-docker nvidia-docker.copy
sudo cp nvidia-docker.copy nvidia-docker
sudo rm nvidia-docker.copy
Most helpful comment
To work around this issue as a user on a machine with SELinux such as CentOS 7 you can run the following commands:
I look forward to this issue being fixed in the package itself.