r-lib / gert

Simple git client for R
https://docs.ropensci.org/gert/
Other
151 stars 33 forks source link

libgit2 not recognizing proxy variable #210

Open cb12991 opened 9 months ago

cb12991 commented 9 months ago

I cannot connect to GitHub using https protocol. I'm behind a corporate firewall but have curl proxy environment variables set with allow connection via CLI. Any attempt with gert fails unless ssh protocol is used.

gert::git_clone("https://github.com/r-lib/gert")
#> Error in libgit2::git_clone: failed to connect to github.com:

All required credentials seem to be set up correctly (PAT being stored and pulled from OS credential manager on Windows).

gitcreds::gitcreds_get()
#> <gitcreds>
#>   protocol: https
#>   host    : github.com
#>   username: PersonalAccessToken
#>   password: <-- hidden -->

I've tried adding my proxy to git config under both http and https but with no success.

I understand libgit2 is used with gert but it appears that it's the only thing not recognizing the proxy config. Since it isn't packaged though I don't know how to pass the proxy settings to it for it to use. I've tried looking at similar issues online but haven't found a solution.

Created on 2024-02-06 with reprex v2.0.2

jeroen commented 9 months ago

I'm not quite sure what the status of the proxy support is in libgit2. Can you review this thread if there are any hints? https://github.com/r-lib/gert/issues/122

cb12991 commented 9 months ago

I've reviewed that thread many times, but unfortunately haven't found a solution. It looks like I'll just have to avoid using gert and instead run git commands via CLI.

jeroen commented 9 months ago

Sorry about that. It is difficult for me to test this because I don't have access to such a proxied windows corp network.

I think there is a setting to pick up the proxy server, but that will still require you to provide crendentials somehow. Does your proxy server itself also require authentication?

cb12991 commented 9 months ago

No, it just uses the server address and port number AFAIK. I think Git is using the HTTP_PROXY environment variable somehow; not sure why libgit2 is not.

LiNk-NY commented 6 months ago

@jeroen I am also running into this. It works when I use git CLI but not with gert::git_clone. Note that git config --list returns:

http.https://github.com.proxy=http://<IP_ADDRESS>:<PORT>
http.https://github.com.proxysslcainfo=/etc/ssl/certs/local-ca.crt

Does libgit2 use these values?

Note. I am using :

> gert::libgit2_config()
$version
[1] '1.4.2'
mbannert commented 5 months ago

A few findings, that hopefully help to resolve the libgit2 issue.

However, despite https://github.com/libgit2/libgit2/blob/585210ab210800657ca32f843d3dc8e770c2a4d0/src/libgit2/remote.c#L1135 that looks like HTTP_PROXY & co are processed, libgit2 does not seem to respect the PROXY. Is there any way other than falling back to no-gert with system calls? Like passing the proxy var explicitly to gert::git_clone?