Skip to content
IAM Policy Generator

IAM policy example: push images to one ECR repository, with a least privilege rewrite

Allows a build role to push images to one repository, web-app, with the upload and layer actions a push uses. The AWS documentation lists these actions. The original puts them on every repository in the account. The names and the account ID 111122223333 are AWS documentation placeholders.

Open the workbench ยท All examples

{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Sid": "Login",
      "Effect": "Allow",
      "Action": "ecr:GetAuthorizationToken",
      "Resource": "*"
    },
    {
      "Sid": "Push",
      "Effect": "Allow",
      "Action": [
        "ecr:BatchCheckLayerAvailability",
        "ecr:InitiateLayerUpload",
        "ecr:UploadLayerPart",
        "ecr:CompleteLayerUpload",
        "ecr:PutImage"
      ],
      "Resource": "arn:aws:ecr:us-east-1:111122223333:repository/*"
    }
  ]
}

What it allows

  • Allows login, then pushing images to any repository in one Region.

What it allows

  1. Allow 1 action (ecr:GetAuthorizationToken) on every resource.

    Action or patternActionsAccess levels
    ecr:GetAuthorizationToken1Read 1
  2. Allow 5 actions (ecr:BatchCheckLayerAvailability, ecr:InitiateLayerUpload, ecr:UploadLayerPart, ecr:CompleteLayerUpload, ecr:PutImage) on arn:aws:ecr:us-east-1:111122223333:repository/*.

    Action or patternActionsAccess levels
    ecr:BatchCheckLayerAvailability1Read 1
    ecr:InitiateLayerUpload1Write 1
    ecr:UploadLayerPart1Write 1
    ecr:CompleteLayerUpload1Write 1
    ecr:PutImage1Write 1

Checks

No flags from the six checks.

A build job could overwrite an image in a repository that production services pull from.

Least privilege rewrite

{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Sid": "Login",
      "Effect": "Allow",
      "Action": "ecr:GetAuthorizationToken",
      "Resource": "*"
    },
    {
      "Sid": "PushOne",
      "Effect": "Allow",
      "Action": [
        "ecr:BatchCheckLayerAvailability",
        "ecr:InitiateLayerUpload",
        "ecr:UploadLayerPart",
        "ecr:CompleteLayerUpload",
        "ecr:PutImage"
      ],
      "Resource": "arn:aws:ecr:us-east-1:111122223333:repository/web-app"
    }
  ]
}

The rewrite replaces the repository wildcard with one repository ARN. The build job can push only to web-app.

What it allows

  1. Allow 1 action (ecr:GetAuthorizationToken) on every resource.

    Action or patternActionsAccess levels
    ecr:GetAuthorizationToken1Read 1
  2. Allow 5 actions (ecr:BatchCheckLayerAvailability, ecr:InitiateLayerUpload, ecr:UploadLayerPart, ecr:CompleteLayerUpload, ecr:PutImage) on arn:aws:ecr:us-east-1:111122223333:repository/web-app.

    Action or patternActionsAccess levels
    ecr:BatchCheckLayerAvailability1Read 1
    ecr:InitiateLayerUpload1Write 1
    ecr:UploadLayerPart1Write 1
    ecr:CompleteLayerUpload1Write 1
    ecr:PutImage1Write 1

Checks

No flags from the six checks.

Sources

  1. Amazon ECR User Guide: identity-based policy examples, read 16 Nov 2026
  2. Amazon ECR User Guide: repository policy examples, read 16 Nov 2026
  3. AWS Service Authorization Reference, programmatic access (fetched 16 Nov 2026), read 16 Nov 2026

Last reviewed 16 Nov 2026.