针对AWS CodeCommits运行git clone会出现403错误

问题描述 投票:10回答:8

我的本地笔记本电脑是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.

`2.我创建了一个带有密码和访问密钥的IAM用户bruce666,使该用户成为“团队”组的一部分。然后我创建了一个包含“AWSCodeCommitPowerUsers”的策略,并将此策略分配给“团队”。最后将bruce666分配给“团队”。此时,bruce666可以通过管理控制台访问CodeCommit中的任何仓库。

  1. 我运行了aws config --profile bruce666,用他的访问和密钥,他的区域和json指定格式。此时,我能够通过运行aws codecommit get-repository --repository-name rekha --profile bruce666在CodeCommmit中创建rekha repo。
  2. 我可以创建几个虚拟文件,运行git init,git add。 ,git commit -m“1”,git add origin https://git-gitcode.amzonaws.com/repos/v1/rekha,git push -u origin master并且该操作将成功。
  3. 但是,当我运行git clone ssh://git-gitcode.amazonaws.com/repos/v1/rekha时,我得到“致命:无法访问'https://git-codecommit.us-east-1.amazonaws.com/v1/repos/barthia/':请求的URL返回错误:403”是什么给出的?
git amazon-web-services aws-codecommit
8个回答
17
投票

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

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

enter image description here

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

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


9
投票

在Windows中使用git push命令时,我也遇到同样的403错误。我完成了AWS文档中提到的所有设置,但未解决我的问题。之后我通过Windows Credential查看了git凭证集,如屏幕所示。我找到了代替git https凭据,它设置了访问密钥/密钥(不知道如何)。

enter image description here

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


4
投票

This helpful text is found on the AWS documentation for codecommit and Windows integration

如果您安装的Git for Windows包含Git凭据管理器实用程序,则在前几次连接尝试后,您将看到403错误或提示以向凭证管理器实用程序提供凭据。解决此问题的最可靠方法是在没有Git凭据管理器实用程序选项的情况下卸载然后重新安装Git for Windows,因为它与AWS CodeCommit不兼容。

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

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

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

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

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

最后一部分适用于我的情况,虽然当我运行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'."

3
投票

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

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

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


2
投票

我解决了

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,因为我没有遇到任何工具链问题。


2
投票

我在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  [email protected]
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

第一行之前没有出现,git正在使用osxkeychain优先。因此,我不得不做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。所以它可以(应该)添加在[凭证]下


1
投票

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

它发生在以下地区

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

配置

  1. 确保存储库存在于那里。

0
投票

以下解决方案适用于在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

© www.soinside.com 2019 - 2024. All rights reserved.