我想将 EC2 实例限制为具有相同 namespace 的 EC2 容器注册表 (ECR) 存储库.
IAM 实例角色应该只能拉取 AWS_ACCOUNT_ID.dkr.ecr.REGION.amazonaws.com/test-namespace/...
下的所有存储库.没有其他的。
我已经在 EC2 实例角色上尝试了以下 IAM 策略:
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "Stmt1490955256000",
"Effect": "Allow",
"Action": [
"ecr:GetAuthorizationToken",
"ecr:BatchCheckLayerAvailability",
"ecr:GetDownloadUrlForLayer",
"ecr:GetRepositoryPolicy",
"ecr:DescribeRepositories",
"ecr:ListImages",
"ecr:DescribeImages",
"ecr:BatchGetImage"
],
"Resource": [
"arn:aws:ecr:REGION:AWS_ACCOUNT_ID:repository/test-namespace/*"
]
}
]
}
但我能够
docker pull
来自该实例上所有存储库的图像。例如。 AWS_ACCOUNT_ID.dkr.ecr.REGION.amazonaws.com/test-repo:latest
我看不出我做错了什么。不可能是 resource-level permissions .除了
ecr:GetAuthorizationToken
,以上所有 Action 都支持它们。 .由于我们有很多存储库,我不想在每个存储库上设置资源权限。
最佳答案
ecr:GetAuthorizationToken
不支持资源级权限。您需要授予 "Resource": "*"
到 ecr:GetAuthorizationToken
行动。其他操作可以限制为您希望访问的特定资源。
在政策中,这看起来像这样:
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "Stmt1490955256000",
"Effect": "Allow",
"Action": [
"ecr:GetAuthorizationToken",
],
"Resource": [
"*"
]
},
{
"Sid": "Stmt1490955256001",
"Effect": "Allow",
"Action": [
"ecr:BatchCheckLayerAvailability",
"ecr:GetDownloadUrlForLayer",
"ecr:GetRepositoryPolicy",
"ecr:DescribeRepositories",
"ecr:ListImages",
"ecr:DescribeImages",
"ecr:BatchGetImage"
],
"Resource": [
"arn:aws:ecr:REGION:AWS_ACCOUNT_ID:repository/test-namespace/*"
]
}
]
}
关于amazon-web-services - 限制对 ECR 中命名空间的访问,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43146730/