繁体   English   中英

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

[英]Does git clone work through NTLM proxies?

我已尝试使用export http_proxy=http://[username]:[pwd]@[proxy]git config --global http.proxy http://[username]:[pwd]@[proxy]

我无法让它发挥作用。 看起来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搜索返回了混合且可能未更新的结果。 在某个地方,它说curl是(是?)在引擎盖下使用,但它的选项(是?)硬连线到代码中。 例如,

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

工作,我想与git使用相同的选项。

我在这里需要一些更明确的答案:有没有人通过Windows代理成功使用git? 哪个版本?

谢谢。

默认NTLM凭据

要使用默认的NTLM凭据,请提供空的用户名和密码

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

ISA Server的防火墙客户端

您可以使用Microsoft的ISA Server防火墙客户端,而不是为git,npm等设置代理。 安装后:

Start > Autostart > Microsoft Firewall Client Management

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

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

1.7.10 发布说明简要提到它:

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

我已经成功地在我的工作场所使用代理进行了测试,这是NTLM并且需要用户/通行证,您可以使用以下命令测试自己:

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

问候,

克隆对我有用,但只能通过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建议通过git://github.com/...克隆,但你必须手动将其更改为http://github.com/...

编辑:我正在使用git版本1.5.6.3。

希望有所帮助!

AndreaG(在上面的评论中)对我能找到的这个问题有唯一可接受的答案。 似乎Git只是不能使用NTLM代理,即使它真的应该因为cURL(它在下面使用)确实工作得很好。 为什么这个问题无法修复我不知道。 这似乎是一个相当普遍的问题。

完整的解决方案是使用ntlmaps充当代理的代理。 您需要做的就是从以下网址下载最新版本的应用程序: http//ntlmaps.sourceforge.net/

更改配置文件以包含您的身份验证和代理详细信息,然后将代理设置为新的本地代理:

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

我可以确认它工作得很好。 您不仅可以将它用于任何需要NTLM身份验证但不提供完整NTLM支持的应用程序。

你也可以使用cntlm,

http://cntlm.sourceforge.net/

类似于ntlmaps但使用纯C编写的解决方案。它通过在计算机上的端口(默认为3128)创建本地代理服务器(127.0.0.1),以与ntlmaps相同的方式工作。 这个新的本地创建的代理服务器不需要任何身份验证,因此可以与任何支持http代理的应用程序一起使用。 如果需要,它还可以创建本地socks代理。

使用python编写的ntlmaps的主要优点是cntlm具有非常低的CPU和RAM使用率,通常<2%。

TL / DR:

export GIT_HTTP_PROXY_AUTHMETHOD=basic

要么

git config --global http.proxyauthmethod basic

当git(curl)代理身份验证不起作用时,我遇到了同样的问题。 证书是对的。 升级到最新的git-v2.15.0没有帮助。

问题是由于git-libcurl选择了错误的代理身份验证方法。

有效的proxy_authmethod选项在git源中定义: https//github.com/git/git/blob/d0e9983980a25e0c398cc03342e5ad22ef85b8a8/http.c#L81

可以通过GIT_HTTP_PROXY_AUTHMETHOD环境变量或http.proxyauthmethod git config选项定义GIT_HTTP_PROXY_AUTHMETHOD方法。 环境变量会覆盖config选项值。

由于这是我一直在寻找我的搜索工作的问题,我将在这里添加我的答案。

我需要在一个网络上访问通过http(s)代理(需要NTLM身份验证)工作的github.com托管仓库,并且在正常的互联网连接上,从我们的Mac OS X开发机器上运行它仍然可以工作。

这是我如何使它工作。 这不适用于每个git托管服务提供商,但我发布以防万一它可以帮助你解决这个问题。 这也仅适用于Mac OS X,但如果你弄清楚如何为你的系统进行网络变更运行,其余的应该遵循。

在正常设置ssh访问后,我不得不使用git clone git@github.com:user/repo.git (http://help.github.com/mac-set-up-git/)。

然后我需要设置一个处理NTLM身份验证的本地http(s)代理,例如ntlmaps,cntlm或Authoxy。 我已经使用Authoxy进行了测试。 我将把这个配置给你,因为你需要知道你自己的代理细节。

如果你有MacPorts,你还需要开瓶器,这只是sudo port install corkscrew corkscrew。

然后我将以下内容添加到~/.ssh/config

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

其中6574是TCP端口,我设置Authoxy来监听。

现在我创建了一个脚本,试图找到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."

别忘了chmod +x /usr/local/bin/locationchanger

现在创建~/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>

然后launchctl load ~/Library/LaunchAgents/LocationChanger.plist 只要网络发生变化,此启动作业就会运行。 如果它可以找到您的内部网络http(s)代理服务器,它将使ssh使用corkscrew通过Authoxy工作,它将处理通过公司代理工作。 如果它找不到代理服务器,它将禁用特殊的ssh配置,并且你正常工作。

现在我们的团队不再需要考虑网络切换了。

我一直在使用ntlmaps并通过Windows / NT代理获得了良好的结果: http//ntlmaps.sourceforge.net/

git配置是:

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

我偶然发现了一个更简单,更安全的解决方案,它不仅适用于git,也适用于任何基于命令的安装程序

  • 红宝石中的Rubygems
  • 节点中的npm

从命令行运行所有流量的一个解决方案代表了真实性。

不要在用户中公开您的密码:password @ domain:port format

解:

下载Fiddler ,它有一种内置的方式来为所有请求添加身份验证标头。

一旦运行菜单规则 - >自动验证(勾选)

然后为git

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

而已!

暂无
暂无

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

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