简体   繁体   English

git clone是否可以通过NTLM代理工作?

[英]Does git clone work through NTLM proxies?

I've tried both using export http_proxy=http://[username]:[pwd]@[proxy] and git config --global http.proxy http://[username]:[pwd]@[proxy] . 我已尝试使用export http_proxy=http://[username]:[pwd]@[proxy]git config --global http.proxy http://[username]:[pwd]@[proxy]

I couldn't make it work. 我无法让它发挥作用。 It looks like git uses Basic authentication: 看起来git使用Basic身份验证:

Initialized empty Git repository in /home/.../.git/
* Couldn't find host github.com in the .netrc file, using defaults
* About to connect() to github.com port 8080 (#0)
*   Trying 10.... * Connected to github.com (10....) port 8080 (#0)
* Proxy auth using Basic with user '...'
> GET http://github.com/sunlightlabs/fiftystates.git/info/refs HTTP/1.1
Proxy-Authorization: Basic MD...
User-Agent: git/1.6.1.2
Host: github.com
Pragma: no-cache
Accept: */*
Proxy-Connection: Keep-Alive

< HTTP/1.1 407 Proxy Authentication Required ( The ISA Server requires authorization to fulfill the request. Access to t
he Web Proxy filter is denied.  )
< Via: 1.1 ...
< Proxy-Authenticate: Negotiate
< Proxy-Authenticate: Kerberos
< Proxy-Authenticate: NTLM
< Connection: Keep-Alive
< Proxy-Connection: Keep-Alive
< Pragma: no-cache
< Cache-Control: no-cache
< Content-Type: text/html
< Content-Length: 4118
* The requested URL returned error: 407
* Closing connection #0
fatal: http://github.com/sunlightlabs/fiftystates.git/info/refs download error - The requested URL returned error: 407

Google search returned mixed and probably not updated results. Google搜索返回了混合且可能未更新的结果。 Somewhere it says that curl is (was?) used under the hood, but its options are (were?) hardwired into code. 在某个地方,它说curl是(是?)在引擎盖下使用,但它的选项(是?)硬连线到代码中。 For example, 例如,

curl --proxy-ntlm --proxy ...:8080 google.com

works, and I'd like to use the same option with git. 工作,我想与git使用相同的选项。

I need some more definite answers here: has anybody succeed using git through Windows proxies? 我在这里需要一些更明确的答案:有没有人通过Windows代理成功使用git? Which version? 哪个版本?

Thanks. 谢谢。

Default NTLM credentials 默认NTLM凭据

In order to use default NTLM credentials, provide an empty username and password 要使用默认的NTLM凭据,请提供空的用户名和密码

git config --global http.proxy https://:@proxy:port

Firewall Client for ISA Server ISA Server的防火墙客户端

Instead of setting proxy for git, npm, etc. you can use Firewall Client for ISA Server from Microsoft. 您可以使用Microsoft的ISA Server防火墙客户端,而不是为git,npm等设置代理。 After installation: 安装后:

Start > Autostart > Microsoft Firewall Client Management

Settings tab > Manual specified ISA Server > proxy:port Web Browser tab > Uncheck "Enable web browser automatic configuration."

Git supports NTLM proxy authentication from version 1.7.10 onwards, relevant commit is https://github.com/gitster/git/commit/dd6139971a18e25a5089c0f96dc80e454683ef0b Git支持从版本1.7.10开始的NTLM代理身份验证,相关提交是https://github.com/gitster/git/commit/dd6139971a18e25a5089c0f96dc80e454683ef0b

1.7.10 release notes briefly mentioned it as: 1.7.10 发布说明简要提到它:

* HTTP transport learned to authenticate with a proxy if needed.

I've successfully tested it with the proxy at my workplace which is NTLM and requires user/pass, you can test yourself with following commands: 我已经成功地在我的工作场所使用代理进行了测试,这是NTLM并且需要用户/通行证,您可以使用以下命令测试自己:

git config --global http.proxy http://user:password@proxy.com:port
git clone http://git.videolan.org/git/bitstream.git

Regards, 问候,

Cloning works for me but only over HTTP (since our corporate firewall blocks the ssh/git protocols): 克隆对我有用,但只能通过HTTP(因为我们的公司防火墙阻止了ssh / git协议):

$ export http_proxy="http://username:password@proxy:port/"
$ git clone http://github.com/sunlightlabs/fiftystates_site.git fifty
Initialized empty Git repository in /home/user/fifty/.git/
got e15f5192b923d8e87abaeb9406d0f4d80403da09
walk e15f5192b923d8e87abaeb9406d0f4d80403da09
got a78b792191f1cf5e961753dcfe05e9c809bdb0ed
got 76e6e86e72a0f998f7663da69ca49c457a302e27
walk 76e6e86e72a0f998f7663da69ca49c457a302e27
got 35b68a3b876fb90e73ba7a7eb51432e825ef2aa3
...

Github suggests cloning via git://github.com/... but you have to change it to http://github.com/... manually. Github建议通过git://github.com/...克隆,但你必须手动将其更改为http://github.com/...

Edit: I'm using git version 1.5.6.3. 编辑:我正在使用git版本1.5.6.3。

Hope that helps! 希望有所帮助!

AndreaG (in a comment above) has the only acceptable answer to this problem that I can find. AndreaG(在上面的评论中)对我能找到的这个问题有唯一可接受的答案。 It seems that Git just won't work with NTLM proxies even though it really should because cURL (which it uses underneath) does work just fine. 似乎Git只是不能使用NTLM代理,即使它真的应该因为cURL(它在下面使用)确实工作得很好。 Why this issue can't be fixed I have no idea. 为什么这个问题无法修复我不知道。 It seems to be a fairly common issue. 这似乎是一个相当普遍的问题。

The solution, in full then, is to use ntlmaps to act as a proxy to the proxy. 完整的解决方案是使用ntlmaps充当代理的代理。 All you need to do is to download the latest version of the app from: http://ntlmaps.sourceforge.net/ 您需要做的就是从以下网址下载最新版本的应用程序: http//ntlmaps.sourceforge.net/

Change the config file to include your authentication and proxy details and then set the proxy to be your new local one: 更改配置文件以包含您的身份验证和代理详细信息,然后将代理设置为新的本地代理:

git config --global http.proxy http://localhost:5865

I can confirm that it works just fine. 我可以确认它工作得很好。 Not only that you can use it for any app that requires NTLM authentication but does not provide full NTLM support. 您不仅可以将它用于任何需要NTLM身份验证但不提供完整NTLM支持的应用程序。

You can also use cntlm, 你也可以使用cntlm,

http://cntlm.sourceforge.net/ http://cntlm.sourceforge.net/

A solution similar to ntlmaps but written in pure C. It works in the same way as ntlmaps by creating a local proxy server (127.0.0.1) at a port (3128 default) on your machine. 类似于ntlmaps但使用纯C编写的解决方案。它通过在计算机上的端口(默认为3128)创建本地代理服务器(127.0.0.1),以与ntlmaps相同的方式工作。 This new locally created proxy server does not require any authentication and thus can be used with any application that supports http proxy. 这个新的本地创建的代理服务器不需要任何身份验证,因此可以与任何支持http代理的应用程序一起使用。 It can also create a local socks proxy if you need one. 如果需要,它还可以创建本地socks代理。

The main advantage over ntlmaps which is written in python, is that cntlm has very low CPU and RAM usage, typically <2%. 使用python编写的ntlmaps的主要优点是cntlm具有非常低的CPU和RAM使用率,通常<2%。

TL/DR: TL / DR:

export GIT_HTTP_PROXY_AUTHMETHOD=basic

or 要么

git config --global http.proxyauthmethod basic

I had the same issue when git (curl) proxy auth did not work. 当git(curl)代理身份验证不起作用时,我遇到了同样的问题。 Credentials were right. 证书是对的。 Upgrade to the latest git-v2.15.0 did not help. 升级到最新的git-v2.15.0没有帮助。

The issue was due to wrong proxy authentication method chosen by git-libcurl. 问题是由于git-libcurl选择了错误的代理身份验证方法。

The valid proxy_authmethod options are defined in git source: https://github.com/git/git/blob/d0e9983980a25e0c398cc03342e5ad22ef85b8a8/http.c#L81 有效的proxy_authmethod选项在git源中定义: https//github.com/git/git/blob/d0e9983980a25e0c398cc03342e5ad22ef85b8a8/http.c#L81

The proxyauthmethod can be defined either through GIT_HTTP_PROXY_AUTHMETHOD environment variable or http.proxyauthmethod git config option. 可以通过GIT_HTTP_PROXY_AUTHMETHOD环境变量或http.proxyauthmethod git config选项定义GIT_HTTP_PROXY_AUTHMETHOD方法。 Environment variable overrides the config option value. 环境变量会覆盖config选项值。

Since this was a question I kept finding on my search to make this work, I'll add my answer here. 由于这是我一直在寻找我的搜索工作的问题,我将在这里添加我的答案。

I needed to get access to a github.com hosted repo working via an http(s) proxy (that requires NTLM authentication) on one network, and have it still work when on a normal internet connection, from our Mac OS X dev machines. 我需要在一个网络上访问通过http(s)代理(需要NTLM身份验证)工作的github.com托管仓库,并且在正常的互联网连接上,从我们的Mac OS X开发机器上运行它仍然可以工作。

Here is how I made it work. 这是我如何使它工作。 This won't work for every git hosting provider, but I'm posting in case it helps you figure this out. 这不适用于每个git托管服务提供商,但我发布以防万一它可以帮助你解决这个问题。 This is also only for Mac OS X, but if you figure out how to run something on network change for your system, the rest should follow. 这也仅适用于Mac OS X,但如果你弄清楚如何为你的系统进行网络变更运行,其余的应该遵循。

I had to use git clone git@github.com:user/repo.git after setting up ssh access as normal (http://help.github.com/mac-set-up-git/). 在正常设置ssh访问后,我不得不使用git clone git@github.com:user/repo.git (http://help.github.com/mac-set-up-git/)。

I then needed to setup a local http(s) proxy that handles the NTLM authentication, such as ntlmaps, cntlm or Authoxy. 然后我需要设置一个处理NTLM身份验证的本地http(s)代理,例如ntlmaps,cntlm或Authoxy。 I've tested with Authoxy. 我已经使用Authoxy进行了测试。 I'll leave configuring this to you, because you'll need to know your own proxy details. 我将把这个配置给你,因为你需要知道你自己的代理细节。

You'll also need corkscrew, which is just sudo port install corkscrew if you have MacPorts. 如果你有MacPorts,你还需要开瓶器,这只是sudo port install corkscrew corkscrew。

Then I added the following to ~/.ssh/config : 然后我将以下内容添加到~/.ssh/config

Host github.com.disabled
User git
HostName ssh.github.com
Port 443
ProxyCommand /opt/local/bin/corkscrew localhost 6574 %h %p

Where 6574 is the TCP port I set Authoxy to listen on. 其中6574是TCP端口,我设置Authoxy来监听。

Now I created a script that tries to find the http(s) proxy server, and configures the ssh setup according to what it finds, at /usr/local/bin/locationchanger : 现在我创建了一个脚本,试图找到http(s)代理服务器,并根据它找到的内容在/usr/local/bin/locationchanger配置ssh设置:

#!/bin/sh

set -o nounset
set -o errexit

sleep 10 # allow for WiFi to actually connect.

# if we can find the proxy server, then use it.
if ! host proxy.internal.network;
then
    echo "Proxy server not found, clearing http(s) proxy";
    sed -i '.backup' -E 's/^Host github.com$/Host github.com.disabled/' "$HOME/.ssh/config"
else
    echo "Proxy server found, setting http(s) proxy";
    sed -i '.backup' -E 's/^Host github.com.disabled$/Host github.com/' "$HOME/.ssh/config"
fi
echo "Done."

Don't forget to chmod +x /usr/local/bin/locationchanger . 别忘了chmod +x /usr/local/bin/locationchanger

Now create ~/Library/LaunchAgents/LocationChanger.plist : 现在创建~/Library/LaunchAgents/LocationChanger.plist

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN"
    "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>Label</key>
    <string>tech.inhelsinki.nl.locationchanger</string>
    <key>ProgramArguments</key>
    <array>
        <string>/usr/local/bin/locationchanger</string>
    </array>
    <key>WatchPaths</key>
    <array>
        <string>/Library/Preferences/SystemConfiguration</string>
    </array>
</dict>
</plist>

And then launchctl load ~/Library/LaunchAgents/LocationChanger.plist . 然后launchctl load ~/Library/LaunchAgents/LocationChanger.plist This launchd job will run whenever the network changes. 只要网络发生变化,此启动作业就会运行。 If it can find your internal network http(s) proxy server, it will make ssh use corkscrew to work through Authoxy, which will handle working through the company proxy. 如果它可以找到您的内部网络http(s)代理服务器,它将使ssh使用corkscrew通过Authoxy工作,它将处理通过公司代理工作。 If it can't find the proxy server, it will disable the special ssh config, and you're working just like normal. 如果它找不到代理服务器,它将禁用特殊的ssh配置,并且你正常工作。

Now our team doesn't have to think about network switching anymore. 现在我们的团队不再需要考虑网络切换了。

I've been using ntlmaps and been having good results getting through windows/NT proxies: http://ntlmaps.sourceforge.net/ 我一直在使用ntlmaps并通过Windows / NT代理获得了良好的结果: http//ntlmaps.sourceforge.net/

The git configuration is: git配置是:

git config --global http.proxy http://localhost:5865 git config --global http.proxy http:// localhost:5865

I have stumbled on a more easier and possibly safer solution that works not just for git but also any command based installers 我偶然发现了一个更简单,更安全的解决方案,它不仅适用于git,也适用于任何基于命令的安装程序

  • Rubygems in ruby 红宝石中的Rubygems
  • npm in node 节点中的npm

One solution running all your traffic from command line is proxied with authentiction. 从命令行运行所有流量的一个解决方案代表了真实性。

Wont expose your password in the user:password@domain:port format 不要在用户中公开您的密码:password @ domain:port format

Solution: 解:

Download Fiddler , It has a built in way to add authentication headers to all requests. 下载Fiddler ,它有一种内置的方式来为所有请求添加身份验证标头。

Once running menu Rules-> Automatically Authenticate (Tick that) 一旦运行菜单规则 - >自动验证(勾选)

Then for git 然后为git

git config --global http.proxy http://localhost:8888
git config --global https.proxy http://localhost:8888

Thats it! 而已!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM