IAM policy example: push images to one ECR repository, with a least privilege rewrite
Facts read 16 Nov 2026. Page reviewed 16 Nov 2026.
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
Allow 1 action (ecr:GetAuthorizationToken) on every resource.
Action or pattern Actions Access levels ecr:GetAuthorizationToken1 Read 1 Allow 5 actions (ecr:BatchCheckLayerAvailability, ecr:InitiateLayerUpload, ecr:UploadLayerPart, ecr:CompleteLayerUpload, ecr:PutImage) on arn:aws:ecr:us-east-1:111122223333:repository/*.
Action or pattern Actions Access levels ecr:BatchCheckLayerAvailability1 Read 1 ecr:InitiateLayerUpload1 Write 1 ecr:UploadLayerPart1 Write 1 ecr:CompleteLayerUpload1 Write 1 ecr:PutImage1 Write 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
Allow 1 action (ecr:GetAuthorizationToken) on every resource.
Action or pattern Actions Access levels ecr:GetAuthorizationToken1 Read 1 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 pattern Actions Access levels ecr:BatchCheckLayerAvailability1 Read 1 ecr:InitiateLayerUpload1 Write 1 ecr:UploadLayerPart1 Write 1 ecr:CompleteLayerUpload1 Write 1 ecr:PutImage1 Write 1
Checks
No flags from the six checks.
Related pages
Sources
- Amazon ECR User Guide: identity-based policy examples, read 16 Nov 2026
- Amazon ECR User Guide: repository policy examples, read 16 Nov 2026
- AWS Service Authorization Reference, programmatic access (fetched 16 Nov 2026), read 16 Nov 2026
Last reviewed 16 Nov 2026.