Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Git repository is owned by someone else #6683

Closed
vishalovercome opened this issue May 4, 2022 · 14 comments
Closed

Git repository is owned by someone else #6683

vishalovercome opened this issue May 4, 2022 · 14 comments
Assignees
Labels
containers Issue in vscode-remote containers info-needed Issue requires more information from poster

Comments

@vishalovercome
Copy link

  • VSCode Version: 1.66.2
  • Local OS Version: MacOS Monterey
  • Remote OS Version: Ubuntu 20.04
  • Remote Extension/Connection Type: Docker
  • Logs:

Steps to Reproduce:

  1. Use remote ssh to access remote machine
  2. Clone git repository in remote machine
  3. Open folder in container (v0.231.6)
  4. git status

Output

fatal: unsafe repository ('/workspaces' is owned by someone else)
To add an exception for this directory, call:

    git config --global --add safe.directory /workspaces

Adding this line seems to fix Source Control & Github extensions. But I never had to do this before. Additionally, I can see this in my .gitconfig file inside container:

[credential]
helper = "!f() { /root/.vscode-server/bin/dfd34e8260c270da74b5c2d86d61aee4b6d56977/node /tmp/vscode-remote-containers-731ca5ddc2028f730f3ae2e2799ae3dad0fb6ee0.js $*; }; f"

/tmp/vscode-remote-containers-731ca5ddc2028f730f3ae2e2799ae3dad0fb6ee0.js doesn't exist however.

@github-actions github-actions bot added the containers Issue in vscode-remote containers label May 4, 2022
@chrmarti
Copy link
Contributor

chrmarti commented May 5, 2022

This appears to be new Git behavior in 2.35.2: https://github.blog/2022-04-12-git-security-vulnerability-announced/

The file should exist though. Could you try reloading the VS Code window and check if a new file (with a different random id) is created?

@chrmarti chrmarti self-assigned this May 5, 2022
@chrmarti chrmarti added the info-needed Issue requires more information from poster label May 5, 2022
@vishalovercome
Copy link
Author

This appears to be new Git behavior in 2.35.2: github.blog/2022-04-12-git-security-vulnerability-announced

git --version
git version 2.17.1

The file should exist though. Could you try reloading the VS Code window and check if a new file (with a different random id) is created?

No such file exists no matter how many times I reload

@chrmarti
Copy link
Contributor

chrmarti commented May 6, 2022

Is the .git folder in /workspaces? What is the current working directory? Which user owns these folders?

Please also append the full log from after a window reload.

@vishalovercome
Copy link
Author

Is the .git folder in /workspaces? What is the current working directory? Which user owns these folders?

Yes. /workspaces. ubuntu (myself) though devcontainer is run as root, though this wasn't an issue in the past.

Please also append the full log from after a window reload.

How to do this?

@julian-poidevin
Copy link

Having the same issue here. Where can I find the full log trace so I can link it here ?

@chrmarti
Copy link
Contributor

chrmarti commented May 9, 2022

You can show the current log with F1 > Remote-Containers: Show Container Log.

@julian-poidevin
Copy link

@chrmarti Here's my log, I'm running git 2.34.2.

[77 ms] Remote-Containers 0.234.0 in VS Code 1.67.0 (57fd6d0195bb9b9d1b49f6da5db789060795de47).
[76 ms] Start: Resolving Remote
[87 ms] Setting up container for folder or workspace: /home/julian/repo/EmbeddedC/4q
[94 ms] Start: Check Docker is running
[95 ms] Start: Run: docker version --format {{.Server.APIVersion}}
[144 ms] Server API version: 1.41
[146 ms] Start: Run: docker volume ls -q
[185 ms] Start: Run: docker ps -q -a --filter label=vsch.local.folder=/home/julian/repo/EmbeddedC/4q --filter label=vsch.quality=stable
[223 ms] Start: Run: docker inspect --type container 2d86685ecb6d
[273 ms] Start: Run: /opt/visual-studio-code/code /home/julian/.vscode/extensions/ms-vscode-remote.remote-containers-0.234.0/dist/spec-node/devContainersSpecCLI.js up --user-data-folder /home/julian/.config/Code/User/globalStorage/ms-vscode-remote.remote-containers/data --container-data-folder .vscode-server/data/Machine --container-system-data-folder /var/vscode-server --workspace-folder /home/julian/repo/EmbeddedC/4q --workspace-mount-consistency cached --id-label vsch.local.folder=/home/julian/repo/EmbeddedC/4q --id-label vsch.quality=stable --log-level debug --log-format json --config /home/julian/repo/EmbeddedC/4q/.devcontainer/devcontainer.json --default-user-env-probe loginInteractiveShell --mount type=volume,source=vscode,target=/vscode,external=true --skip-post-create --update-remote-user-uid-default on --mount-workspace-git-root true
[482 ms] remote-containers 0.234.0.
[482 ms] Start: Resolving Remote
[487 ms] Start: Run: git rev-parse --show-cdup
[494 ms] Start: Run: docker ps -q -a --filter label=vsch.local.folder=/home/julian/repo/EmbeddedC/4q --filter label=vsch.quality=stable
[532 ms] Start: Run: docker inspect --type container 2d86685ecb6d
[559 ms] Start: Inspecting container
[559 ms] Start: Run: docker inspect --type container 2d86685ecb6d26f0bafc12a184965d68123d12781173a9699ca0d25812140b3e
[590 ms] Start: Run in container: /bin/sh
[593 ms] Start: Run in container: uname -m
[688 ms] x86_64
[688 ms] 
[688 ms] Start: Run in container: (cat /etc/os-release || cat /usr/lib/os-release) 2>/dev/null
[690 ms] NAME="Alpine Linux"
ID=alpine
VERSION_ID=3.15.0
PRETTY_NAME="Alpine Linux v3.15"
HOME_URL="https://alpinelinux.org/"
BUG_REPORT_URL="https://bugs.alpinelinux.org/"
[690 ms] 
[690 ms] Start: Run in container: cat /etc/passwd
[691 ms] Start: Run in container: test -f '/var/vscode-server/.patchEtcEnvironmentMarker'
[692 ms] 
[692 ms] 
[692 ms] Start: Run in container: test -f '/var/vscode-server/.patchEtcProfileMarker'
[693 ms] 
[693 ms] 
[699 ms] Start: Run: docker inspect --type container 2d86685ecb6d26f0bafc12a184965d68123d12781173a9699ca0d25812140b3e
[728 ms] Start: Run: /opt/visual-studio-code/code /home/julian/.vscode/extensions/ms-vscode-remote.remote-containers-0.234.0/dist/spec-node/devContainersSpecCLI.js read-configuration --workspace-folder /home/julian/repo/EmbeddedC/4q --log-level debug --log-format json --config /home/julian/repo/EmbeddedC/4q/.devcontainer/devcontainer.json --mount-workspace-git-root true
[934 ms] remote-containers 0.234.0.
[934 ms] Start: Run: git rev-parse --show-cdup
[945 ms] Start: Inspecting container
[946 ms] Start: Run: docker inspect --type container 2d86685ecb6d26f0bafc12a184965d68123d12781173a9699ca0d25812140b3e
[981 ms] Start: Run in container: /bin/sh
[987 ms] Start: Run in container: uname -m
[1094 ms] x86_64
[1094 ms] 
[1095 ms] Start: Run in container: (cat /etc/os-release || cat /usr/lib/os-release) 2>/dev/null
[1096 ms] NAME="Alpine Linux"
ID=alpine
VERSION_ID=3.15.0
PRETTY_NAME="Alpine Linux v3.15"
HOME_URL="https://alpinelinux.org/"
BUG_REPORT_URL="https://bugs.alpinelinux.org/"
[1096 ms] 
[1097 ms] Start: Run in container: cat /etc/passwd
[1105 ms] Start: Setup shutdown monitor
[1106 ms] Forking shutdown monitor: /home/julian/.vscode/extensions/ms-vscode-remote.remote-containers-0.234.0/dist/shutdown/shutdownMonitorProcess /run/user/1000/vscode-remote-containers-488995777c4a50c06f44d9606df53b0dd612ce65.sock singleContainer Debug /home/julian/.config/Code/logs/20220509T143516/exthost1/ms-vscode-remote.remote-containers 1652107634734
[1112 ms] Start: Run in container: test -d /root/.vscode-server
[1115 ms] 
[1115 ms] 
[1117 ms] Start: Run in container: test ! -f '/root/.vscode-server/data/Machine/.writeMachineSettingsMarker' && set -o noclobber && mkdir -p '/root/.vscode-server/data/Machine' && { > '/root/.vscode-server/data/Machine/.writeMachineSettingsMarker' ; } 2> /dev/null
[1118 ms] 
[1119 ms] 
[1119 ms] Exit code 1
[1120 ms] Start: Run in container: cat /root/.vscode-server/data/Machine/settings.json
[1122 ms] 
[1123 ms] cat: can't open '/root/.vscode-server/data/Machine/settings.json': No such file or directory
[1123 ms] Exit code 1
[1124 ms] 
Support for Alpine Linux is in preview.

[1125 ms] Start: Run in container: test -d /root/.vscode-server/bin/57fd6d0195bb9b9d1b49f6da5db789060795de47
[1127 ms] 
[1127 ms] 
[1127 ms] Start: Run in container: test -d /vscode/vscode-server/bin/linux-alpine/57fd6d0195bb9b9d1b49f6da5db789060795de47
[1128 ms] 
[1128 ms] 
[1129 ms] Start: Run in container: touch '/vscode/vscode-server/bin/linux-alpine/57fd6d0195bb9b9d1b49f6da5db789060795de47'
[1129 ms] Start: Launching Remote-Containers helper.
[1130 ms] ssh-agent: SSH_AUTH_SOCK in container (/tmp/vscode-ssh-auth-d8029642a82b8c4609319691951157654c82cb55.sock) forwarded to local host (/run/user/1000/keyring/ssh).
[1131 ms] Start: Run: gpgconf --list-dir agent-extra-socket
[1141 ms] 
[1141 ms] 
[1147 ms] /run/user/1000/gnupg/S.gpg-agent.extra
[1148 ms] 
[1148 ms] Start: Run in container: gpgconf --list-dir agent-socket
[1150 ms] 
[1150 ms] /bin/sh: gpgconf: not found
[1150 ms] Exit code 127
[1152 ms] Start: Run in container: /bin/sh
[1157 ms] userEnvProbe: loginInteractiveShell (default)
[1158 ms] Start: Run in container: echo ~
[1158 ms] userEnvProbe shell: /bin/ash
[1158 ms] Start: Run in container: command -v git >/dev/null 2>&1 && git config --system --replace-all credential.helper '!f() { /root/.vscode-server/bin/57fd6d0195bb9b9d1b49f6da5db789060795de47/node /tmp/vscode-remote-containers-d8029642a82b8c4609319691951157654c82cb55.js $*; }; f' || true
[1162 ms] 
[1163 ms] 
[1165 ms] Start: Run in container: for pid in `cd /proc && ls -d [0-9]*`; do { echo $pid ; readlink /proc/$pid/cwd ; readlink /proc/$pid/ns/mnt ; cat /proc/$pid/stat | tr "
[1231 ms] Extension host agent is already running.
[1232 ms] Start: Run in container: cat '/root/.vscode-server/data/Machine/.devport-57fd6d0195bb9b9d1b49f6da5db789060795de47' 2>/dev/null
[1235 ms] 34805
[1236 ms] 
[1236 ms] Start: Run in container: cat '/root/.vscode-server/data/Machine/.connection-token-57fd6d0195bb9b9d1b49f6da5db789060795de47'
[1251 ms] 3ef5b780-1823-433c-be70-a3b1546233db
[1251 ms] 
[1251 ms] Port forwarding for container port 34805 starts listening on local port.
[1252 ms] Port forwarding local port 34805 to container port 34805
[1253 ms] Start: Run in container: # Test for /root/.gitconfig and git
[1253 ms] /root/.gitconfig exists
[1253 ms] 
[1253 ms] Exit code 1
[1254 ms] Start: Run in container: command -v git >/dev/null 2>&1 && git config --global --replace-all credential.helper '!f() { /root/.vscode-server/bin/57fd6d0195bb9b9d1b49f6da5db789060795de47/node /tmp/vscode-remote-containers-d8029642a82b8c4609319691951157654c82cb55.js $*; }; f' || true
[1255 ms] 
[1256 ms] 
[1277 ms] /root
[1277 ms] 
[1278 ms] Start: Run in container: cat <<'EOF-/tmp/vscode-remote-containers-d8029642a82b8c4609319691951157654c82cb55.js' >/tmp/vscode-remote-containers-d8029642a82b8c4609319691951157654c82cb55.js
[1282 ms] 
[1282 ms] 
[1283 ms] Start: Run in container: cat <<'EOF-/tmp/vscode-remote-containers-server-d8029642a82b8c4609319691951157654c82cb55.js' >/tmp/vscode-remote-containers-server-d8029642a82b8c4609319691951157654c82cb55.js_1652107636016
[1287 ms] 
[1290 ms] 
[1429 ms] userEnvProbe PATHs:
Probe:     '/toolchain/gcc-arm-none-eabi-10.3-2021.10/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin'
Container: '/toolchain/gcc-arm-none-eabi-10.3-2021.10/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin'
[1454 ms] Port forwarding connection from 52360 > 34805 > 34805 in the container.
[1454 ms] Start: Run in container: /root/.vscode-server/bin/57fd6d0195bb9b9d1b49f6da5db789060795de47/node -e 
[1666 ms] Port forwarding 52360 > 34805 > 34805 stderr: Connection established
[1686 ms] Port forwarding connection from 52364 > 34805 > 34805 in the container.
[1686 ms] Start: Run in container: /root/.vscode-server/bin/57fd6d0195bb9b9d1b49f6da5db789060795de47/node -e 
[1897 ms] Port forwarding 52364 > 34805 > 34805 stderr: Connection established
[4572 ms] Start: Run in container: cat /proc/711/environ
[4578 ms] Start: Run in container: rm '/tmp/vscode-remote-containers-ipc-f14e26ae6cafba7effb631d3b4a38ab2850d6897.sock' && ln -s '/tmp/vscode-remote-containers-ipc-d8029642a82b8c4609319691951157654c82cb55.sock' '/tmp/vscode-remote-containers-ipc-f14e26ae6cafba7effb631d3b4a38ab2850d6897.sock'
[4583 ms] 
[4583 ms] 
[4584 ms] Start: Run in container: rm '/tmp/vscode-ssh-auth-f14e26ae6cafba7effb631d3b4a38ab2850d6897.sock' && ln -s '/tmp/vscode-ssh-auth-d8029642a82b8c4609319691951157654c82cb55.sock' '/tmp/vscode-ssh-auth-f14e26ae6cafba7effb631d3b4a38ab2850d6897.sock'
[4591 ms] 
[4592 ms] 

When running git status I'm having the following error :

2d86685ecb6d:/workspaces/4q# git status
fatal: unsafe repository ('/workspaces/4q' is owned by someone else)
To add an exception for this directory, call:

        git config --global --add safe.directory /workspaces/4q
2d86685ecb6d:/workspaces/4q# 

@chrmarti
Copy link
Contributor

@julian-poidevin You seem to be running on a Linux host or WSL, correct? It looks like Git doesn't like the fact that you are root in the container and the files are owned by the local user's UID:GID. When you add a regular user to the container (in the Dockerfile) and specify that as the "remoteUser" in the devcontainer.json the extension will attempt to update the container user's UID:GID to those of the local user (this only works when these UID:GID are not already used in the container).

@julian-poidevin
Copy link

@julian-poidevin You seem to be running on a Linux host or WSL, correct? It looks like Git doesn't like the fact that you are root in the container and the files are owned by the local user's UID:GID. When you add a regular user to the container (in the Dockerfile) and specify that as the "remoteUser" in the devcontainer.json the extension will attempt to update the container user's UID:GID to those of the local user (this only works when these UID:GID are not already used in the container).

Yes I'm under ArchLinux. Your recommandations fixed my issue.

I added support for the common-alpine.sh script provided here, passing ARG USERNAME=vscode to the script and added this : "remoteUser": "vscode" setting in my devcontainer.json file and it fixed my issue.

Thanks a lot !

@vishalovercome I suggest you try the same.

@julian-poidevin
Copy link

@chrmarti Getting back to you on this issue.

For some reasons, I need to connect to the container as root.
Any way to get git working without using the remoteUser setting ?

@chrmarti
Copy link
Contributor

Adding the workspace as a "safe.directory" as Git suggests might help. Or you could use chown -R root:root . in the devcontainer.json's "postCreateCommand" to make root own everything. Note that this will also change the ownership on the host OS.

@github-actions
Copy link

This issue has been closed automatically because it needs more information and has not had recent activity. See also our issue reporting guidelines.

Happy Coding!

@amasciotta
Copy link

I'm facing the same issue: I'm trying to develop my application inside a custom container. My host OS is Ubuntu 20.04, with VS Code 1.68. The container is based on Ubuntu 20.04. The default user inside the container is root (which seems to be the default choice for many containers these days), while the user which runs VS Code on the host is another one.

After starting the container, any git command inside the repo returns the following error:

fatal: unsafe repository ('/workspaces/repo' is owned by someone else)
To add an exception for this directory, call:

        git config --global --add safe.directory /workspaces/repo

Adding the suggested exception fixes the problem, so I tried to automate this step by adding the git config command to the postCreateCommand setting of my .devcontainer.json file, like so

"postCreateCommand": "git config --global --add safe.directory /workspaces/repo"

This fixes problem, as expected, but breaks another thing: now git has lost the username and the email, and prompts me to add them.

After some investigation, I discovered that VS Code copies the global .gitconfig file from the host to the container at startup, and I also verified that adding the git config command to the postCreateCommand setting of my .devcontainer.json file breaks this step: if I do not add the postCreateCommand, the ~/.gitconfig file of the container looks like this

[credential]
        helper = "!f() { /root/.vscode-server/bin/4af164ea3a06f701fe3e89a2bcbb421d2026b68f/node /tmp/vscode-remote-containers-a323d0b4fefdea4944f81fafafe2e16c2c11bc07.js $*; }; f"
        credentialStore = secretservice
[user]
        email = <my email>
        name = <my name>
[credential "https://dev.azure.com"]
        useHttpPath = true
[filter "lfs"]
        clean = git-lfs clean -- %f
        smudge = git-lfs smudge -- %f
        process = git-lfs filter-process
        required = true
[http]
        version = HTTP/1.1

while if I add the postCreateCommand, the ~/.gitconfig file looks like this

[safe]
        directory = /workspaces/space
[credential]
        helper = "!f() { /root/.vscode-server/bin/4af164ea3a06f701fe3e89a2bcbb421d2026b68f/node /tmp/vscode-remote-containers-fc8de4f9109022f098c7c51d24cbb4b87b6fcb21.js $*; }; f"

By exploring the container log I found that my custom command is executed before the copy of the .gitconfig file, which then fails because of this

[6225 ms] Start: Run in container: # Test for /root/.gitconfig and git
[6226 ms] /root/.gitconfig exists
[6226 ms] 
[6226 ms] Exit code 1

Any help?

@julian-poidevin
Copy link

Hi @amasciotta, I had similar issues. What did the trick for me was :

add this line to .devcontainer.json : This avoid logging in the environnement as root

"remoteUser": "vscode",

Same as you, I added the following postCreateCommand :

"postCreateCommand": "git config --global --add safe.directory /workspaces/repo"

Finally, I had to setup my git information locally (outside of the container) by running :

$ git config user.name "John Doe"
$ git config user.email [email protected].

Make sure to avoid putting the --global flag. This way, your local (and not global) git config (located in .\.git\config in your repo) gets populated and copied into the docker environment.

@github-actions github-actions bot locked and limited conversation to collaborators Jul 8, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
containers Issue in vscode-remote containers info-needed Issue requires more information from poster
Projects
None yet
Development

No branches or pull requests

4 participants