ExitAmazon ECR: private repository configuration1 / 7
Explanation

Separate registry authentication from repository authorization

How to configure private repositories for secure, reproducible CI/CD image publishing through repository policies, encryption settings, and tag immutability. · advanced

A private repository needs two separate controls: authentication to the registry and authorization for repository operations. The publishing role needs ecr:GetAuthorizationToken in an identity-based IAM policy with Resource: "*"; this action cannot be scoped to a repository ARN. The token inherits the principal's permissions—it does not grant permission to push. Use aws ecr get-login-password with Docker's --password-stdin, rather than exposing the password in command arguments.

Scope publishing permissions to the destination repository ARN. A normal push needs ecr:BatchCheckLayerAvailability, ecr:InitiateLayerUpload, ecr:UploadLayerPart, ecr:CompleteLayerUpload, and ecr:PutImage. An ECR repository policy is resource-based: attach it with set-repository-policy, name the publishing role in Principal, and allow only the required repository actions. Do not give the publishing role repository deletion or policy-management permissions merely to publish images.

For cross-account publishing, authorize repository operations in both the publishing role's identity policy and the destination repository policy. Within one account, an applicable allow in either policy can authorize repository operations; a repository policy is not automatically a mandatory second gate. Explicit denies and applicable organizational or identity restrictions still constrain access. A repository policy never replaces the identity-based permission for ecr:GetAuthorizationToken.