是否可以使用默认的 Windows 凭据以非交互方式对远程 Git 存储库进行身份验证?

2023-12-19

我的远程 Git 存储库由本地 TFS 服务器托管。有两种方法可以访问其内容:

  • 使用 TFS Restful API -https://learn.microsoft.com/en-us/rest/api/vsts/git/items/get?view=vsts-rest-4.1 https://learn.microsoft.com/en-us/rest/api/vsts/git/items/get?view=vsts-rest-4.1
  • 使用本机 git 客户端,例如这git clone command

要使用 Restful API,可以使用 powershellInvoke-RestMethod命令与-UseDefaultCredentials而且效果很好,没有任何问题。

With git clone但是,我不知道如何使用默认凭据。这经理凭证助手 https://github.com/Microsoft/Git-Credential-Manager-for-Windows/releases不使用它们。第一次使用时,它会要求提供凭据。

所以,我看到的选项是:

  • 还有一个替代的 git 客户端,可能功能有限,但足以运行可以使用默认 Windows 凭据的克隆。
  • Windows 有一个凭据帮助程序,可以使用默认的 Windows 凭据。
  • Windows 有一个 Askpass 实现,可以使用默认的 Windows 凭据。

问题是我在网上找不到任何实现这些选项的东西。

Edit 1

中建议的方法https://github.com/git-for-windows/git/wiki/FAQ#how-do-i-access-a-repository-hosted-on-a-microsoft-team-foundation-server-inside-a- windows域 https://github.com/git-for-windows/git/wiki/FAQ#how-do-i-access-a-repository-hosted-on-a-microsoft-team-foundation-server-inside-a-windows-domain似乎不起作用。请注意:

C:\xyz\DevOps> $GitApiUrl
http://tfsserver:8080/tfs/DefaultCollection/code/_apis/git/repositories/MyConfigData
C:\xyz\DevOps> $ProjectName
dev_smoketest56oc
C:\xyz\DevOps> Test-Path .\params.json
False
C:\xyz\DevOps> Invoke-RestMethod -Uri "$GitApiUrl/items?path=$ProjectName.json&api-version=4.1" -UseDefaultCredentials -OutFile params.json
C:\xyz\DevOps> Test-Path .\params.json
True

正如您所看到的,Restful API 无需提供凭据即可工作。现在让我们尝试 git clone:

C:\xyz\DevOps> $env:GIT_TRACE=1
C:\xyz\DevOps> git clone http://:@tfsserver:8080/tfs/DefaultCollection/code/_git/MyApp a
09:13:21.405748 exec-cmd.c:236          trace: resolved executable dir: C:/Program Files/Git/mingw64/bin
09:13:21.406249 git.c:415               trace: built-in: git clone http://:@tfsserver:8080/tfs/DefaultCollection/code/_git/MyApp a
Cloning into 'a'...
09:13:21.430369 run-command.c:637       trace: run_command: git remote-http origin http://:@tfsserver:8080/tfs/DefaultCollection/code/_git/MyApp
09:13:21.459149 exec-cmd.c:236          trace: resolved executable dir: C:/Program Files/Git/mingw64/libexec/git-core
09:13:21.460654 git.c:654               trace: exec: git-remote-http origin http://:@tfsserver:8080/tfs/DefaultCollection/code/_git/MyApp
09:13:21.460654 run-command.c:637       trace: run_command: git-remote-http origin http://:@tfsserver:8080/tfs/DefaultCollection/code/_git/MyApp
09:13:21.481711 exec-cmd.c:236          trace: resolved executable dir: C:/Program Files/Git/mingw64/libexec/git-core
09:13:21.539575 run-command.c:637       trace: run_command: 'git credential-manager erase'
09:13:21.642660 exec-cmd.c:236          trace: resolved executable dir: C:/Program Files/Git/mingw64/libexec/git-core
09:13:21.644162 git.c:654               trace: exec: git-credential-manager erase
09:13:21.644162 run-command.c:637       trace: run_command: git-credential-manager erase
fatal: Authentication failed for 'http://:@tfsserver:8080/tfs/DefaultCollection/code/_git/MyApp/'
C:\xyz\DevOps> $env:GIT_TRACE=0
C:\xyz\DevOps>

认证失败。

Edit 2

在 bash 控制台上:

$ GIT_CURL_VERBOSE=1

$ curl -v --ntlm -u : http://tfsserver:8080/tfs/DefaultCollection/code/_git/MyApp -o 1.html 2> out.txt

$ curl -v --ntlm -u : http://:@tfsserver:8080/tfs/DefaultCollection/code/_git/MyApp -o 2.html 2> out2.txt

文件 1.html 和 2.html 似乎代表了存储库的网页,就像在浏览器中一样,因此两个curl命令都是成功的。

输出文件 out.txt 和 out2.txt 非常相似,区别在于时间戳、guid 和加密字符串。所以,这是 out.txt (我冒昧地删除了空行并删除了一些字符串):

  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current                                 Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0*   Trying 192.168.17.155...* TCP_NODELAY set* Connected to tfsserver (192.168.17.155) port 8080 (#0)* Server auth using NTLM with user ''> GET /tfs/DefaultCollection/code/_git/MyApp HTTP/1.1
> Host: tfsserver:8080
> Authorization: NTLM ***SCRUBBED***
> User-Agent: curl/7.60.0
> Accept: */*
> 
< HTTP/1.1 401 Unauthorized
< Content-Type: text/html; charset=us-ascii
< Server: Microsoft-HTTPAPI/2.0
< WWW-Authenticate: NTLM ***SCRUBBED***
< Date: Thu, 15 Nov 2018 23:07:58 GMT
< Content-Length: 341
< 
* Ignoring the response-body{ [341 bytes data]
100   341  100   341    0     0    642      0 --:--:-- --:--:-- --:--:--   642* Connection #0 to host tfsserver left intact* Issue another request to this URL: 'http://tfsserver:8080/tfs/DefaultCollection/code/_git/MyApp'* Found bundle for host tfsserver: 0x4116f20 [can pipeline]* Re-using existing connection! (#0) with host tfsserver* Connected to tfsserver (192.168.17.155) port 8080 (#0)* Server auth using NTLM with user ''> GET /tfs/DefaultCollection/code/_git/MyApp HTTP/1.1
> Host: tfsserver:8080
> Authorization: NTLM ***SCRUBBED***
> User-Agent: curl/7.60.0
> Accept: */*
> 
< HTTP/1.1 200 OK
< Cache-Control: no-cache, no-store, must-revalidate
< Pragma: no-cache
< Content-Type: text/html; charset=utf-8
< Expires: -1
< Server: Microsoft-IIS/8.5
< X-TFS-ProcessId: e5b67424-832f-468b-8787-c7c05aef5396
< ActivityId: 50f62941-8163-4ee9-9c2b-81359ca72838
< X-TFS-Session: 50f62941-8163-4ee9-9c2b-81359ca72838
< X-VSS-E2EID: 50f62941-8163-4ee9-9c2b-81359ca72838
< X-FRAME-OPTIONS: SAMEORIGIN
< X-VSS-UserData: 34be4ed8-c4fd-4e9f-bdae-d1843df36b0f:mkharitonov
< X-AspNetMvc-Version: 4.0
< X-AspNet-Version: 4.0.30319
< Set-Cookie: __RequestVerificationToken_L3Rmcw2=***SCRUBBED***; path=/; HttpOnly
< Set-Cookie: __RequestVerificationToken27563503a-8c73-4ee0-8930-e1f466b255f5=***SCRUBBED***; path=/; HttpOnly
< Persistent-Auth: true
< X-Powered-By: ASP.NET
< P3P: CP="CAO DSP COR ADMa DEV CONo TELo CUR PSA PSD TAI IVDo OUR SAMi BUS DEM NAV STA UNI COM INT PHY ONL FIN PUR LOC CNT"
< Lfs-Authenticate: NTLM
< X-Content-Type-Options: nosniff
< Date: Thu, 15 Nov 2018 23:07:58 GMT
< Content-Length: 120608
< 
{ [183 bytes data]
100  117k  100  117k    0     0   167k      0 --:--:-- --:--:-- --:--:--  167k* Connection #0 to host tfsserver left intact

我无法验证到底,但也许你应该设置http.emptyAuth to true在配置中(命令git config --global http.emptyAuth true)。至少在设置之后我的 git 2.19.1.windows.1 已经发送了Authorization: Negotiate ...标头到通告此协议的服务器。

底线:

git config --global http.emptyAuth true

如果 LFS 不在图中,则执行此操作。如果涉及 LFS,则在主机名前添加:@, e.g.

http://:@tfsserver:8080/tfs/DefaultCollection/code/_git/MyApp
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

是否可以使用默认的 Windows 凭据以非交互方式对远程 Git 存储库进行身份验证? 的相关文章

随机推荐

  • 检查数组中值的简写

    有一个简短的方法可以做到这一点吗 if isset a key a key value echo equal more code else echo not equal more code 我需要测试数组上可以存在或不存在的大量值 我觉得这
  • Android NDK Eclipse 构建错误:无法重命名文件。原因:文件存在

    我正在使用 Eclipse 和本机代码构建 Android 项目 95 的情况下这工作正常 但时不时地它会给出以下错误 make libs armeabi libnative so 错误 1 make 删除文件 libs armeabi l
  • 使用 taskkill /F 返回代码 0 终止进程

    我需要终止一个 Windows 进程 java exe 我目前正在使用 taskkill exe F IM java exe 我需要使用 F 选项 因为这是一个关键进程 但这样我得到返回代码 1 而不是我需要返回代码 0 当我不使用 F 杀
  • 在 Visual Studio 中自动创建处理程序签名

    在 c asp net 4 0 VS2015 中工作 我创建了一个用户控件 它只是一个下拉列表 其中包含用户可以传递给它的几个其他属性 以及一个事件和委托 当下拉列表更改时 会触发 OnSelectedIndexChanged 然后检查事件
  • 我的 ASP.NET MVC 应用程序结构是否正确?

    我已经阅读了教程 特别是使用 Linq To Entities 的教程 并且了解基本概念 但是有些事情给我带来了问题 这些教程通常只涉及简单的模型和表单 仅使用基本的创建 更新和删除语句 我的有点复杂 我不确定我是否以正确的方式处理这个问题
  • 提取数据库对象的代码或脚本

    我需要从所有函数 过程 包 视图和表中提取代码 脚本 以便当我转向生产时我可以运行脚本来创建所有对象 在开发过程中 我没有对所有数据库对象进行脚本备份 提取代码或脚本的最佳方法是什么 任何建议或帮助都非常值得赞赏 Thanks 您确实使用版
  • 我可以将值为“未定义”的字符串转换为实际的未定义吗?

    当我从前端发出 GET 请求时 我将几个查询参数应用于 URL 如下所示 let response await axios get products searchQuery this searchQuery categoryId this
  • 调用结构体的方法

    这段代码工作正常 feedService postgres FeedService feeds err feedService GetAllRssFeeds 但这段代码给了我错误 feeds err postgres FeedService
  • Bootstrap:向导航栏添加按钮组?

    添加一个是否足够容易btn group to navbar in bootstrap btn很好 但不太好 当btn group div 在Bootstrap3中 您可以添加一个navbar btn类给你的按钮让它们垂直对齐 即使在btn
  • Android中可以使用哪些编程语言进行开发? [复制]

    这个问题在这里已经有答案了 可能的重复 我可以在 Android Dalvik 上使用哪些编程语言 https stackoverflow com questions 1994703 which programming languages
  • 计算百分比Javascript

    我有一个关于 JavaScript 逻辑的问题 我用什么来从文本字段获取两个输入的百分比 这是我的代码 var pPos pointspossible val var pEarned pointsgiven val var perc pEa
  • R 中的部分合并

    在我最终达到 7之前r中数据帧之间的两两匹配 https stackoverflow com questions 12123013 two by two matching between dataframes in r是的 让我说我已经阅读
  • Android textview html 字体大小标签

    I use font size 4 android textview 中的标签像这样 resultTextView setText Html fromHtml font size 4 color 337744 Text Message fo
  • 突出显示缓冲区修改

    文件缓冲区经常被修改 废话 退出之前 emacs 会询问是否保存更改 现在了解到底发生了什么变化将会很有趣 有办法找出来吗 As of Emacs 22 1 at least save buffers kill emacs the defa
  • MigraDoc 表超出了第 2 页的标题?

    您好 我在 MigraDoc 中制作了一个大型表格 当表格对于页面而言太大时 它会自动拆分表格 我的页眉中有一个徽标 当我的表格转到第 2 页时 它位于徽标上方 而不是在徽标下方 有人知道如何确保它在移动到其他页面时消失吗 这是徽标代码 就
  • ModuleNotFoundError:没有名为“setuptools._distutils”的模块

    当我在 python 中安装以下包时遇到异常 pip install django microsoft auth 例外 ModuleNotFoundError No module named setuptools distutils 这里有
  • 为 Android 手机和平板电脑创建不同的布局

    这是一个基本的安卓问题 我的应用程序需要为手机和平板电脑提供不同的屏幕设计 手机需要有一个 ListView 平板电脑需要有一个项目的 GridView 我想知道如何在不制作两个不同的应用程序的情况下做到这一点 Thanks 基本上你必须为
  • C++ 控制台屏幕尺寸

    所以我在大学里学习了一些关于 C 的东西 我和老师就如何将文本实际居中到输出屏幕进行了讨论 所以我的建议是使用setw但得到字符串的长度和size在控制台屏幕上 进行算法和 BAM 我们就有了真正居中的文本 他说屏幕尺寸是80但屏幕可以调整
  • 清单文件无效

    我成功上传了扩展程序的新版本到 Chrome 应用程序 https chrome google com webstore detail producteev auto login dbmjalgigkhfhmckigghggodkafpfd
  • 是否可以使用默认的 Windows 凭据以非交互方式对远程 Git 存储库进行身份验证?

    我的远程 Git 存储库由本地 TFS 服务器托管 有两种方法可以访问其内容 使用 TFS Restful API https learn microsoft com en us rest api vsts git items get vi