You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Support devcontainers on Linux hosts using SELinux #1283
True, that might be a possibility. But the security-opts must be added as runargs, right? And as far as I know, the runargs are set in the devcontainer-file. However, if I do this, I don't know if it would affect other repository collaborators negatively.
Also, the label can be added to the $HOME/.config/containers/containers.conf-file, but then it affects all containers for that user
What are the alternatives to adding something like runArgsSelinux to the
devcontainers spec ?
- call a script that conditionally includes $runargsSelinux in $runArgs
- this would probably work
- disadvantages:
- there's then a shell with elevated privileges instead of an execve(.,
*(runargsWithSelinux))
-
Thanks @haakobja for reporting the issue and providing a good summary of the problem. I'm not too sure if we should change devpod though to accommodate this, other than document the use case in the docs. I'm unsure of how devpod would detect dynamically that SELinux is running in the local environment to know to edit the .devcontainer.json. Currently we do not mutate this file and expect it to be configured by the developer. Devpod does support using alternative devcontainer.json via --devcontainer-path and --devcontainer-source though. I can see a workaround involving the creation of a .devcontainer.selinux.json and simply pointing devpod to this file for users with SELinux. Do you think that would be appropriate?
@bkneis I think your suggestion would suffice for me at the moment. Thank you.
An alternative may be to add it to the Docker provider, just to make the security label configurable. I never meant for DevPod to detect SELinux automatically.
Devcontainers.json was specified by ms for windows, which doesn't have
selinux; so it may be reasonable to request extra attrs for selinux in the
devcontainers spec.
Do other tools have solutions for this?
remoteUser 🏷️ string: Overrides the user that devcontainer.json supporting services tools / runs as in the container (along with sub-processes like terminals, tasks, or debugging). Does not change the user the container as a whole runs as which can be set using containerUser. Defaults to the user the container as a whole is running as (often root). You may learn more in the remoteUser section below.
capAdd 🏷️ array: Defaults to []. Cross-orchestrator way to add
capabilities typically disabled for a container. Most often used to add the
ptrace capability required to debug languages like C++, Go, and Rust. For
example:
"capAdd": ["SYS_PTRACE"]
securityOpt 🏷️ array: Defaults to []. Cross-orchestrator way to set
container security options. For example:
Shouldn't it be possible to omit the securityOpt label=disable and instead use :z/:Z to relabel volumes (that cross an (selinux) context boundary) and --userns to remap uid and gid of the [rootless] user that owns the mounted volume to the necessary uid and gid within the container?
Though is it better to run --userns=auto:size=2 for root and an app user?
(I've fixed the email markdown formatting, which gh now mangles unfortunately).
How should -userns=keep-id:uid=1000,gid=100 be specified to get e.g. the jupyter/scipy-notebook docker stack working with Fedora 40 (and other RH linux distros like RHEL, SUSE, Rocky, Alma)?
I think :Z or :z (private or shared SELinux context) or label=false should be set by DevPod.
I agree with @haakobja in suggesting that :Z or :z should be set automatically by DevPod if SELinux is active and the user configured DevPod as such (so it could be a new config option added to DevPod).
This would be especially important in devcontainers (and DevPod) as some of the mounts are not under the control of the user, for example devcontainer features can add mounts themselves.
Activity
westurner commentedon Sep 28, 2024
--security-opt=label=disableor--security-opt=label=nestedor a more restrictive label= value?https://docs.podman.io/en/v4.6.1/markdown/options/security-opt.html#security-opt-option
haakobja commentedon Oct 4, 2024
True, that might be a possibility. But the security-opts must be added as runargs, right? And as far as I know, the runargs are set in the devcontainer-file. However, if I do this, I don't know if it would affect other repository collaborators negatively.
Also, the label can be added to the
$HOME/.config/containers/containers.conf-file, but then it affects all containers for that userwesturner commentedon Oct 4, 2024
bkneis commentedon Oct 7, 2024
Thanks @haakobja for reporting the issue and providing a good summary of the problem. I'm not too sure if we should change devpod though to accommodate this, other than document the use case in the docs. I'm unsure of how devpod would detect dynamically that SELinux is running in the local environment to know to edit the .devcontainer.json. Currently we do not mutate this file and expect it to be configured by the developer. Devpod does support using alternative devcontainer.json via
--devcontainer-pathand--devcontainer-sourcethough. I can see a workaround involving the creation of a.devcontainer.selinux.jsonand simply pointing devpod to this file for users with SELinux. Do you think that would be appropriate?haakobja commentedon Oct 7, 2024
@bkneis I think your suggestion would suffice for me at the moment. Thank you.
An alternative may be to add it to the Docker provider, just to make the security label configurable. I never meant for DevPod to detect SELinux automatically.
westurner commentedon Oct 7, 2024
bkneis commentedon Oct 10, 2024
@westurner @haakobja Looking at the spec I can actually see it already supports the attribute
securityOptwhich devpod then passes onto the docker run - https://github.com/loft-sh/devpod/blob/main/pkg/driver/docker/docker.go#L283You should be able to add any of the security options you need there :)
westurner commentedon Oct 14, 2024
I guess that's what you get for looking at the spec; devcontainers.json
JSON Reference: https://containers.dev/implementors/json_reference/
For jupyter-docker-stacks the other day I had:
Shouldn't it be possible to omit the securityOpt label=disable and instead use
:z/:Zto relabel volumes (that cross an (selinux) context boundary) and--usernsto remap uid and gid of the [rootless] user that owns the mounted volume to the necessary uid and gid within the container?The podman run docs (
man podman-run) have an example of--userns=keep-id:uid=,gid=:https://docs.podman.io/en/latest/markdown/podman-run.1.html
Though is it better to run
--userns=auto:size=2for root and an app user?(I've fixed the email markdown formatting, which gh now mangles unfortunately).
How should
-userns=keep-id:uid=1000,gid=100be specified to get e.g. the jupyter/scipy-notebook docker stack working with Fedora 40 (and other RH linux distros like RHEL, SUSE, Rocky, Alma)?etvt commentedon Feb 16, 2025
I agree with @haakobja in suggesting that
:Zor:zshould be set automatically by DevPod if SELinux is active and the user configured DevPod as such (so it could be a new config option added to DevPod).Other developer tools and IDEs are already doing the same, see for example Jetbrains products (e.g. IntelliJ IDEA or PyCharm): https://www.jetbrains.com/help/idea/docker-containers.html#bind_mounts_selinux
This would be especially important in devcontainers (and DevPod) as some of the mounts are not under the control of the user, for example devcontainer features can add mounts themselves.
bkneis commentedon Feb 26, 2025
Should be fixed with PR from #1476