You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
git urls are incorrectly transformed from relative to absolute (unable to clone git repo from server when the repo is relative to the git user's home dir)
#4322
Closed
alexcb opened this issue
Oct 11, 2023
· 3 comments
· Fixed by #4326
#4142 introduced a regression, which makes it impossible to access a git repo from a ssh server that is configured to store the hosted git repos out of a user's home directory.
Here's a reproduction case:
First setup a git repo on a server:
$ ssh alex@192.168.0.2
Welcome to Ubuntu 21.04 (GNU/Linux 5.11.0-1027-raspi aarch64)
...
alex@coho:~$ mkdir repo.git
alex@coho:~$ cd repo.git
alex@coho:~/repo.git$ git init --bare .
...
Initialized empty Git repository in /home/alex/repo.git/
alex@coho:~/repo.git$ exit
logout
Connection to 192.168.0.2 closed.
Then add something to it:
alex@surfperch:/tmp$ git clone alex@192.168.0.2:repo.git
Cloning into 'repo'...
warning: You appear to have cloned an empty repository.
alex@surfperch:/tmp$ cd repo/
alex@surfperch:/tmp/repo$ echo -e "FROM alpine\nRUN echo hello"
FROM alpine
RUN echo hello
alex@surfperch:/tmp/repo$ echo -e "FROM alpine\nRUN echo hello" > Dockerfile
alex@surfperch:/tmp/repo$ git add Dockerfile
alex@surfperch:/tmp/repo$ git commit -m 'my initial commit'
[master (root-commit) b696fd5] my initial commit
Author: Alex Couture-Beil <alex@earthly.dev>
1 file changed, 2 insertions(+)
create mode 100644 Dockerfile
alex@surfperch:/tmp/repo$ git push
Enumerating objects: 3, done.
Counting objects: 100% (3/3), done.
Writing objects: 100% (3/3), 773 bytes | 773.00 KiB/s, done.
Total 3 (delta 0), reused 0 (delta 0), pack-reused 0
To 192.168.0.2:repo.git
* [new branch] master -> master
This works under docker (which might be an older copy without #4142)
However when I use the latest version of buildkit (which includes #4142), it fails:
$ sudo -E ./buildctl build --ssh=default --frontend=dockerfile.v0 --opt source=docker/dockerfile --opt context=alex@192.168.0.2:repo.git
[+] Building 3.1s (1/1) FINISHED
=> ERROR [internal] load git source alex@192.168.0.2:repo.git 3.0s
------
> [internal] load git source alex@192.168.0.2:repo.git:
2.991 fatal: '/repo.git' does not appear to be a git repository
2.993 fatal: Could not read from remote repository.
2.993
2.993 Please make sure you have the correct access rights
2.993 and the repository exists.
------
error: failed to solve: failed to read dockerfile: failed to load cache key: error fetching default branch for repository ssh://xxxxx@192.168.0.2/repo.git: git error: exit status 128
stderr:
fatal: '/repo.git' does not appear to be a git repository
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
This is because buildkit has incorrectly transformed alex@192.168.0.2:repo.git into ssh://alex@192.168.0.2/repo.git.
These two git URLs are not the same, the former is relative to my home director, and the later is absolute to the / filesystem.
The text was updated successfully, but these errors were encountered:
you can embed a ~ in the ssh:// form, which would then allow you to use a custom port:
e.g. this works on my server (Ubuntu with OpenSSH)
git clone ssh://alex@192.168.0.2:22/~/repo.git
unfortunately you can't assume all git hosts (e.g. github), support repos with a path like that.
e.g. this does not work:
$ git clone ssh://git@github.com:22/~/moby/buildkit.git
Cloning into 'buildkit'...
fatal: remote error:
is not a valid repository name
Visit https://support.github.com/ for help
Ultimately if a user gives you an implicit git url, I think it needs to kept in it's implicit form.
#4142 introduced a regression, which makes it impossible to access a git repo from a ssh server that is configured to store the hosted git repos out of a user's home directory.
Here's a reproduction case:
First setup a git repo on a server:
Then add something to it:
This works under docker (which might be an older copy without #4142)
However when I use the latest version of buildkit (which includes #4142), it fails:
This is because buildkit has incorrectly transformed
alex@192.168.0.2:repo.git
intossh://alex@192.168.0.2/repo.git
.These two git URLs are not the same, the former is relative to my home director, and the later is absolute to the
/
filesystem.The text was updated successfully, but these errors were encountered: