【发布时间】:2021-08-02 04:13:47
【问题描述】:
嗨,
当使用来自 Eclipse 的 egit 时,我们正面临这个可怕的问题“不支持身份验证”。我已经阅读了很多文章和问题,但似乎都没有解决手头的问题。
我们正在使用 Microsoft Team Foundation Server 2015,它可以提供一个 git 存储库作为版本控制系统。但是使用 eclipse 的 egit 插件,身份验证机制似乎不起作用。我们检查了使用 eclipse 2020-06、2020-12、2021-03 中的不同 eclipse 版本以及不同的 jdk 设置 1.8、11 和 15,但没有成功。
克隆、推送/获取在 git 命令行 (git bash - windows) 下运行良好,即使是旧版 eclipse kepler 也可以正常运行,但不是最新的。该问题似乎与 NTLM 身份验证有关。在较新版本的 eclipse 中,即使服务器使用 WWW-Authenticate: NTLM 响应,egit 也不会协商或发送 NTLM 令牌。
以下是新旧 Eclipse 版本的详细信息,它们通过 TCP/IP 监视器隧道捕获流量。即使门户在 https 上,TFS git 存储库克隆协议也是 http。
Eclipse 2021-03
请求:
GET /tfs/xxx/_git/xxx/info/refs?service=git-upload-pack HTTP/1.1
Accept-Encoding: gzip
Pragma: no-cache
User-Agent: JGit/5.11.0.202103091610-r
Accept: application/x-git-upload-pack-advertisement, */*
Git-Protocol: version=2
Host: tfs-xxx-xx:8090
Connection: Keep-Alive
回应:
HTTP/1.1 401 Unauthorized
Cache-Control: private
Content-Type: text/html
Server: Microsoft-IIS/8.5
X-TFS-ProcessId: 76ec3355-4bc2-498d-ba64-xxxxxxx
X-FRAME-OPTIONS: SAMEORIGIN
Access-Control-Allow-Origin: *
Access-Control-Max-Age: 3600
Access-Control-Allow-Methods: OPTIONS,GET,POST,PATCH,PUT,DELETE
Access-Control-Expose-Headers: ActivityId,X-TFS-Session
Access-Control-Allow-Headers: authorization
Set-Cookie: Tfs-SessionId=3b370bd6-2197-xxxxxxxxx; path=/
Set-Cookie: Tfs-SessionActive=2021-05-11T17:25:24; path=/
WWW-Authenticate: NTLM
X-Powered-By: ASP.NET
P3P: CP="CAO xxxxxxxxxxxxxxxxx"
X-Content-Type-Options: nosniff
Date: Tue, 11 May 2021 17:25:24 GMT
Content-Length: 1293
Eclipse 开普勒
第一个请求/响应与上述类似。
第二次请求:
GET /tfs/xxx/_git/xxx/info/refs?service=git-upload-pack HTTP/1.1
Accept-Encoding: gzip
Pragma: no-cache
User-Agent: JGit/3.2.0.201312181205-r
Accept: application/x-git-upload-pack-advertisement, */*
Cache-Control: no-cache
Host: tfs-pmo-app:8090
Connection: keep-alive
Authorization: NTLM TlRMTVxxxxxxx - Length 72 chars
第二反应:
HTTP/1.1 401 Unauthorized
Content-Type: text/html; charset=us-ascii
WWW-Authenticate: NTLM TlRMxxxxxx== - Length 354 chars
Server: Microsoft-HTTPAPI/2.0
Date: Tue, 11 May 2021 17:33:00 GMT
Content-Length: 341
第三次请求:
GET /tfs/xxx/_git/xxx/info/refs?service=git-upload-pack HTTP/1.1
Accept-Encoding: gzip
Pragma: no-cache
User-Agent: JGit/3.2.0.201312181205-r
Accept: application/x-git-upload-pack-advertisement, */*
Cache-Control: no-cache
Host: tfs-pmo-app:8090
Connection: keep-alive
Authorization: NTLM TlRMTVNxxxxx - Length 256 chars
第三反应:
HTTP/1.1 200 OK
Cache-Control: private
Content-Type: application/x-git-upload-pack-advertisement
Server: Microsoft-IIS/8.5
X-TFS-ProcessId: 76ec3355-4bc2-xxxxxxxxxxxxxx
X-FRAME-OPTIONS: SAMEORIGIN
Access-Control-Allow-Origin: *
Access-Control-Max-Age: 3600
Access-Control-Allow-Methods: OPTIONS,GET,POST,PATCH,PUT,DELETE
Access-Control-Expose-Headers: ActivityId,X-TFS-Session
Access-Control-Allow-Headers: authorization
Set-Cookie: Tfs-SessionId=xxxxxxxxxxxx; path=/
Set-Cookie: Tfs-SessionActive=2021-05-11T17:33:01; path=/
X-VSS-UserData: 69b58752-xxxxxxxxxxxxx
X-AspNet-Version: 4.0.30319
Persistent-Auth: true
X-Powered-By: ASP.NET
P3P: CP="CAO xxxxxxxxxxxxxxxxxxxxxxxxx"
X-Content-Type-Options: nosniff
Date: Tue, 11 May 2021 17:33:00 GMT
Content-Length: 1098
到目前为止我们所做的尝试,将连接超时增加到 300,在 Eclipse Preferences for Git 中更改 http 客户端,在克隆 repo 时添加用户名/密码 - 这没有任何明显的影响,使用 jdk 更改 eclipse 的不同变体,将 git 凭据助手更改为 wincred、管理器、存储甚至在没有任何凭据助手的情况下重置,尝试配置 cntlm 但在测试期间它说您不需要代理,这些似乎都不起作用。
这可能意味着 egit/jgit 实现中存在错误。从错误中查看当前的实现源和跟踪堆栈:
!ENTRY org.eclipse.egit.core 4 0 2021-05-08 04:56:02.018
!MESSAGE Pulling 1 repository
!SUBENTRY 1 org.eclipse.egit.core 4 0 2021-05-08 04:56:02.021
!MESSAGE http://xxxxx:8090/tfs/xxxx/_git/xxx: authentication not supported
!STACK 0
org.eclipse.jgit.api.errors.TransportException: http://xxxxx:8090/tfs/xxxx/_git/xxx: authentication not supported
at org.eclipse.jgit.api.FetchCommand.call(FetchCommand.java:224)
at org.eclipse.jgit.api.PullCommand.call(PullCommand.java:263)
at org.eclipse.egit.core.op.PullOperation$PullJob.run(PullOperation.java:255)
at org.eclipse.core.internal.jobs.Worker.run(Worker.java:63)
Caused by: org.eclipse.jgit.errors.TransportException: http://xxxxx:8090/tfs/xxxx/_git/xxx: authentication not supported
at org.eclipse.jgit.transport.TransportHttp.connect(TransportHttp.java:674)
at org.eclipse.jgit.transport.TransportHttp.openFetch(TransportHttp.java:465)
at org.eclipse.jgit.transport.FetchProcess.executeImp(FetchProcess.java:142)
at org.eclipse.jgit.transport.FetchProcess.execute(FetchProcess.java:94)
at org.eclipse.jgit.transport.Transport.fetch(Transport.java:1309)
at org.eclipse.jgit.api.FetchCommand.call(FetchCommand.java:213)
... 3 more
org.eclipse.jgit.transport.TransportHttp.connect(TransportHttp.java:674):
Line 671: case HttpConnection.HTTP_UNAUTHORIZED:
Line 672: authMethod = HttpAuthMethod.scanResponse(conn, ignoreTypes);
Line 673: if (authMethod.getType() == HttpAuthMethod.Type.NONE)
Line 674: throw new TransportException(uri, MessageFormat.format(
Line 675: JGitText.get().authenticationNotSupported, uri));
看起来 scanResponse 方法没有返回导致问题的 auth 方法类型,所以让我们回顾一下 HttpAuthMethod:
这里的代码基本上检查了 3 种身份验证方法,BASIC、DIGEST 和 NEGOTIATE,在我们的例子中,标题“WWW-Authenticate: NTLM”是不支持的一次,因此例外。
但令人困惑的部分是开普勒如何成功地为 NTLM 进行身份验证,答案可能(通过网络搜索)实际上是 jdk 可能对此负责,因为它在 HttpURLConnection 类下固有地发送可能不是 NTLM 令牌较新 jdks 的案例(不知道为什么)。
结论:我似乎没有找到问题出在哪里的正确答案?
- 是不是因为新的 jdk 本身不支持 NTML(在 引擎盖)?
- 不应 egit/jgit 回退到其他机制,如 BASIC 身份验证?
- 为什么我不能使用预先发送我的凭据 egit/jgit 绕过 NTLM?
P.S. 在写这篇文章时,看起来我们的服务器可能没有配置为 BASIC 身份验证支持,但我使用 git 命令尝试了不同的身份验证类型,它们确实有效。我会用wireshark capture再次检查,看看底层机制。
谢谢,如果您阅读了整篇文章:)。
【问题讨论】: