【问题标题】:Git CodeCommit credentials keep ending up in Keychain Access on Mac OS XGit CodeCommit 凭证不断出现在 Mac OS X 上的 Keychain Access 中
【发布时间】:2020-02-14 01:30:16
【问题描述】:

在执行以下操作以使用 git 在 AWS 上设置我的 CodeCommit 存储库后:

$ git config --global credential.helper '!aws codecommit credential-helper $@'
$ git config --global credential.UseHttpPath true

我只能进行一次提交,然后我必须像这样从 Keychain Access 中删除它:

这太烦人了。任何人都知道如何防止 Mac OS X 将其添加到每个 git push 的钥匙串中?

【问题讨论】:

    标签: git macos aws-codecommit


    【解决方案1】:

    以下是一些避免钥匙串干扰的选项:

    • 为 git 禁用 osxkeychain:

      $ nano /usr/local/git/etc/gitconfig
      # helper = osxkeychain <======== Comment out using #
      
    • 使用 SSH 而不是 HTTPS 连接到 CodeCommit。有关详细信息,请参阅 Linux、macOS 或 Unix 上的 SSH 连接 [1]。

    • 安装默认不使用钥匙串的 Git 版本。

    • 考虑使用脚本解决方案来删除钥匙串项。要查看社区生成的脚本解决方案示例,请参阅 Mac OS X 脚本以定期删除产品和服务集成中 OS X 证书存储中的缓存凭据 [2]。

    • 在钥匙串访问实用程序中,在 git-codecommit.us-east-2.amazonaws.com 的访问控制选项卡上,选择允许所有应用程序访问此项目(访问此项目不受限制)选项。这可以防止弹出窗口,但凭据最终会过期(平均而言,这需要大约 15 分钟),然后您会看到 403 错误消息。发生这种情况时,您必须删除钥匙串项才能恢复功能。

    有关 AWS Docs 中上述选项的更多信息:[3]

    [1]https://docs.aws.amazon.com/codecommit/latest/userguide/setting-up-ssh-unixes.html

    [2]https://github.com/nicc777/macaws-codecommit-pwdel

    [3] 对凭据帮助程序和与 AWS CodeCommit 的 HTTPS 连接进行故障排除 - 适用于 macOS 的 Git:我成功配置了凭据帮助程序,但现在我被拒绝访问我的存储库 (403) - https://docs.aws.amazon.com/codecommit/latest/userguide/troubleshooting-ch.html#troubleshooting-macoshttps

    【讨论】:

    • 对于您的第一个选项,该文件对我来说不存在? stat: /usr/local/git/etc/gitconfig: stat: No such file or directory。但这些都是很好的链接,谢谢!我将不得不研究 SSH 一个,这可能是唯一可口的一个(安装一些可以触及我的钥匙串的随机代码对我来说是不行的......)。
    • @lollercoaster 你可能会在$HOME/.gitconfig下找到那个文件
    【解决方案2】:

    对我来说,这个问题的发生更多是因为 AWS SSO 具有短暂的访问密钥,当您需要 github 来处理某些项目而需要 codecommit 来处理其他项目时也是如此。

    对我来说,解决方案是将 git 配置为将 oskeychain 用于 github,而不是将其用于 codecommit..

    # identify location of git config file with credential.helper**
    git config -l --show-origin
       > file:/<path>/git-core/gitconfig    credential.helper=osxkeychain
    
    # edit the file as root 
    sudo vi <path-from-above>
    
    # add github in the credential line so oskeychain not used for other sites
    [credential "https://github.com"]
        helper = osxkeychain
    

    【讨论】:

    • 很好,这对我来说非常有效。我用git config --get-all --show-origin credential.helper找到了文件,然后按照你的回答,谢谢!
    • 如果你已经通过 homebrew 安装了 git,你需要更新 /opt/homebrew/etc/gitconfig 中的 gitconfig。 @SaurabhShrivastava 提到的脚本将显示文件路径。
    猜你喜欢
    • 2016-01-29
    • 2010-12-26
    • 1970-01-01
    • 2011-10-12
    • 1970-01-01
    • 1970-01-01
    • 2012-03-01
    • 2012-10-31
    • 2015-04-02
    相关资源
    最近更新 更多