Skip to content

vcpkg_from_git: Add support for git over ssh#9446

Merged
dan-shaw merged 6 commits intomicrosoft:masterfrom
marcrambo:enable-git-over-ssh
Apr 1, 2020
Merged

vcpkg_from_git: Add support for git over ssh#9446
dan-shaw merged 6 commits intomicrosoft:masterfrom
marcrambo:enable-git-over-ssh

Conversation

@marcrambo
Copy link
Copy Markdown
Contributor

@marcrambo marcrambo commented Dec 26, 2019

vcpkg_from_git currently restricts urls to start with https. This PR removes the restriction and adds support for git over SSH, which is often preferred or even needed for private repos.

I do understand the restriction of https in vcpkg_from_github / vcpkg_from_bitbucket but from my understanding in vcpkg_from_git both protocols should be allowed and work the same way.

The tricky part is to make git over SSH work inside sandboxed vcpkg environment on windows:

  • users may set GIT_SSH and / or GIT_SSH_COMMAND to point to a custom ssh executable / comand.
  • users may use ssh-agent in order to facilitate authentications, in which case environment variables SSH_AUTH_SOCK and SSH_AGENT_PID need to be provided.
  • if GIT_SSH / GIT_SSH_COMMAND is not set, then git will assume ssh.exe is on the PATH. Currently this fails because the PATH is not forwarded to vcpkg. Hence we search for the ssh executable in a sibling directory of the git executable and prepend this directory to the PATH variable. I don't know a better way to do this. I have tested it with git that ships with vcpkg and also with git-for-windows, and it works in both cases. I do not know any other (popular) git clients for windows but I am happy to test with other clients as well.

I have tested all the above combinations of set / unset environment variables and git clients on windows. I have also tested on MacOS to verify that ssh works as expected, but this was already working out of the box, since there is no sandboxing on non-windows platforms.

@JackBoosY
Copy link
Copy Markdown
Contributor

/azp run

@JackBoosY
Copy link
Copy Markdown
Contributor

Maybe we should choose a port as an example to test?

@marcrambo marcrambo force-pushed the enable-git-over-ssh branch from 83c4a8d to 60b904a Compare March 7, 2020 13:31
@marcrambo
Copy link
Copy Markdown
Contributor Author

I rebased and resolved the conflicts. Anything else I can do on my side? Would be nice to merge this one.

@JackBoosY JackBoosY added the info:needs-maintainer-attention Lets the current 'on rotation' vcpkg maintainer know they need to look at this. label Mar 10, 2020
@strega-nil
Copy link
Copy Markdown
Contributor

Does this work on Linux/macOS?

@strega-nil strega-nil self-assigned this Mar 10, 2020
@JackBoosY JackBoosY added waiting for response and removed info:needs-maintainer-attention Lets the current 'on rotation' vcpkg maintainer know they need to look at this. labels Mar 11, 2020
@marcrambo
Copy link
Copy Markdown
Contributor Author

Yes this also works on macos / linux. Actually on these platforms git over ssh was already working, I didn't have to add anything. The only problematic platform was windows because of the clean_environment step.

@marcrambo
Copy link
Copy Markdown
Contributor Author

As @JackBoosY suggested we could also modify one of the ports to use ssh to verify the ci passes. We probably want to do that on another MR though which we close afterwards. As an alternative I can also push to this branch, and then revert the commit.

@strega-nil
Copy link
Copy Markdown
Contributor

strega-nil commented Mar 11, 2020

@marcrambo I might just test it locally, that's all it really needs, I think.

I'm going to bring it up at the PR review meeting tomorrow :)

@marcrambo
Copy link
Copy Markdown
Contributor Author

@strega-nil sounds good. Thanks!

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Should probably "usr/bin/ssh.exe" rather than going through the operator/= logic so many times.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

As the path separator is \ on windows this would then look like this:

fs::path git_ssh_exe_path = git_ssh_search_path / "usr\\bin\\ssh.exe"

To be honest I would rather leave it like it is. After all std::filesystem was designed to elegantly handle these platform specific details. I'd favor clarity over performance here and it looks like this is not performance critical code anyways.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

You can also do git_ssh_search_path / "usr/bin/ssh.exe"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Right, @strega-nil 's suggestion is what I meant.

@strega-nil
Copy link
Copy Markdown
Contributor

Could we modify the code to append to path, as opposed to prepending to path? There's a concern about overriding some utilities with the path to ssh.

@marcrambo marcrambo force-pushed the enable-git-over-ssh branch from dfd0fc3 to 4da3abf Compare March 14, 2020 16:27
@marcrambo
Copy link
Copy Markdown
Contributor Author

@strega-nil I have changed the code to append the ssh path as you suggested which is probably safer. Unfortunately the pipeline seems to be broken again, but this seems unrelated to my changes.

@JackBoosY
Copy link
Copy Markdown
Contributor

/azp run

@strega-nil strega-nil assigned dan-shaw and unassigned strega-nil Mar 16, 2020
@JackBoosY
Copy link
Copy Markdown
Contributor

/azp run

2 similar comments
@ras0219-msft
Copy link
Copy Markdown
Contributor

/azp run

@ras0219-msft
Copy link
Copy Markdown
Contributor

/azp run

@christophe-calmejane
Copy link
Copy Markdown
Contributor

Hi,
I've encountered a critical issue when using the commits from this PR, as described here.
Basically when this PR is merged into the current master, the openssl-windows port is no longer compiling.

@marcrambo
Copy link
Copy Markdown
Contributor Author

Hi,
I'm having an issue using this patch.
If the remote host is not yet in the ssh known_hosts file, the operation will fail with Host key verification failed.

Thanks for reporting this issue. I haven't tested it but I would say the failure is expected behavior unless you are using StrictHostKeyChecking=no (which I wouldn't recommend) https://askubuntu.com/questions/123072/ssh-automatically-accept-keys. When the host is not listed in the known_hosts file yet, git / ssh will ask the user to accept the key. This requires user interaction which cannot be handled in that case as vcpkg runs unattended.

@christophe-calmejane
Copy link
Copy Markdown
Contributor

Hi,
I'm having an issue using this patch.
If the remote host is not yet in the ssh known_hosts file, the operation will fail with Host key verification failed.

Thanks for reporting this issue. I haven't tested it but I would say the failure is expected behavior unless you are using StrictHostKeyChecking=no (which I wouldn't recommend) https://askubuntu.com/questions/123072/ssh-automatically-accept-keys. When the host is not listed in the known_hosts file yet, git / ssh will ask the user to accept the key. This requires user interaction which cannot be handled in that case as vcpkg runs unattended.

Hi,

yes I imagine it's expected behavior but looking from end-user perspective, it would be nice if we could find a solution for him to know what to do (as the error message is not clear, and he just expects things to just work).
Maybe if it's possible, detect user interaction is required and print a nice message... I don't know (for other people, I do have the solution now :) )

@marcrambo
Copy link
Copy Markdown
Contributor Author

Hi,
I've encountered a critical issue when using the commits from this PR, as described here.
Basically when this PR is merged into the current master, the openssl-windows port is no longer compiling.

Hi, thanks for reporting. I can reproduce the issue. I guess it has to do with additional binaries that are now visible next to the ssh executable. I'll try to come up with a solution. Probably the only way will be to overwrite the GIT_SSH environment variable.

@MVoz
Copy link
Copy Markdown
Contributor

MVoz commented Mar 27, 2020

all you had to do was add a folder to ENV PATH and it's already done

"${DOWNLOADS}/tools/${SUBDIR}/mingw32/bin"

@dan-shaw
Copy link
Copy Markdown
Contributor

@marcrambo This PR looks good and ready to merge. I don't know if you wanted to make any more changes, but let me know

@dan-shaw dan-shaw added info:needs-maintainer-attention Lets the current 'on rotation' vcpkg maintainer know they need to look at this. and removed waiting for response labels Mar 28, 2020
@christophe-calmejane
Copy link
Copy Markdown
Contributor

@dan-shaw What about the critical issue I talked about a few messages above, that breaks compilation?
Hasn't automatic build caught this? (if not there is probably a test missing in unit tests)

@marcrambo
Copy link
Copy Markdown
Contributor Author

all you had to do was add a folder to ENV PATH and it's already done

"${DOWNLOADS}/tools/${SUBDIR}/mingw32/bin"

Yes that's what I thought too. However adding the ssh directory to the path also pulls in quite a lot of unix binaries next to the ssh executable. This seems to affect the build process of open-ssh as reported by @christophe-calmejane , and potentially other packages.

@marcrambo
Copy link
Copy Markdown
Contributor Author

@dan-shaw @christophe-calmejane I had another look and it turns out the ssh path problem was fixed in upstream git-for-windows. There is no need to modify the path at all anymore, which is great! There is an interesting read on the subject here https://gitter.im/git-for-windows/git?at=5d2d8c4e01621760bcc2e649.

The funny coincidence is that the git version was bumped quite recently in vcpkg: https://github.com/microsoft/vcpkg/pull/10311/files just 2 days before I rebased my PR, so that's a pretty good timing i'd say ;)

@christophe-calmejane thanks again for reporting the issue. It was also quite good timing i'd say ;)
I have tested that openssl successfully builds locally but it would be great if you can confirm it. And also please check that ssh is still working for you.

I have tested extensively all variants of downloaded / system git, with / without GIT_SSH GIT_SSH_COMMAND ... and everything is working as expected.

@christophe-calmejane
Copy link
Copy Markdown
Contributor

@marcrambo I rebased my own work yesterday, and was forced to revert your commits due to openssl compilation issue, and the funny thing I noticed is my ssh repositories were working just fine!
At the time I just suspected it was because there was some sort of cache somewhere or something like that, and couldn't afford to wipe everything to test from scratch.
But based on what you said, it looks like it's actually fixed, which is good news then! I won't be able to test again (from scratch) before Monday, but I'll drop a note here if it's actually good when using vcpkg master branch!
Thanks :)

@marcrambo
Copy link
Copy Markdown
Contributor Author

@marcrambo I rebased my own work yesterday, and was forced to revert your commits due to openssl compilation issue, and the funny thing I noticed is my ssh repositories were working just fine!
At the time I just suspected it was because there was some sort of cache somewhere or something like that, and couldn't afford to wipe everything to test from scratch.

Yes vcpkg uses a download cache for each package. So even if you remove and reinstall a package, vcpkg will not fetch the source again. This explains why it was still working for you after switching back to master. At least the remaining parts of this PR are needed to unblock non-https urls, and to whitelist some environmental variables for the ssh-agent.

@dan-shaw from my side this PR is good to go. Please feel free to merge.

@christophe-calmejane
Copy link
Copy Markdown
Contributor

I was talking about a cache for SSH, not vcpkg. When I do my tests I always wipe all generated folders (downloads, buildtrees, packages, installed).
I just checked my branch and it was indeed rebased after the change to git version so I guess it was the reason it worked for me once again. I’ll do a new test tomorrow but it looks pretty good to me, gj :)

@JackBoosY JackBoosY added Needs Testing and removed info:needs-maintainer-attention Lets the current 'on rotation' vcpkg maintainer know they need to look at this. labels Mar 30, 2020
@christophe-calmejane
Copy link
Copy Markdown
Contributor

@marcrambo I confirm I can build openssl-windows once again, and I can clone using SSH as well.

@JackBoosY
Copy link
Copy Markdown
Contributor

@christophe-calmejane So, does this PR work now?

@christophe-calmejane
Copy link
Copy Markdown
Contributor

@JackBoosY yes it does

@JackBoosY JackBoosY added info:needs-maintainer-attention Lets the current 'on rotation' vcpkg maintainer know they need to look at this. and removed Needs Testing labels Apr 1, 2020
@dan-shaw dan-shaw merged commit e1fc03c into microsoft:master Apr 1, 2020
@dan-shaw
Copy link
Copy Markdown
Contributor

dan-shaw commented Apr 1, 2020

@marcrambo Thanks for the PR and wait!

@christophe-calmejane thanks for testing!

strega-nil pushed a commit to strega-nil/vcpkg that referenced this pull request May 5, 2021
* vcpkg_from_git: Add support for git over ssh

* vcpkg_from_git: append ssh bin directory to path

* vcpkg_from_git: fix function signature on non windows platforms

* Revert "vcpkg_from_git: fix function signature on non windows platforms"

This reverts commit 0d608ee.

* Revert "vcpkg_from_git: append ssh bin directory to path"

This reverts commit 377ce3f.

* Partial Revert "vcpkg_from_git: Add support for git over ssh"

This partially reverts commit 9b81b16.

Co-authored-by: Marc Boucek <marc.boucek@native-instruments.de>
Co-authored-by: Marc Boucek <marc.boucek@posteo.net>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

info:needs-maintainer-attention Lets the current 'on rotation' vcpkg maintainer know they need to look at this.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

9 participants