# IAM policy example: ECR policy for cross-account pull, with a least privilege rewrite

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

A repository policy that lets account 444455556666 pull images from the repository web-app. The original also grants push actions. The rewrite keeps the three pull actions only, which matches the AWS documentation example for cross-account pulls. Resource names and account 111122223333 are placeholders used in AWS documentation.

```json
{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Sid": "CrossAccount",
      "Effect": "Allow",
      "Principal": {
        "AWS": "arn:aws:iam::444455556666:root"
      },
      "Action": [
        "ecr:BatchCheckLayerAvailability",
        "ecr:GetDownloadUrlForLayer",
        "ecr:BatchGetImage",
        "ecr:PutImage",
        "ecr:InitiateLayerUpload",
        "ecr:UploadLayerPart",
        "ecr:CompleteLayerUpload"
      ]
    }
  ]
}
```

## What it allows

- Allows principals in account 444455556666, when their own policies also allow it, to pull and push images in the repository.

- Allows 7 actions (ecr:BatchCheckLayerAvailability, ecr:GetDownloadUrlForLayer, ecr:BatchGetImage, ecr:PutImage, ecr:InitiateLayerUpload, ecr:UploadLayerPart, ecr:CompleteLayerUpload) on no resource named for AWS arn:aws:iam::444455556666:root.

Checks:
- No flags.

Push actions let the other account replace an image that other consumers deploy.

## Least privilege rewrite

```json
{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Sid": "CrossAccountPull",
      "Effect": "Allow",
      "Principal": {
        "AWS": "arn:aws:iam::444455556666:root"
      },
      "Action": [
        "ecr:BatchCheckLayerAvailability",
        "ecr:GetDownloadUrlForLayer",
        "ecr:BatchGetImage"
      ]
    }
  ]
}
```

The rewrite removes the four push actions. The other account can pull but cannot replace images.

- Allows 3 actions (ecr:BatchCheckLayerAvailability, ecr:GetDownloadUrlForLayer, ecr:BatchGetImage) on no resource named for AWS arn:aws:iam::444455556666:root.

Checks:
- No flags.

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

## Related pages

- [IAM policy example: read one S3 bucket](/examples/s3-read-one-bucket/)
- [IAM policy example: read and write one S3 bucket](/examples/s3-read-write-one-bucket/)
- [IAM policy example: give each user an S3 home folder](/examples/s3-home-folder-by-username/)
- [All of them](/examples/)

## Sources

- Amazon ECR User Guide: repository policy examples: https://docs.aws.amazon.com/AmazonECR/latest/userguide/repository-policy-examples.html (read 16 Nov 2026)
- 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)
- 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-repository-policy-cross-account-pull/

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