How to Give Read-Only Access to ECR Repo for One User

amazon-ecramazon-web-services

How can I give a_user read-only access (i.e. no permission to Push) and b_user is not banned?

What I have done so far:

  • Added my AWS access + secret key with aws configure

  • Made an ECR repo and did the aws ecr get-login ... command to get my login

  • Added a permission that does:

    Deny, Principal: my_principal_id, IAM: a_user, Push

  • Tried docker Push and it explicitly denies me despite being b_user (permission only bans a_user?)

Best Answer

That may be better achieved through IAM Policy for the User instead of doing it on the ECR repo level.

Try this as a IAM policy for a_user (read-only):

    {
        "Version": "2012-10-17",
        "Statement": [
            {
                "Effect": "Allow",
                "Action": [
                    "ecr:Get*",
                    "ecr:List*",
                    "ecr:Describe*",
                    "ecr:BatchGetImage",
                    "ecr:BatchCheckLayerAvailability"
                ],
                "Resource": "arn:aws:ecr:*:*:repository/test"
            },
            {
                "Effect": "Allow",
                "Action": "ecr:GetAuthorizationToken",
                "Resource": "*"
            }
        ]
    }

And this as a policy for b_user (read-write):

    {
        "Version": "2012-10-17",
        "Statement": [
            {
                "Effect": "Allow",
                "Action": [
                    "ecr:*"
                ],
                "Resource": "arn:aws:ecr:*:*:repository/test"
            },
            {
                "Effect": "Allow",
                "Action": "ecr:GetAuthorizationToken",
                "Resource": "*"
            }
        ]
    }

Hope that helps :)