无法从我的 ECS 实例上的 AWS ECR 中提取图像
Not able to pull image from AWS ECR on my ECS instance
我是 运行 亚马逊的 ECS 实例提供 ECSInstance 角色,其在 JSON 中的策略如下所示:
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"ec2:DescribeTags",
"ecs:CreateCluster",
"ecs:DeregisterContainerInstance",
"ecs:DiscoverPollEndpoint",
"ecs:Poll",
"ecs:RegisterContainerInstance",
"ecs:StartTelemetrySession",
"ecs:UpdateContainerInstancesState",
"ecs:Submit*",
"ecr:GetAuthorizationToken",
"ecr:BatchCheckLayerAvailability",
"ecr:GetDownloadUrlForLayer",
"ecr:BatchGetImage",
"logs:CreateLogStream",
"logs:PutLogEvents"
],
"Resource": "*"
}
]
}
我可以看到 ECR 特定访问权限,其中包括 Submit* 和 "ecr:BatchGetImage"
等,使用它我应该能够简单地在我的 ECR 中提取任何图像但是当我尝试这样做时,它给我以下错误:
An error occurred (AccessDeniedException) when calling the
DescribeRepositories operation: User:
arn:aws:sts::755671380468:assumed-role/ecsInstanceRole/i-0e3a77458fe98d842
is not authorized to perform: ecr:DescribeRepositories on resource:
arn:aws:ecr:ap-south-1:755671380468:repository/*
现在,由于错误消息表明它没有 ecr:DescribeRepositories
,当我尝试添加内联策略并搜索 ecr
时,它没有给出任何结果,那么我如何才能将这个或其他一些策略添加到我现有的角色中,以便我的 ECS 实例能够下载图像并将其推送到 ECR?
您可以将以下 inline policy 添加到您的 ECSInstance
角色中,并查看它的运行情况:
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "VisualEditor0",
"Effect": "Allow",
"Action": "ecr:DescribeRepositories",
"Resource": "*"
}
]
}
或者,您可以使用任务执行角色。任务执行角色是执行 ECS 操作的 IAM 角色,例如拉取镜像和将应用程序日志存储在 CloudWatch 中。
您可以按照此link创建并附加任务执行角色 - https://docs.aws.amazon.com/AmazonECS/latest/developerguide/task_execution_IAM_role.html
我是 运行 亚马逊的 ECS 实例提供 ECSInstance 角色,其在 JSON 中的策略如下所示:
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"ec2:DescribeTags",
"ecs:CreateCluster",
"ecs:DeregisterContainerInstance",
"ecs:DiscoverPollEndpoint",
"ecs:Poll",
"ecs:RegisterContainerInstance",
"ecs:StartTelemetrySession",
"ecs:UpdateContainerInstancesState",
"ecs:Submit*",
"ecr:GetAuthorizationToken",
"ecr:BatchCheckLayerAvailability",
"ecr:GetDownloadUrlForLayer",
"ecr:BatchGetImage",
"logs:CreateLogStream",
"logs:PutLogEvents"
],
"Resource": "*"
}
]
}
我可以看到 ECR 特定访问权限,其中包括 Submit* 和 "ecr:BatchGetImage"
等,使用它我应该能够简单地在我的 ECR 中提取任何图像但是当我尝试这样做时,它给我以下错误:
An error occurred (AccessDeniedException) when calling the DescribeRepositories operation: User: arn:aws:sts::755671380468:assumed-role/ecsInstanceRole/i-0e3a77458fe98d842 is not authorized to perform: ecr:DescribeRepositories on resource: arn:aws:ecr:ap-south-1:755671380468:repository/*
现在,由于错误消息表明它没有 ecr:DescribeRepositories
,当我尝试添加内联策略并搜索 ecr
时,它没有给出任何结果,那么我如何才能将这个或其他一些策略添加到我现有的角色中,以便我的 ECS 实例能够下载图像并将其推送到 ECR?
您可以将以下 inline policy 添加到您的 ECSInstance
角色中,并查看它的运行情况:
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "VisualEditor0",
"Effect": "Allow",
"Action": "ecr:DescribeRepositories",
"Resource": "*"
}
]
}
或者,您可以使用任务执行角色。任务执行角色是执行 ECS 操作的 IAM 角色,例如拉取镜像和将应用程序日志存储在 CloudWatch 中。
您可以按照此link创建并附加任务执行角色 - https://docs.aws.amazon.com/AmazonECS/latest/developerguide/task_execution_IAM_role.html