Skip to content

Support for SELinux #1476

Closed
Closed

Description

@acolombier

Is your feature request related to a problem?

Yes - when running devpod with a docker-compatible executable (such as podman) using SELinux, the container gets permission denied on the mounted workspace folder

Which solution do you suggest?

It looks like adding the Z flag is enough to make it work:

diff --git a/pkg/docker/helper.go b/pkg/docker/helper.go
index 4adf4ff6..26f60ada 100644
--- a/pkg/docker/helper.go
+++ b/pkg/docker/helper.go
@@ -65,6 +65,15 @@ func (r *DockerHelper) GPUSupportEnabled() (bool, error) {
        return strings.Contains(string(out), "nvidia-container-runtime"), nil
 }
 
+func (r *DockerHelper) SELinuxEnabled(ctx context.Context) (bool, error) {
+       out, err := r.buildCmd(ctx, "info", "-f", "{{.Host.Security.SELinuxEnabled}}").Output()
+       if err != nil {
+               return false, command.WrapCommandError(out, err)
+       }
+
+       return strings.Contains(string(out), "true"), nil
+}
+
 func (r *DockerHelper) FindDevContainer(ctx context.Context, labels []string) (*config.ContainerDetails, error) {
        containers, err := r.FindContainer(ctx, labels)
        if err != nil {
diff --git a/pkg/driver/docker/docker.go b/pkg/driver/docker/docker.go
index c9b00db2..b27a3ea9 100644
--- a/pkg/driver/docker/docker.go
+++ b/pkg/driver/docker/docker.go
@@ -272,6 +272,12 @@ func (d *dockerDriver) RunDockerDevContainer(
                        mountPath = strings.Replace(mountPath, ",consistency='consistent'", "", 1)
                }
 
+               if ok, err := helper.SELinuxEnabled(ctx); ok && err == nil {
+                       mountPath = fmt.Sprintf("%s,z", mountPath)
+               } else if err != nil {
+                       d.Log.Infof("Unable to check if docker is running with SELinux. Assuming it is not.")
+               }
+
                args = append(args, "--mount", mountPath)
        }
 

Let me know if you would like me to submit a PR

Which alternative solutions exist?

N/A

Additional context

Using the main version of devpod, using with podman on Fedore 41 SilverBlue

Activity

  1. bkneis commented on Dec 16, 2024

    @bkneis
    Contributor

    Thanks for reporting @acolombier! Currently we have this workaround documented on our website - https://devpod.sh/docs/troubleshooting/linux-troubleshooting#using-selinux

    As you mentioned adding the Z is needed to allow the runtime to mount the volume. We opted to not automatically add this as we would need to detect SELinux and add the flag which is potentially not desired behaviour for other users.

    Let me know if you have any specific ideas though about this or how it could be supported

  2. acolombier commented on Dec 16, 2024

    @acolombier
    ContributorAuthor

    which is potentially not desired behaviour for other users.

    Yes that makes sense. Could we consider adding an option similar to SSH_ADD_PRIVATE_KEYS to be used in tandem with DockerHelper.SELinuxEnabled? The rational being, devpod offers the great feature of working directly off a git repo, but the workaround require changing the devcontainer spec prior to running it.
    As I mentioned in the initial report, in case this is something you would be okay to see in devpod, I'd be happy to submit my contribution!

  3. bkneis commented on Dec 16, 2024

    @bkneis
    Contributor

    Hi @acolombier yes that would work! As long as we can toggle this functionality with a CLI flag then it would be great if you could submit a PR with your changes :) I think adding --disable-selinux-flag to the up command would suffice.

  4. bkneis commented on Jan 7, 2025

    @bkneis
    Contributor

    @acolombier did you manage to get around adding the context option? If not please feel free to open a PR with your current changes and I can add the rest :)

  5. acolombier commented on Jan 8, 2025

    @acolombier
    ContributorAuthor

    Apologies for the delay here @bkneis, I'm still planing to do it, just hadn't the time lately! Hoping to get that done this month! I will ping you if I need your help to complete the work :)

  6. github-actions commented on Mar 10, 2025

    @github-actions

    This issue is stale because it has been open for 60 days with no activity.

  7. github-actions commented on Apr 9, 2025

    @github-actions

    This issue was closed because it has been inactive for 30 days since being marked as stale.

  8. gadgethm commented on May 13, 2025

    @gadgethm

    @bkneis Should this have been closed automatically? Issue is still present.

    I also noticed that the website's solution causes an extra folder called /workspaces/${localWorkspaceFolderBasename} to appear (with that exact spelling) inside the container.

  9. added a commit that references this issue on Oct 26, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions