Skip to content

Support devcontainers on Linux hosts using SELinux #1283

Closed as duplicate

Description

@haakobja

What happened?
Unable to access mounted workspace directory due to SELinux permissions

What did you expect to happen instead?
Use workspace directory as expected

How can we reproduce the bug?

  • Log on a linux distribution using SELinux
  • Use DevPod to create and start new devcontainer
  • SSH into the contiainer
  • touch /workspaces//test

My devcontainer.json: none (cloned a fresh git repo)

Local Environment:

  • DevPod Version: 0.5.20
  • Operating System: linux (Fedora 41)
  • ARCH of the OS: AMD64

DevPod Provider:

  • Local/remote provider: docker

Anything else we need to know?
I use Podman and its Docker compatibility mode.

There are three workarounds for this:

  1. Set SELinux as permissive (I've not tried this)
  2. Append :Z in .devcontainer.json as described in Fedora Silverblue + podman + DevPod does not work #970 (comment), but this is not viable if the devcontainer is used by others
  3. When using Podman: Add label=false to [container] in $HOME/.config/containers/containers.conf

I think :Z or :z (private or shared SELinux context) or label=false should be set by DevPod.

Activity

  1. haakobja commented on Oct 4, 2024

    @haakobja
    Author

    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

  2. westurner commented on Oct 4, 2024

    @westurner
  3. bkneis commented on Oct 7, 2024

    @bkneis
    Contributor

    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?

  4. haakobja commented on Oct 7, 2024

    @haakobja
    Author

    @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.

  5. westurner commented on Oct 7, 2024

    @westurner
  6. bkneis commented on Oct 10, 2024

    @bkneis
    Contributor

    @westurner @haakobja Looking at the spec I can actually see it already supports the attribute securityOpt which devpod then passes onto the docker run - https://github.com/loft-sh/devpod/blob/main/pkg/driver/docker/docker.go#L283

    You should be able to add any of the security options you need there :)

  7. westurner commented on Oct 14, 2024

    @westurner

    I guess that's what you get for looking at the spec; devcontainers.json
    JSON Reference: https://containers.dev/implementors/json_reference/

    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:

    "securityOpt": [ "seccomp=unconfined" ]
    

    For jupyter-docker-stacks the other day I had:

     --security-opt label=disable --userns=keep-id:uid=1000,gid=100
    

    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?

    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=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)?

  8. etvt commented on Feb 16, 2025

    @etvt

    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).

    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.

  9. bkneis commented on Feb 26, 2025

    @bkneis
    Contributor

    Should be fixed with PR from #1476

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions