我有两个帐户,a1
和a2
。
我在 a1 中有一个 EC2 实例,a1.ec2
. 它在该帐户中扮演某种角色,a1.r
. 此角色对所有 ECR 操作具有完全访问权限。
现在,我有一个映像注册表 (ECR),a2
并且希望能够从a1.ec2
.
所以,我 ssh 进入那个实例,为了测试我运行的访问
aws ecr describe-repositories --region <my-region> --registry-id <id of a2>
但我得到了错误
An error occurred (AccessDeniedException) when calling the DescribeRepositories operation: User: arn:aws:sts::<id of a1>:assumed-role/a1.r/i-075fad654b998275c is not authorized to perform: ecr:DescribeRepositories on resource: arn:aws:ecr:*:*:repository/*
但是,这个权限确实是授予角色的a1.r
。我通过能够a1
很好地访问 ECR 来验证这一点。
另外,我喜欢访问的 ECR 有以下权限策略,所以我确保问题不是由 ECR 引起的a2
:
{
"Sid": "new statement",
"Effect": "Allow",
"Principal": {
"AWS": "arn:aws:iam::<id of a1>:root"
},
"Action": "*"
},
{
"Sid": "new statement",
"Effect": "Allow",
"Principal": {
"AWS": "arn:aws:iam::<id of a1>:role/a1.r"
},
"Action": "*"
}
我查看了https://serverfault.com/questions/897392/ecr-cross-account-pull-permissions,其中的解决方案似乎是创建跨账户角色。尽管我可以创建这样的角色a2.cross-acc-r
,但我无法弄清楚如何为aws ecr
cli 命令承担该角色。我不希望 EC2 实例承担该角色,因为它驻留在不同的账户中(甚至不确定这是否可能)。
我是否缺乏有关 AWS IAM 工作原理的基本知识?