-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Unable to clone repositories in Windows Containers #1403
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
Comments
So. upon doing some more digging, it looks like the issue is to do with
Unfortunately, as part of my container automation, I'm faced with some difficulties in resolving this correctly. My initial instinct was to add this to my
Which gives me this error message during my container build:
So now I'm left trying to figure out what about being run in a container build seems to be upsetting the SSH tools bundled with git for Windows. I'm also a bit frustrated that I've had no error feedback at any step along the way. If I try to run it via
|
Not that I claim to know how to resolve this properly, but maybe you want to imitate what I do in my VSTS jobs: mkdir -p .ssh &&
echo 'github.com,192.30.252.128 ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAq2A7hRGmdnm9tUDbO9IDSwBK6TbQa+PXYPCPy6rbTrTtw7PHkccKrpp0yVhp5HdEIcKr6pLlVDBfOLX9QUsyCOV0wzfjIJNlGEYsdlLJizHhbn2mUjvSAHQqZETYP81eFzLQNnPHt4EVVUh7VfDESU84KezmD5QlWpXLmvU31/yMf+Se8xhHTvKSCZIFImWwoG6mbUoWf9nzpIoaSjB+weqqUUmpaaasXVal72J+UX2B+2RPW3RcT0eOzQgqlJL3RKrTJvdsjE3JEAvGq3lGHSZXy28G3skua2SmVi/w4yCE6gbODqnTWlg7+wC604ydGXA8VJiS5ap43JXiUFFAaQ==' >>.ssh/known_hosts Sure, this would fail if the host key changed. But that's exactly what I would want it to do: to fail, so that I can figure out whether it was really GitHub that changed the key, or whether it was my cute buddy playin' a trick on me. |
@dscho - Indeed, I think I'm going to have to do something like that in the interim. It would be nice if I could have my Thanks for the snippet, I'll probably end up using it until this can be fixed properly. |
Two part solution... Part 1FROM microsoft/windowsservercore:1709 ENV OPENSSH_VERSION 0.0.24.0 RUN powershell -Command RUN setx PATH %PATH%;c:\OpenSSH-Win64 Part 2FROM openssh RUN mkdir C:\Users\ContainerAdministrator\.ssh |
@taylorb-microsoft After installing openssh and adding the server's key to the known_hosts file (tested by successfully opening an ssh session on the Bitbucket server), I copied my Bitbucket ssh key to Running
but still cloning does not work:
I'm curious if there are additional steps required to get this to work? Have you actually been able to successfully clone a Git repo in a Windows container? |
Yes ;-) Almost all of Git for Windows' continuous testing and integration is performed in Docker containers itself. BTW did you To diagnose your woes further, I would suggest running |
Is there an add-in that brings this command to powershell? Otherwise I don't seem to have Thanks for the |
Thanks for the assistance, using that verbose flag helped pinpoint the issue: I was using a
|
@atrauzzi can this ticket be closed? |
I'm having a similar problem but I haven't been able to pinpoint the problem yet. I just started looking into this and I don't seem to have the same Bad permissions error message. I do however have multiple errors like this: Did you use git clone without ssh private/public keys? And what user where you able to run the clone commands with? @atrauzzi @Sean-Brown |
Scratch what I said above, with |
The |
I've been experimenting with this in a container and I thought I had it working but now I'm unable to reproduce the container -- I am always getting git clone failures, which is confusing because I thought I was doing the same procedure but now it doesn't work and |
Ok I did some more digging and found another issue but also a workaround. It seems like git is calling the version of SSH it installed vs OpenSSH. Below is a complete dockerfile the installs git and OpenSSH. It also registers the ssh services, sets the ssh-agent service to auto start and does the hack of copying the OpenSSH binaries over the top of the git installed version :/. After all this here's the test I was able to successfully complete:
Dockerfile:
|
Oh I didn't know that, btw it looks like there is a git environment variable for telling it which ssh.exe to use, in powershell it'd be something like: |
OK I tried over-writing the ssh executables like you said and I was able to clone the repo, however getting submodules is somehow broken, i.e. running UPDATE: I recreated the container, but this time setting |
I wasn't getting GIT_SSH working either, I suspect but I'm not positive that while GIT_SSH points to ssh.exe but there are other binaries that might be in conflict... I'm not sure why git submodule isn't working, though I suspect its similar to the root problem of ssh (something to do with msys). |
@taylorb-microsoft your hack fix worked for me aswell. |
I believe the issue with |
There is likely some
I fear that it does not do that. The helper only handles one submodule at a time. The recursion is what the As I suggested earlier, if you have problems with shell scripts in Docker containers, maybe using the -BusyBox variant of MinGit helps? (You only need MinGit, anyway, as you do not plan on using fancy UIs in Docker, right?) |
I just realized that I suggested this not only earlier, but elsewhere. So please let me clarify: MinGit is a subset of Git for Windows, intended for applications. All purely interactive commands have been stripped, and also MinGit is released simultaneously with every Git for Windows version. There is a new, experimental kid on the block: BusyBox-based MinGit. It not only shrinks size, but it also avoids the Cygwin derivative MSYS2 in many cases (although not for OpenSSH). The BusyBox component has still not seen any serious battle testing, that is the entire reason why MinGit still uses MSYS2. The BusyBox based MinGit can be found here: https://github.com/git-for-windows/git/releases/download/v2.15.1.windows.2/MinGit-2.15.1.2-busybox-64-bit.zip Your Furthermore, MinGit (both the regular variant as well as the BusyBox one) are distributed as plain .zip files, so it should be super easy to extract via Powershell: $WebClient = New-Object System.Net.WebClient; $WebClient.DownloadFile("https://github.com/git-for-windows/git/releases/download/v2.15.1.windows.2/MinGit-2.15.1.2-64-bit.zip", "MinGit-2.15.1.2-64-bit.zip")
mkdir MinGit | Out-Null
Add-Type -AssemblyName System.IO.Compression.FileSystem ; [System.IO.Compression.ZipFile]::ExtractToDirectory("MinGit-2.15.1.2-64-bit.zip", "MinGit") |
@dscho it looks like sh (or really bash.exe) is AV'ing (it's producing a memory dump with an AV is msys someplace)… I created a dockerfile combining OpenSSH and MinGit - I was able to clone the repro still and preform basic commands. git submodule is at least returning output with -? so it might work.
|
So you're saying this fixes the described issues in your setup? If so: great! |
I'll give BusyBox MinGit a shot, if it works I'll favor it over my hack using
UPDATE: BusyBox MinGit works perfectly :) Thanks for your assistance on this issue, it was driving me crazy, glad to get it resolved |
Thanks for your feedback! I will try to set aside time (hopefully in the next sprint) to try to get BusyBox-based MinGit further along. |
My problem now is that I'm trying to use the machine as a Jenkins slave. It works perfectly fine if I add the ssh keys to the image manually but if I try to pass the keys from the master the build will fail because of the OpenSSH permission problems on windows. Doesn't sound like using mingit would help either since it's using the same version of ssh as the regular git installation. Git was last updated in chocolatey November 30th and atrauzzi mentioned that cloning has worked previously, I wonder if using Git 2.15.0 instead of Git 2.15.1.2 would work. I'm going to try that next. edit: Cloning does not work with 2.15.0 |
This line |
@taylorb-microsoft That doesn't help since Jenkins generates the key files on demand into temporary folders. I also can't add that to any running builds because cloning happens (and fails) before anything else. I'm reverting to https for now because I don't want to bake the ssh perm files into the docker images. But the solution did work perfectly fine when I tried that. |
@Custodia do you have any control over where the keys are placed? i.e. we might be able to fix this via the right inheritance settings on the root directory. |
The keys are stored in |
Old issue but I stumbled across it and it helped me end up with this docker file. It uses a supplied .ssh folder instead of generating a key:
|
I struggled with this for a while as well. I used the above comments to install OpenSSH into my windows image but it still didn't work. From another post I found that there is an environment variable, GIT_SSH, which tells git where ssh.exe is. Once I set that, everything worked great. So I added this to my dockerfile:
|
I'll simply interpret the latest comment as the workaround everybody was waiting for. |
Cross posting from here: microsoft/dotnet-framework-docker#61
Not sure what happened, but up until last week, I was able to clone git repositories via SSH-based URIs in my Windows containers. Now, suddenly without warning, when I go to clone - even a public repository, I get this error:
Here's a simple
Dockerfile
that can be used to reproduce the issue:I'm not sure at this point what might be the issue - whether it's Windows or git. The only suspicious thing is that if I try to run the mingw based
ssh.exe
, it prints a blank line and then exits. My gut is telling me something about the SSH support in git for Windows is having a hard time?The text was updated successfully, but these errors were encountered: