Repository navigation
Description
Environment
- VSCode Version: 1.37.1
- Local OS Version: Fedora 30
- Remote OS Version: fedora 30, debian 10 (really the python 3 default container)
- Remote Extension/Connection Type: Docker
Steps to Reproduce:
- use default open-folder in container
- choose python 3 container
- docker exec in to the generated container
- ls -l /workspaces/name-of-your-project
- permission denied
You can see the same problem in the normal GUI interface but it is less obvious what is going on. You also have the same issue if you use a custom container and (probably) any other container.
Basically, as far as I can tell, the bind mount of the user's devel dir into /workspaces is not using the z or Z flag that let's it work well with SELinux. I think this will be particularly a problem as you can't set that flag using the new --mount option (see: Differences between “--mount” and “--volume” on https://docs.docker.com/engine/reference/commandline/service_create/#add-bind-mounts-or-volumes) at all.
There is a workaround that I note here for anyone running into this issue but probably not something the tool should do automatically. You can chcon your devel directory to be modifiable by docker. For example: chcon -Rt svirt_sandbox_file_t /full/path/to/your/code then reattach your devel dir to the container (probably using rebuild).
Activity
chrmarti commentedon Sep 5, 2019
You could set
"workspaceMount"tonull(or the empty string) and use"runArgs"to do the mount using--volumein thedevcontainer.json.chrmarti commentedon Oct 2, 2020
There are now also built-in ways of connecting to a Docker volume:
sclel016 commentedon May 1, 2021
What is the current recommended work around for SELinux? I'm trying to open a host workspace in a container using the dev container infrastructure built into vscode-remote. It seems that on systems with SELinux, this can only be accomplished with a bind mount and
zorZflags.Short of cloning a repository to a volume, is there a better workflow that still involves vscode-remote?
PavelSosin-320 commentedon May 2, 2021
sclel016 Those people who invented SeLinux provided a tool that gives to rootless users the same power as the root user has without compromising security - FUSE and FUSE mount Look at the contributor's list of both projects. It is an important part of Rootles Docker and Podman and comes to Linux as a dependency. Using FUSE mount implementation instead of Linux mount solves the problem.
The configuration that works perfectly for me in Podman:
graphDriverName: overlay
graphOptions:
overlay.mount_program:
Executable: /usr/bin/fuse-overlayfs
Package: fuse-overlayfs-1.5.0-1.fc33.x86_64
Version: |-
fusermount3 version: 3.9.3
fuse-overlayfs: version 1.5
FUSE library version 3.9.3
using FUSE kernel interface version 7.31
PavelSosin-320 commentedon May 2, 2021
sclel016 Docker graph driver overlayfs + fuse/overlayfs should work for you on any Linux - fuse-overlayf storage driver should work for you on any Linux
aallrd commentedon Jul 6, 2021
Hello,
I am using VSCode 1.57.1 and Podman 3.1.2.
I managed to mount my SELinux protected directory using this
runArgsconfiguration:However, I am not able to use the
${workspaceFolder}and${workspaceFolderBasename}variables in therunArgsvalues for the volume command.I am not sure if it used to worked but I remember doing something like that previously (where
${workspaceFolder}would be the folder opened with VSCode containing the .devcontainer/devcontainer.json file):It fails with this error:
Is it expected?
aallrd commentedon Jul 7, 2021
Could it be linked to #5007 ?
chrmarti commentedon Jul 9, 2021
Antoine Allard (@aallrd) Thanks for filing #5301. Tracking the missing variables support with "runArgs" there.
lovasoa commentedon Aug 12, 2021
Hello !
Has there been any news on this front ? Dev containers are currently broken on fedora.
Is there a problem with
--volume=${localWorkspaceFolder}:/workspaces/${localWorkspaceFolderBasename}:Zwhich prevents it from being enabled by default ?chrmarti commentedon Aug 13, 2021
Ophir LOJKINE (@lovasoa) Make sure to clear the
"workspaceMount":PavelSosin-320 commentedon Aug 13, 2021
langdon (@langdon) You can try it:
Neither of these versions promised 100% back compatibility.
Check to corresponding sites.
jibsaram commentedon Nov 3, 2021
I ran into this for the first time just now as I'm setting up a new environment using Fedora 35. If you're making use of one of the existing devcontainer configurations or wrote your own that makes use of a
docker-compose.ymlfile, you can achieve the same as what's mentioned above here by setting the:Zflag (a selinux specific label, apparently) on a volume defined there, like so:Hopefully a more official solution can be made available at some point. I'm not sure if an environment specific fix should exist in a repository's configuration file, as colleagues/collaborators might use very different environments, but at least for now this can hopefully help you get back to working on your project :).
15 remaining items
bradydean commentedon Dec 20, 2022
Well, I'm not really sure what happened, but my files inside the container are owned by root again, even using podman...
bradydean commentedon Dec 21, 2022
Anyways,
podman unshare chown 1000:1000 filefixed that, and that reminded me of docker desktop's file sharing options. I already had/homein there, but I removed it, then added/home/bradyand docker desktop is working now.EDIT: It worked once and only once..
EDIT2: Did some more playing around and apparently
podman unsharewill correct the perms for docker-desktopctron commentedon Mar 24, 2023
Is there a real solution now to this? The workarounds I saw all seem to require patching the devcontainer configuration. Which may work for one setup, but not for another. So as the original reported mentioned, I would expect some out-of-the-box support for this.
theonlyfoxy commentedon Apr 28, 2023
as a workaround you could set remoteUser to root.
example devcontainer.json:
{ "remoteUser": "root", "containerUser": "vscode", "workspaceMount": "", "runArgs": ["--volume=${localWorkspaceFolder}:/workspaces/${localWorkspaceFolderBasename}:Z"] }also see.
TommyTran732 commentedon Jun 8, 2023
I ran into this issue with the Docker package from the official Fedora repository. However, when I switched to using the package from the upstream docker repo, the problem goes away. There's no need to manually set the :z or :Z flag. I am not sure what has change though.
ctron commentedon Jun 20, 2023
To my understanding that simply drops the SElinux support and runs everything as root. Which might not be everyone's cup of tea.
sanmai-NL commentedon Jan 29, 2024
This does not work when your image has tooling installed specifically configured for the unprivileged user (
PATH, standard directories, etc.).geoffreysmith commentedon May 31, 2024
No I have a feeling why only containerd+ docker are used in the k8s lightweightvm + containterd. There’s a few other containers that are allowed. Basically from what I gather the eventual work around is to assume containers are run under hypervisor (visor now) ignored by demonic and have selinyx ignore all non objects and containers.
I believe there’s a system call made in docker that ignores bind/volumes and as the hypervisot intercepts all Linux calls it makes more sense to patch it then break all of docker.
Can someone direct me to a github repo they tested this on? I can trace the syscall and see if disabling apparmor seccomp in containers fixes this.
This feels like a historical docker issue that it is easier to rewrite a hypervisor then change docker.
Malix-Labs commentedon Jun 2, 2024
So what should be the default minimal addition to
.devcontainer/devcontainer.jsonfile to make Podman run on SELinux ?So far I've seen 3 versions (excluding the
:Zvariant which is basically cheating), but I don't know which is the best, and what some options really does and why do they workvscode docs
universal blue - devcontainer setup
universal blue - podman support
geoffreysmith commentedon Jun 2, 2024
Install qVisor run containers in a lightweight hypervisor set SELinux to ignore objects and just binaries. Call it a day. If the containers need to talk to each other there’s tompr or something. Dev containers are made for old school Dockers running root not anything OCI compliant.
Malix-Labs commentedon Jun 2, 2024
Comment from Geoffrey Smith (@geoffreysmith) :
qVisor would indeed be great, but I want to make everyone of the contributors of my repo to have working podman devcontainers without installing another package
For that, I apparently have to append one of the three option above
JaneSmith commentedon Sep 12, 2024
I have had a nightmare getting VS Code working with dev containers on Fedora Silverblue. I finally got it working with the following in
devcontainer.json:None of the other solutions worked for me. I don't know why they worked for others and not for me.
The above, without setting
--security-opt, let me build and enter the container. However, post-commands and anything that I actually run in the container terminal would fail. For example,lswould give me a permission error.The above wouldn't even let me build the container. I'd just get a "command failed" error with not much useful information.
Why is this still not working out of the box in 2024? This issue was opened in 2019! I thought the whole point of dev containers was that the project environment "just works", i.e. a contributor can pull a code repository and VS Code will automatically set up the environment so the contributor can get started. Obviously that doesn't work. And I find it quite strange that I have to resort to machine-specific hacks in the devcontainer.json file — I thought that file was supposed to be used for per-project settings, e.g. setting up dependencies needed for the project, not for per-machine settings (as this is a shared file for all contributors?). All very strange. Dev containers were advertised to me as a way to make things easier, but instead it's been the total opposite.
If anyone is interested in configuration for VS Code Flatpak app, I've also made the following changes successfully using Flatseal:
/tmp/(necessary for dev containers to work; not sure if there's an alternative solution)./var/home/myuser/Projects(necessary for dev containers to work; not happy about this, but it doesn't seem to work when folders are opened via Flatpak portals)./var/home/myuser/.local/bin/podman-host:ro, wherepodman-hostis this executable file provided by Distrobox to provide Podman access to the Flatpak app.All seems to work now, finally... Until I run into the next problem. But I really am not happy with machine-specific tweaks to the devcontainer.json file. That might be fine for my own projects, but what about when I want to contribute to someone else's project?
theonlyfoxy commentedon Sep 15, 2024
Check this for a clean workaround that is compatible with others project.
JaneSmith commentedon Sep 17, 2024
Thanks! Moving the
security-optsetting to the Podman wrapper script seems like a good solution.camerongreen commentedon Nov 12, 2025
I just want to reiterate as per langdon (@langdon) that if you are running selinux, such as I am on Fedora 42, a chcon will probably fix this.
Check any existing working docker containers you have with:
And you should see the selinux context in there. Take that context and apply it to your new files, something like this: