# IAM policy example: pull images from one ECR repository, with a least privilege rewrite

Facts read 16 Nov 2026. Page reviewed 16 Nov 2026.

Allows a role to log in to the registry and pull images from one repository, web-app. The login token action has no resource-level support, so it uses a wildcard. The original allows ecr:* on every repository. The names and the account ID 111122223333 are AWS documentation placeholders.

```json
{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Sid": "Ecr",
      "Effect": "Allow",
      "Action": "ecr:*",
      "Resource": "*"
    }
  ]
}
```

## What it allows

- Allows every ECR action on all repositories, including pushing and deleting images.

- Allows 65 actions (ecr:*) on every resource.

Checks:
- high: Allows 36 write or permissions-management actions (4 permissions management) on every resource ("Resource": "*"). (https://docs.aws.amazon.com/IAM/latest/UserGuide/best-practices.html)

The action ecr:* covers 65 actions, including deleting repositories and replacing images.

## Least privilege rewrite

```json
{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Sid": "Login",
      "Effect": "Allow",
      "Action": "ecr:GetAuthorizationToken",
      "Resource": "*"
    },
    {
      "Sid": "PullOneRepo",
      "Effect": "Allow",
      "Action": [
        "ecr:BatchCheckLayerAvailability",
        "ecr:GetDownloadUrlForLayer",
        "ecr:BatchGetImage"
      ],
      "Resource": "arn:aws:ecr:us-east-1:111122223333:repository/web-app"
    }
  ]
}
```

The rewrite splits the login token from the three pull actions and names one repository. Pushing and deleting are removed.

- Allows 1 action (ecr:GetAuthorizationToken) on every resource.
- Allows 3 actions (ecr:BatchCheckLayerAvailability, ecr:GetDownloadUrlForLayer, ecr:BatchGetImage) on arn:aws:ecr:us-east-1:111122223333:repository/web-app.

Checks:
- No flags.

- [Paste it into the workbench](/)
- [Every Elastic Container Registry action and its access level](/actions/ecr/)

## Related pages

- [IAM policy example: push images to one ECR repository](/examples/ecr-push-images-to-one-repository/)
- [IAM policy example: run ECS tasks in one cluster](/examples/ecs-run-tasks-in-one-cluster/)
- [IAM policy example: read EKS cluster details for kubeconfig](/examples/eks-describe-cluster-for-kubeconfig/)
- [All of them](/examples/)

## Sources

- Amazon ECR User Guide: identity-based policy examples: https://docs.aws.amazon.com/AmazonECR/latest/userguide/security_iam_id-based-policy-examples.html (read 16 Nov 2026)
- Amazon ECR User Guide: repository policy examples: https://docs.aws.amazon.com/AmazonECR/latest/userguide/repository-policy-examples.html (read 16 Nov 2026)
- AWS Service Authorization Reference, programmatic access (fetched 16 Nov 2026): https://docs.aws.amazon.com/service-authorization/latest/reference/service-reference.html (read 16 Nov 2026)

Last reviewed 16 Nov 2026. Canonical: https://iampolicygenerator.com/examples/ecr-pull-images-from-one-repository/

This site is not affiliated with Amazon Web Services. AWS service and product names are used only to describe AWS services.
