microsoft / vscode-remote-release

Visual Studio Code Remote Development: Open any folder in WSL, in a Docker container, or on a remote machine using SSH and take advantage of VS Code's full feature set.
https://aka.ms/vscode-remote
Other
3.61k stars 275 forks source link

Git repositories are reported as unsafe when opening workspaces in Dev Containers on Windows #8656

Closed JamieEdge closed 1 week ago

JamieEdge commented 1 year ago

Steps to Reproduce:

  1. Initialise a new Git repository or clone an existing repository on Windows.
  2. Open the folder in a container using the "Dev Containers: Open Folder in Container" command.
  3. Observe that the command git config --global --add safe.directory '/workspaces/<folder>' is executed in the "Dev Containers" terminal whilst starting the container for the first time.
  4. Execute the command git status within the container and observe that it exits without reporting an error.
  5. Open the Source Control panel and observe that an error is not displayed.
  6. Create and save a workspace containing the folder.
  7. Open the workspace in a container using the "Dev Containers: Open Workspace in Container" command.
  8. Observe that no command(s) to modify the safe.directory Git configuration option are executed in the "Dev Containers" terminal whilst starting the container.
  9. Execute the command git status within the container and observe that it reports an error ("fatal: detected dubious ownership in repository").
  10. Open the Source Control panel and observe that an error is displayed ("The detected git repositories are potentially unsafe as the folders are owned by someone other than the current user.").

Does this issue occur when you try this locally?: Yes Does this issue occur when you try this locally and all extensions are disabled?: Yes

This is related to https://github.com/microsoft/vscode-remote-release/issues/7628. The Git error occurs because /workspaces, and the contents within, are owned by root when using Docker Desktop for Windows, as documented in the Add a non-root user to a container section. This was fixed for the single folder use case (https://github.com/microsoft/vscode-remote-release/issues/7628#issuecomment-1406157351) but not for workspaces.

This is difficult to workaround because the safe.directory Git configuration option requires specific directories to be specified (see I cannot add the parent directory to safe.directory in Git). As a result, it's not possible to add a value such as /workspaces/<workspace>/** to trust all directories within the workspace directory.

chrmarti commented 1 year ago

We currently only check the folder at the mount point for having a .git folder and change in ownership. We should also check all workspace folders.

langestefan commented 7 months ago

Any progress on this? This is still blocking me from using git inside a dev container. It's odd that sometimes I get it to work after rebuilding a couple of times.

Clockwork-Muse commented 1 month ago

I'm hitting this even in the single-folder case. The appropriate .gitconfig entry isn't getting added, although my host config is otherwise being added.

I am trying this with the most recent pre-release devcontainers extension (0.381) error.log

chrmarti commented 1 week ago

It looks like git rev-parse --show-toplevel now also fails with this error message. We can fix that by parsing the error message.

richb-hanover commented 1 week ago

@chrmarti Thanks for looking into this. For clarity, what will we need to do in our tooling (https://github.com/microsoft/vscode-remote-release/issues/10179 and https://github.com/PRQL/prql/pull/4830) to avoid this message? Many thanks

chrmarti commented 1 week ago

@richb-hanover The fix should take care of it when using the Dev Containers extension. The Dev Containers CLI doesn't handle this case yet.