Skip to content

Visual Studio Code Dev Containers file permissions #8278

Closed
@jdh80

Description

@jdh80

While running dev containers in this configuration:

Following these steps:

  1. Starting a container of my own
  2. Asking VSCode to create a dev container
  3. Stopping the container in step 1
  4. Asking VSCode to rebuild without cache the dev container

We receive the following error:

Failed to save 'test.txt': Unable to write file 'vscode-remote://dev-container+7b22686f737...65227d7d/workspaces/eci-test/test.txt' (NoPermissions (FileSystemError): Error: EACCES: permission denied, open '/workspaces/eci-test/test.txt')

After investigation, it is determined that this error occurs due to a limitation of Windows WSL, as it does not occur on Hyper-V or Mac/Linux. The 9p filesystem has a limitation where it does not yet support idmapping, which would allow the files to show up with proper ownership inside the ECI-backed container. Because of this, files show up as nobody:nogroup when rebuilding the dev container without cache.

This is the recommended workaround and it works for files created via the command line and the UI:

Place this Dockerfile inside the .devcontainer dir in the workspace:

/bin/new-sh && \ chmod 755 /bin/new-sh && \ mv /bin/new-sh /bin/sh # Append umask configuration to relevant shell profiles RUN for f in /etc/profile ~/.profile ~/.bashrc ~/.zshrc; do \ [ -f "$f" ] && echo -e '\n# Set umask to allow 0777 permissions\numask 000\n' >> "$f"; \ done">
# NOTE: Replace with desired dev container image
FROM [mcr.microsoft.com/devcontainers/javascript-node:1-18-bullseye](https://mcr.microsoft.com/devcontainers/javascript-node:1-18-bullseye)

# Substitute /bin/sh with /bin/bash (because we need it to read the umask from /etc/profile)
RUN echo '#!/bin/bash\nexec /bin/bash "$@"' > /bin/new-sh && \
    chmod 755 /bin/new-sh && \
    mv /bin/new-sh /bin/sh

# Append umask configuration to relevant shell profiles
RUN for f in /etc/profile ~/.profile ~/.bashrc ~/.zshrc; do \
        [ -f "$f" ] && echo -e '\n# Set umask to allow 0777 permissions\numask 000\n' >> "$f"; \
    done

Then configure the devcontainer.json file in that same directory as follows:

    // Comment out the base image; we will use a Dockerfile instead.
    //"image": "[mcr.microsoft.com/devcontainers/javascript-node:1-18-bullseye](https://mcr.microsoft.com/devcontainers/javascript-node:1-18-bullseye)",
	
    "build": {
        "dockerfile": "Dockerfile",
        "context": "."
    },
	
    // This tells VSCode to set the BASH_ENV=/etc/profile variable in "docker exec" commands it issues; it's 
    // needed so that when VSCode starts the code-server inside the dev-container, the server picks up the
    // modified umask in /etc/profile. This ensures files created via the VSCode UI pick up the umask.
	"containerEnv": { "BASH_ENV": "/etc/profile" },

Since this is a Windows host using WSL, the workspace is mounted from the Windows C:\ drive so all files show up with 0777 permissions anyway because Windows does not have the same file permission framework as Linux where running this would make all new files accessible to everyone.

We would like the documentation updated to reflect the above findings and look forward to 9p supporting idmapping in the future.

Cheers,

Docker Support

Metadata

Metadata

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions