AWS IAM 用户在访问 ECR 存储库时收到 401,与根用户一起使用

AWS IAM user receive 401 when accessing to ECR repository, works with root user

我已经开始使用 AWS ECR 来存储我的 docker 图片。当我尝试通过 Powershell 对 IAM 用户进行身份验证时(当我通过 AWS 命令​​行执行时也会发生同样的情况)我收到 401:UnAuthorized。 如果我使用 root 用户的 Auth key/secret,它可以工作并进行身份验证。

我使用的PowerShell脚本是

(Get-ECRLoginCommand).Password | docker login --username AWS --password-stdin 474389077978.dkr.ecr.eu-west-3.amazonaws.com/myreoi

我已将 AWS 用户替换为 IAM 用户。我也将 IAM 用户添加到管理员,但似乎还不够。

有什么建议吗? 谢谢

必须为 IAM 用户分配角色才能访问 ECR 服务。这可以通过在组的权限部分添加内联策略来完成。

请按照以下步骤执行使用非根 IAM 用户可以执行 docker ecr 操作。

1.) Create IAM user say "ecr-user". 
2.) Create IAM group called "ecr-group".
3.) Add user ecr-user to ecr-group.
4.) Create a role "ecr-role"
5.) Attach the policy name "AmazonEC2ContainerServiceRole" to the role ecr-role.

6.) Go in the group section of the AWS console.
7.) Select the group "ecr-group" and go to the permission tab.
    Add policy - "AmazonEC2ContainerServiceRole" using attach policy button. 
8.) "Click here" in the inline policy section of the permission tab.
9.) Choose custom policy.
10.) Choose a name for custom policy - "ecr-passon"
11.) Add policy json given above - ensure to change your account id.

{
"Version": "2012-10-17",
"Statement": [{
    "Effect": "Allow",
    "Action": [
        "iam:GetRole",
        "iam:PassRole"
    ],
    "Resource": "arn:aws:iam::<account-id>:role/ecr-role"
}]}

所有这些步骤都会将角色 ecr-role 附加到具有策略 AmazonEC2ContainerServiceRole 的组 ecr-group 的 ecr-user。

AWS 编程 IAM 用户必须担任角色才能执行某些操作。

使用参考资料了解传球角色。 Pass a Role to an AWS Service