Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AWS ECR CF template fails with 'Invalid repository policy provided'

This CF template fails:

  MyECSrepo:
    Type: "AWS::ECR::Repository"
    Properties:
      RepositoryName: !Ref RepoName
      RepositoryPolicyText:
        Version: "2012-10-17"
        Statement:
          - Sid: AllowAll
            Effect: Allow
            Principal: 
              AWS:
                - arn:aws:iam::00000000000:group/admin
            Action:
          - "ecr:*"

The stack creation produces this error:

Invalid parameter at 'PolicyText' failed to satisfy constraint: 'Invalid repository policy provided'

What might the problem be?

like image 485
Neil H Watson Avatar asked Sep 01 '17 13:09

Neil H Watson


People also ask

What is an AWS ECR repository?

Amazon Elastic Container Registry (Amazon ECR) is an AWS managed container image registry service that is secure, scalable, and reliable. Amazon ECR supports private repositories with resource-based permissions using AWS IAM.

What is ECR template?

Embedded Crystal (ECR) is a template language for embedding Crystal code into other text, that includes but is not limited to HTML. The template is read and transformed at compile time and then embedded into the binary.

Is not authorized to perform ECR Getauthorizationtoken?

The error can have a few meanings: You are not authorized because you do not have ECR policy attached to your user. You are not authorized because you are using 2FA and using cli is not secure unless you set a temporary session token. You provided invalid credentials.


2 Answers

Having a read of the documentation around ECR Repository Policy, it turns out it's limited to users and root accounts for the Principal list. So you will probably need to swap out to listing all the users you want to give access to.

Amazon documentation has some samples has some examples of what you can do with it.

like image 119
Neil Bostrom Avatar answered Nov 15 '22 07:11

Neil Bostrom


Just in case duke of muppets link breaks, here is an example. I had trouble today with the automatically created json. This seemed to fix it.

    {
      "Version": "2008-10-17",
      "Statement": [
        {
          "Sid": "AllowPushPull",
          "Effect": "Allow",
          "Principal": {
            "AWS": "arn:aws:iam::<<id number of root user here>>:user/<<some iam user>>"
          },
          "Action": [
            "ecr:BatchCheckLayerAvailability",
            "ecr:BatchGetImage",
            "ecr:CompleteLayerUpload",
            "ecr:GetDownloadUrlForLayer",
            "ecr:InitiateLayerUpload",
            "ecr:PutImage",
            "ecr:UploadLayerPart"
          ]
    }
  ]
}
like image 21
andrew pate Avatar answered Nov 15 '22 06:11

andrew pate