60

我的本地笔记本电脑是 Mac。

  1. ssh 密钥配置正确。这是 ~/.ssh/config 的内容
Host barthea
Hostname git-codecommit.us-east-1.amazonaws.com
User AVVVVVVVVVVVVVVVVVQ
IdentityFile ~/.ssh/aws-aws.pem

运行 ssh barthea 让我

You have successfully authenticated over SSH. You can use Git to interact with AWS CodeCommit. Interactive shells are not supported.Connection to git-codecommit.us-east-1.amazonaws.com closed by remote host.
  1. 我创建了一个带有密码和访问密钥的 IAM 用户 bruce666,使该用户成为“团队”组的一部分。然后我创建了一个包含“AWSCodeCommitPowerUsers”的策略并将该策略分配给“团队”。最后将 bruce666 分配给“团队”。此时,bruce666 可以通过管理控制台访问 CodeCommit 中的任何存储库。

  2. 我运行aws config --profile bruce666,输入他的访问和密钥、他的区域并在 json 中指定格式。此时,我能够通过运行aws codecommit get-repository --repository-name rekha --profile bruce666在 CodeCommmit 中创建 rekha 存储库

  3. 我可以创建几个虚拟文件,运行git initgit add 。, git commit -m "1" , git add origin https://git-gitcode.amzonaws.com/repos/v1/rekha , git push -u origin master这样操作就成功了。

  4. 但是,当我运行git clone ssh://git-gitcode.amazonaws.com/repos/v1/rekha时,我得到“致命:无法访问'https://git-codecommit.us-east-1.amazonaws。 com/v1/repos/barthia/':请求的 URL 返回错误:403“什么给出?

4

15 回答 15

86

在 MAC 上,如果上述技巧不起作用,请执行以下操作:

  1. 打开钥匙串访问
  2. 搜索 CodeCommit。你应该找到这个:

在此处输入图像描述

  1. 选择“git-codecommit ....”并按删除
  2. 确认删除。

现在再试一次。它应该工作。下次遇到错误 403 时,您可能还需要再次执行此操作。

此问题的一个可能原因是钥匙串密码与 MAC 上的登录密码不同。

于 2018-11-11T05:46:42.437 回答
47

在 Windows 中使用 git push 命令时,我也面临同样的 403 错误。我完成了 AWS 文档中提到的所有设置,但没有解决我的问题。在我通过 Windows 凭据查看 git 凭据集后,如屏幕所示。我发现它不是 git https 凭据,而是设置访问密钥/秘密密钥(不知道如何)。

在此处输入图像描述

单击编辑链接,使用为 AWS 用户生成的正确 git 凭证更新凭证,一切正常。

于 2017-03-24T22:49:40.070 回答
13

此有用文本可在 AWS 文档中找到,用于 codecommit 和 Windows 集成

如果您安装的适用于 Windows 的 Git 包含 Git Credential Manager 实用程序,您将在前几次连接尝试后看到 403 错误或提示您向 Credential Manager 实用程序提供凭据。解决此问题的最可靠方法是卸载并重新安装适用于 Windows 的 Git,而不使用 Git Credential Manager 实用程序选项,因为它与 AWS CodeCommit 不兼容。

如果您想保留 Git Credential Manager 实用程序,则必须执行额外的配置步骤才能使用 AWS CodeCommit,包括手动修改 .gitconfig 文件以指定在连接到 AWS CodeCommit 时使用 AWS CodeCommit 的凭证帮助程序。

从凭据管理器实用程序中删除所有存储的凭据(您可以在控制面板中找到此实用程序)。

删除任何存储的凭据后,将以下内容添加到 .gitconfig 文件中,保存它,然后尝试从新的命令提示符窗口再次连接:

[credential "https://git-codecommit.us-east-1.amazonaws.com"]
    helper = !aws codecommit credential-helper $@
    UseHttpPath = true

此外,在所有连接按预期工作之前,您可能必须通过指定 --system 而不是 --global 或 --local 来重新配置 git config 设置。

最后一部分适用于我的情况,尽管当我运行 git config --system 时它没有按预期运行,而是在 aws codecommit 命令之前附加了 aws configure 。

所以我不得不在 git 中运行它来找到系统配置文件的位置。

git config --list --show-origin

然后,我将 AWS 的建议部分添加到我的 c:/users/username/.gitconfig 和我的 c:/ProgramData/Git/config 文件中。

在那之后 git push 开始工作 - 即使我在我的回复之前得到了虚假错误

"git: 'credential-aws' is not a git command. See 'git --help'."
于 2016-07-27T16:20:21.830 回答
7

运行以下命令后,我必须将以下提到的策略添加到我的 IAM 用户以解决此问题。参考

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

政策:

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Effect": "Allow",
            "Action": [
                "codecommit:*"
            ],
            "Resource": "*"
        }
    ]
}
于 2019-08-16T00:49:49.243 回答
6

我解决了。

403 错误消息是专门的 Git 错误消息。我添加了两个 AWS 指定的辅助命令:

git config --global credential.helper '!aws --profile bruce666 codecommit credential-helper $@'
git config --global credentials.helper UseHttpPath=true

这解决了这个问题。

本地目录中的.git/config文件(在克隆刚刚创建的 Codecommit 存储库之前应该如下所示:

[core]
    repositoryformatversion = 0
    filemode = true
    bare = false
    logallrefupdates = true
    ignorecase = true
    precomposeunicode = false
[credential]
    helper = !aws --profile bruce666 codecommit credential-helper $@
    UseHttpPath = true
[remote "origin"]
    url = https://git-codecommit.us-east-1.amazonaws.com/v1/repos/barthea
    fetch = +refs/heads/*:refs/remotes/origin/*
[branch "master"]
    remote = origin
    merge = refs/heads/master

正如.git/config文件中所指定的,您正在使用 https 而不是 ssh 进行克隆。我一定没有使用 OSX 附带的默认版本的 git,因为我没有遇到任何工具链问题。

于 2015-12-30T12:48:37.127 回答
3

我在 OSX 中的情况。

第一步:

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

然而,验证git config --list --show-origin

file:/usr/local/etc/gitconfig   credential.https://git-codecommit.eu-west-1.amazonaws.com.helper=!aws codecommit credential-helper $@
file:/usr/local/etc/gitconfig   credential.helper=osxkeychain
file:/Users/mine/.gitconfig  user.name=my-user
file:/Users/mine/.gitconfig  user.email=my@gmail.com
file:/Users/mine/.gitconfig  filter.lfs.clean=git-lfs clean -- %f
file:/Users/mine/.gitconfig  filter.lfs.smudge=git-lfs smudge -- %f
file:/Users/mine/.gitconfig  filter.lfs.process=git-lfs filter-process
file:/Users/mine/.gitconfig  filter.lfs.required=true
file:/Users/mine/.gitconfig  credential.helper=!aws codecommit credential-helper $@
file:/Users/mine/.gitconfig  credential.usehttppath=true

第一行以前不存在,并且 gitosxkeychain优先使用。因此,我不得不做git config --system ...

cat /usr/local/etc/gitconfig                                             
[credential "https://git-codecommit.eu-west-1.amazonaws.com"]
    helper = !aws codecommit credential-helper $@
    UseHttpPath = true
[credential]
    helper = osxkeychain

因此,指定 URL 是为了在存储另一个凭据时回退。

更新 https://docs.aws.amazon.com/codecommit/latest/userguide/troubleshooting-ch.html

出于某种原因,有时似乎没有添加UseHttpPath = true 。所以它可以(应该)添加到 [credential] 下

于 2018-06-27T10:16:54.697 回答
3

对我来说,得到错误的根本原因是无论我在 OSX 上使用哪个版本的 git,GIT 总是从文件中获取使用 osxkeychain 的 credential.helper 配置:

/Applications/Xcode.app/Contents/Developer/usr/share/git-core/gitconfig

摆脱这个解决了我的问题并且没有破坏任何东西。

于 2017-03-02T12:36:57.957 回答
1

致命:无法访问“ https://git-codecommit.yourregion.amazonaws.com/v1/yourrepositoryname/ ”:请求的 URL 返回错误:403

它是由于以下区域而发生的

  1. 确保您的用户codecommitfullaccess附加了策略。
  2. 确保本地 aws cli 配置中的默认区域和创建存储库的区域相同。如果未在 aws cli 命令中重置默认区域,如下所示

aws 配置

  1. 确保那里是否存在存储库。
于 2019-06-05T15:33:49.227 回答
1

问题(在 Ubuntu 上)

$ git clone https://git-codecommit.ap-southeast-1.amazonaws.com/v1/repos/xx
克隆到 'xx'...
致命:无法访问 'https://git-codecommit.ap- Southeast-1.amazonaws.com/v1/repos/xx/':请求的 URL 返回错误:403

解决方案:

步骤1:

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

查看:

cat ~/.gitconfig 
[user]
    email = your-email
    name = your-name
[credential]
    helper = !aws codecommit credential-helper $@
    UseHttpPath = true

第2步:

  1. 服务 > IAM
  2. 单击用户(左侧面板)
  3. 点击您的用户名(主面板)
  4. 点击Add permissions
  5. 点击Attach existing policies directly
  6. Filter policies,键入AWSCodeCommitFullAccess
  7. 选中策略旁边的复选框,然后单击Next: Review
  8. 点击Add permissions

结果

$ git clone https://git-codecommit.ap-southeast-1.amazonaws.com/v1/repos/xx
克隆到'xx'...
远程:计数对象:3,完成。
拆包对象:100% (3/3),223 字节 | 223.00 KiB/s,完成。

参考

  1. Git 和 AWS CodeCommit 入门
于 2021-06-16T02:13:59.830 回答
1

以下解决方案适用于少数在 Windows 10 上使用 Git Bash 的开发人员。

如果您在“连接到您的存储库”选项卡上选择 Windows 作为您的操作系统,则命令格式如下:

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

但是,如果您使用 Git Bash,请选择“Linux、MacOS 或 Unix”选项。注意第一行的单引号而不是双引号。

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

祝你好运。

参考: https ://forums.aws.amazon.com/thread.jspa?threadID= 198356 发布者:mwhardesty

于 2019-03-19T05:41:38.130 回答
0

就我而言,我遇到了权限问题。

您需要将AWSCodeCommitFullAccess 策略附加到您的 IAM 用户以授予您对 CodeCommit 的访问权限。

在此处输入图像描述

于 2020-12-26T14:57:11.480 回答
0

我的默认 aws 凭据有问题,我在aws configure没有配置文件的情况下再次运行,重新启动终端并且它工作。

于 2020-07-23T14:22:25.813 回答
0

对我来说,唯一可行的选项是使用带有 HTTPS (GRC) 选项的 git clone,该选项提供的 URL 开头为:

git clone codecommit::
于 2021-10-28T08:21:42.933 回答
0

每当它在尝试从 AWS 克隆或提取代码时要求输入用户名和密码时,而不是通过键入每个字母来手动输入密码,而不是复制密码。这解决了我的问题。

于 2020-11-10T07:02:48.550 回答
0

您需要确保您的 AWS 凭证不仅具有访问 CodeCommit 的权限,而且还没有附加一揽子拒绝策略。在我们的组织中,我们要求对所有控制台帐户进行 MFA,这确实会导致编程访问出现问题。

一个好的解决方案(如果这是您的问题)是创建另一个没有控制台访问权限的 IAM 用户,并直接附加 codecommit 策略(在我们的例子中,MFA 全面拒绝来自用户所属的 IAM 组)。

澄清:这个答案适用于当您使用 IAM 凭证和 CodeCommit Git 扩展(而不是 IAM Git 凭证)时,尽管我怀疑在这种情况下也是如此。

于 2020-09-18T22:29:39.090 回答