1

我正在尝试将 AWS CodeCommit 用于我的存储库。对于那些不知道的人,CC 需要一个特定的 git 凭证助手来生成 HTTPS 请求的密码,因为它是加密的和基于时间的。这正常工作。

但是,我确实有一个更严重的问题:git 似乎会自动在 Keychain 中缓存我对时间敏感的凭据,这意味着在 15 分钟左右后,我只会在推送或获取时收到 403 错误。

我尝试按照此处的说明进行操作,但我没有在osxkeychain任何地方进行配置。据我所知,它被硬编码到 Apple git 中。

这是git显示问题的一对痕迹:

初始提取

MikeBook-Pro:sensei-cli mike$ GIT_TRACE=1 git fetch
13:43:19.583664 git.c:348 跟踪:内置:git 'fetch'
13:43:19.584764 run-command.c:347 跟踪:run_command:'git-remote-https''origin''https://git-codecommit.us-east-1.amazonaws.com/v1/repos/sensei -cli'
13:43:20.024288 run-command.c:347 跟踪:run_command:'git credential-osxkeychain get'
13:43:20.025203 run-command.c:195 trace: exec: '/bin/sh' '-c' 'git credential-osxkeychain get' 'git credential-osxkeychain get'
13:43:20.029429 git.c:557 跟踪:执行:'git-credential-osxkeychain''get'

# 最后一个命令什么也不返回,因为钥匙串里什么都没有。
13:43:20.029928 run-command.c:347 跟踪:run_command:'git-credential-osxkeychain''get'
13:43:21.016738 run-command.c:347 trace: run_command: 'aws --profile default codecommit credential-helper $@ get'

# 这将返回正确生成的凭据
13:43:21.018020 run-command.c:195 trace: exec: '/bin/sh' '-c' 'aws --profile default codecommit credential-helper $@ get' 'aws --profile default codecommit credential-helper $@得到'
13:43:21.985711 run-command.c:347 跟踪:run_command:'git credential-osxkeychain store'

# 这会将凭证存储在钥匙串中
13:43:21.986731 run-command.c:195 trace: exec: '/bin/sh' '-c' 'git credential-osxkeychain store' 'git credential-osxkeychain store'
13:43:21.991811 git.c:557 跟踪:执行:'git-credential-osxkeychain''存储'
13:43:21.992266 run-command.c:347 跟踪:run_command:'git-credential-osxkeychain''store'13:43:22.017201 run-command.c:347 跟踪:run_command:'aws --profile 默认代码提交凭证-helper $@ store'
13:43:22.017897 run-command.c:195 trace: exec: '/bin/sh' '-c' 'aws --profile default codecommit credential-helper $@ store' 'aws --profile default codecommit credential-helper $@商店'
13:43:22.302123 run-command.c:347 跟踪:run_command:'rev-list''--objects''--stdin''--not''--all''--quiet'
...

后续提取

MikeBook-Pro:sensei-cli mike$ GIT_TRACE=1 git fetch
13:53:51.224971 git.c:348 跟踪:内置:git 'fetch'
13:53:51.231140 run-command.c:347 跟踪:run_command:'git-remote-https''origin''https://git-codecommit.us-east-1.amazonaws.com/v1/repos/sensei -cli'
13:53:53.855917 run-command.c:347 跟踪:run_command:'git credential-osxkeychain get'
13:53:53.859291 run-command.c:195 trace: exec: '/bin/sh' '-c' 'git credential-osxkeychain get' 'git credential-osxkeychain get'
13:53:53.876895 git.c:557 跟踪:执行:'git-credential-osxkeychain''get'

# 这确实返回凭据,所以它不会尝试任何帮助程序
13:53:53.877419 run-command.c:347 跟踪:run_command:'git-credential-osxkeychain''get'
致命:无法访问“https://git-codecommit.us-east-1.amazonaws.com/v1/repos/sensei-cli/”:请求的 URL 返回错误:403

git --versiongit config -l输出

MikeBook-Pro:sensei-cli mike$ git --version
git 版本 2.4.9 (Apple Git-60)
MikeBook-Pro:sensei-cli mike$ git config -l
user.name=迈克·卡隆
user.email=myemail@domain.com
credential.helper=!aws --profile 默认代码提交 credential-helper $@
credential.usehttppath=true
core.repositoryformatversion=0
core.filemode=true
core.bare=false
core.logallrefupdates=true
core.ignorecase=true
core.precomposeunicode=true
remote.origin.url=https://git-codecommit.us-east-1.amazonaws.com/v1/repos/sensei-cli
remote.origin.fetch=+refs/heads/*:refs/remotes/origin/*
branch.master.remote=起源
branch.master.merge=refs/heads/master
4

4 回答 4

3

我刚刚使用以下方法破解了它:

git config --global credential.helper '!security delete-internet-password -l "git-codecommit.us-east-1.amazonaws.com"; aws codecommit credential-helper $@'

希望能帮助到你,

于 2016-04-06T16:09:16.400 回答
1

是的,它是硬编码的,可以osxkeychain在他们的 Apple-Git 实现中使用。源代码参考雷达错误 12266645。

我相信许多后续的雷达错误都是由这个非常错误的决定造成的。我建议你也打开一个!

于 2015-11-03T21:35:17.793 回答
1

我遇到了同样的问题,我发现的唯一解决方法是在终端中继续删除钥匙串密码条目,如下所示:

security delete-internet-password -l "git-codecommit.us-east-1.amazonaws.com"

我将它添加到每五分钟运行一次的 cron 作业中。

绝对不是最优雅的解决方案,但可以帮助我建立联系。希望这会有所帮助。

于 2016-03-07T13:47:48.230 回答
0

这类似于Pablo 的回答,但我使用的是git credential-osxkeychain erase实用程序,它接受输入,stdin所以有点长。因此,凭证助手行.gitconfig最终如下:

[credential]
    helper = !printf 'host=%s\nprotocol=https\n\n' 'git-codecommit.us-east-2.amazonaws.com' | git credential-osxkeychain erase && aws codecommit credential-helper $@

基本思想是,它在创建钥匙串后立即擦除钥匙串中的钥匙。

于 2017-07-25T22:06:34.283 回答