[英]AWS cross account access to CodeCommit repo with roles only (no static credentials)
我在AWS帐户1111中有一个CodeCommit REPO1。我需要在EC2实例中克隆REPO1,该实例将在AWS帐户2222中启动并定期终止。启动EC2是为了在短时间内(几分钟)执行一些批处理作业,然后以自动方式终止。
在不生成静态证书的情况下,我如何使用角色在2222中启动EC2实例,从1111克隆REPO1。必须使用bash / CLI使该过程自动化。
几天来,我一直把头撞在桌子上,无济于事。
您需要在帐户1111中创建一个角色(R1):
然后,您需要确保EC2实例的实例角色具有AssumeRole权限。 这使您可以从EC2实例中假设R1。
现在,在帐户2222中的EC2实例中,您应该设置一个通过角色访问REPO1的配置文件。 为此,您可以在〜/ .aws / config文件中添加类似于以下内容的内容:
[profile cross-account-role]
role_arn = arn:aws:iam::<1111>:role/<R1>
credential_source = Ec2InstanceMetadata
external_id = <ExternalId of R1>
output = json
region = <Region where REPO1 is>
然后,您要确认是否正确设置了权限,可以执行以下操作:
aws --profile cross-account-role get-repository --repository-name REPO1
一旦完成,您要配置git客户端,使其在~/.gitconfig
通过正确的配置文件使用credential-helper, ~/.gitconfig
是运行:
git config --global credential.helper '!aws codecommit --profile cross-account-role credential-helper $@'
git config --global credential.UseHttpPath true
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.