Skip to content

fix(docker): remap container UID when remote user comes from image metadata#618

Merged
skevetter merged 1 commit into
mainfrom
fix/container-uid-remap-image-metadata
Jul 7, 2026
Merged

fix(docker): remap container UID when remote user comes from image metadata#618
skevetter merged 1 commit into
mainfrom
fix/container-uid-remap-image-metadata

Conversation

@skevetter

@skevetter skevetter commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

Summary

Fixes a permission denied failure on re-up for git-clone workspaces whose remote user comes from image metadata (e.g. mcr.microsoft.com/devcontainers/* images set remoteUser: vscode).

The container UID/GID remap (UpdateContainerUserUID) gated on the raw devcontainer.json's remoteUser/containerUser. Those fields are commonly empty because the user is defined in image metadata, not the JSON. With the raw config empty, shouldUpdateUserUID returned false, the remap was skipped, and the in-container workspace chown left the bind-mounted host tree owned by the container UID (1000). On the next up, the host agent (a different UID) could no longer read the tree, reported "Couldn't find a devcontainer.json", and failed writing a default one with permission denied.

The fix passes the merged config's resolved user identity (remoteUser/containerUser/updateRemoteUserUID) to the remap on both the single-container and compose paths, so the container user is remapped to match the host user.

Changes

  • withResolvedUser helper overlays the merged user identity onto the config handed to the UID remap.
  • runContainer (single-container) and finalizeComposeContainer (compose) now use it. Compose builds the merged config before the remap so the resolved user is available.

Verification

Reproduced and fixed end-to-end on a remote ws3-ssh provider with github.com/microsoft/vscode-remote-try-python:

  • Before: run 1 succeeds, run 2 fails with permission denied writing .devcontainer.json. Confirmed identical on the pre-fix commit, so this is a pre-existing bug, not a regression.
  • After: container vscode remapped to the host UID (502), host tree owned by the host user, and runs 2 and 3 succeed with a clean git tree and no spurious default .devcontainer.json.

Summary by CodeRabbit

  • Bug Fixes
    • Fixed container user ID/GID handling so workspace permissions now reflect the resolved image and dev container user settings.
    • Improved repo re-run behavior for setups that derive the remote user from image metadata.
  • Tests
    • Added coverage for resolved user handling and for re-running a repository after initial setup.

…tadata

The container UID/GID remap gated on the raw devcontainer.json's
remoteUser/containerUser, but those commonly come from image metadata
(e.g. mcr.microsoft.com/devcontainers/* images set remoteUser=vscode).
With the raw config empty, shouldUpdateUserUID returned false, the remap
was skipped, and the in-container chown left the bind-mounted workspace
owned by the container UID (1000). On the next up the host agent (a
different UID) could no longer read the tree, reported "Couldn't find a
devcontainer.json", and failed writing a default one with permission
denied.

Pass the merged config's resolved user identity to the remap on both the
single-container and compose paths so it matches the host user.
@netlify

netlify Bot commented Jul 7, 2026

Copy link
Copy Markdown

Deploy Preview for images-devsy-sh canceled.

Name Link
🔨 Latest commit c5241ca
🔍 Latest deploy log https://app.netlify.com/projects/images-devsy-sh/deploys/6a4d8a54403b32000841c5e7

@netlify

netlify Bot commented Jul 7, 2026

Copy link
Copy Markdown

Deploy Preview for devsydev canceled.

Name Link
🔨 Latest commit c5241ca
🔍 Latest deploy log https://app.netlify.com/projects/devsydev/deploys/6a4d8a54424a3d0008cb54cf

@coderabbitai

coderabbitai Bot commented Jul 7, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: a8c830de-4b05-4189-9712-d103eb89377b

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@github-actions github-actions Bot added the size/m label Jul 7, 2026
@skevetter
skevetter marked this pull request as ready for review July 7, 2026 22:37

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
e2e/tests/up/git_repositories.go (1)

60-85: 🩺 Stability & Availability | 🔵 Trivial | ⚡ Quick win

Consider TimeoutLong() for this two-up-plus-SSH flow.

This spec runs DevsyUp twice plus an SSH round trip, which is more work than the single-up "commit hash" test that also uses TimeoutShort() (Line 42). The "pull request" checkout test, which only does a single up, already uses TimeoutLong() (Line 57). Given image pulls and container rebuilds involved in vscode-remote-try-go, TimeoutShort() here risks flakiness in CI.

⏱️ Proposed timeout adjustment
 			},
-			ginkgo.SpecTimeout(framework.TimeoutShort()),
+			ginkgo.SpecTimeout(framework.TimeoutLong()),
 		)
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@e2e/tests/up/git_repositories.go` around lines 60 - 85, The ginkgo spec in
git_repositories.go for "should re-up a repo whose remoteUser comes from image
metadata" uses TimeoutShort() even though it performs two DevsyUp calls plus an
SSH check, so it should be aligned with the heavier "pull request" flow by
switching this test case to TimeoutLong() in the ginkgo.SpecTimeout call. Locate
the spec by its description string and update the timeout near the end of that
ginkgo.It block.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@e2e/tests/up/git_repositories.go`:
- Around line 60-85: The ginkgo spec in git_repositories.go for "should re-up a
repo whose remoteUser comes from image metadata" uses TimeoutShort() even though
it performs two DevsyUp calls plus an SSH check, so it should be aligned with
the heavier "pull request" flow by switching this test case to TimeoutLong() in
the ginkgo.SpecTimeout call. Locate the spec by its description string and
update the timeout near the end of that ginkgo.It block.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 268bdbc8-8cb3-4965-8920-77833c678e5b

📥 Commits

Reviewing files that changed from the base of the PR and between 21e9ecb and b12de86.

📒 Files selected for processing (4)
  • e2e/tests/up/git_repositories.go
  • pkg/devcontainer/compose.go
  • pkg/devcontainer/single.go
  • pkg/devcontainer/single_test.go

@skevetter
skevetter enabled auto-merge (squash) July 7, 2026 22:51
@skevetter
skevetter force-pushed the fix/container-uid-remap-image-metadata branch from b12de86 to c5241ca Compare July 7, 2026 23:22
@skevetter
skevetter merged commit 70eacec into main Jul 7, 2026
70 of 75 checks passed
@skevetter
skevetter deleted the fix/container-uid-remap-image-metadata branch July 7, 2026 23:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant