Bind mount mounted as root on Kubernetes #1942
Draft
+246
−15
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Problem
Bind mounts on Kubernetes providers were consistently owned by
root, whereas on Docker providers they are owned by theremoteUser. This inconsistency caused permission issues when accessing mounted files within the devcontainer on Kubernetes.Symptoms
mountsindevcontainer.jsonare owned byroot:rootinside the container.ls -la <mounted-dir>showsrootownership.ubuntuorvscode).Root Cause
The Kubernetes provider (unlike Docker) does not automatically map UID/GID for bind mounts. The
setupphase of the container initialization was missing a step to explicitlychownthese mounted directories to the configuredremoteUser.Solution
Explicitly change the ownership of all bind mount targets to the
remoteUserduring the container setup phase.Key Changes
Added
ChownMountsfunction inpkg/devcontainer/setup/setup.go:type=bind.chownon the target directory to match theremoteUser.chownMounts.marker) to ensure this only runs once per container initialization.Updated
SetupContainerinpkg/devcontainer/setup/setup.go:ChownMountsafter workspace initialization and before environment patching.Refactored Marker Logic:
MarkerBaseDirto allow safer testing by redirecting marker file creation to temporary directories during tests.Added Unit Test:
pkg/devcontainer/setup/setup_test.goto verify the logic ofChownMounts, ensuring it correctly identifies mounts and attempts ownership changes.Files Changed
pkg/devcontainer/setup/setup.go: Implementation ofChownMountsand integration into the setup flow.pkg/devcontainer/setup/setup_test.go: New test file for verification.