How can ECR repository policies control which IAM users, roles, or other AWS accounts can access a specific container image repository?
Short answer
ECR repository policies work similarly to S3 bucket policies, letting you explicitly define which IAM principals, potentially including principals from a completely different AWS account, are allowed to perform specific actions such as pulling or pushing images to a particular…
Advertisement
AModel answer
ECR repository policies work similarly to S3 bucket policies, letting you explicitly define which IAM principals, potentially including principals from a completely different AWS account, are allowed to perform specific actions such as pulling or pushing images to a particular repository, which is especially useful when sharing container images across multiple accounts in an organization without making the repository publicly accessible.
Example
aws ecr set-repository-policy --repository-name my-app --policy-text file://ecr-repository-policy.json
Real-world example
A company sharing a common base container image across several development teams in separate AWS accounts configures an ECR repository policy that grants pull access to those specific accounts, without needing to duplicate the same image into every individual account's own registry.
Likely follow-ups
- How do you grant cross account access to a specific ECR repository?
- What is the difference between a repository policy and an IAM policy for controlling ECR access?
Related topics