Amazon Elastic Container Registry (ECR) is only as trustworthy as the identities that can push to it, the policies that decide who can pull from it, and the settings that stop a tag from silently changing underneath production. This guide covers the ECR-specific controls: IAM and repository policies, authorisation tokens, tag immutability, basic and enhanced scanning, encryption at rest and pull through cache rules with their upstream credentials. For vendor-neutral registry principles such as signing, digests and pruning, read our Container Registry Security Guide; this page does not repeat it.
Almost every ECR caller is a non-human identity (NHI). CI pipelines push images, ECS tasks, EKS nodes and Lambda functions pull them, and pull through cache rules hold credentials for upstream registries such as Docker Hub. An attacker who controls a push role can plant an image that production will run. An attacker who holds a pull credential can read every image, and the secrets that teams too often bake into image layers.
This is an independent guide from NHI Mgmt Group, based on Amazon Web Services' public documentation as of November 2026. It is not sponsored or reviewed by Amazon Web Services. Product features change, so confirm settings against Amazon Web Services' current documentation.
Key takeaways
- ECR access is the union of IAM policies and repository policies, and an explicit deny in either one wins. Review both.
- Every push and pull starts with
ecr:GetAuthorizationToken, which must come from an IAM policy. The resulting token is valid for 12 hours and carries the caller's full ECR permissions. - Separate push roles from pull roles. Only release pipelines should hold
ecr:PutImageand the layer upload actions. - Turn on tag immutability for release repositories so a tag such as
v1.4.2always means the same image. - Enhanced scanning through Amazon Inspector rescans continuously as new CVEs appear; basic scanning covers operating system packages on push or on demand.
- Encryption settings are fixed at repository creation. Decide on AWS KMS keys before you create repositories, not after.
- Pull through cache credentials live in AWS Secrets Manager under the
ecr-pullthroughcache/prefix. Treat them as shared NHI secrets with owners and rotation.
How ECR access control works
AWS describes repository policies as a subset of IAM policies that are scoped for, and specifically used for, controlling access to individual Amazon ECR repositories. IAM identity policies attached to roles and users can grant the same actions across the service or on specific repository ARNs.
The evaluation rule is simple and easy to forget. If a principal is allowed an action in a repository policy but denied it in an IAM policy, or the reverse, the action is denied. A principal needs an allow in only one of the two for the action to succeed. In practice this means:
- A broad IAM policy such as
ecr:*on*grants push and delete on every repository in the account, whatever the repository policies say. - A repository policy that names a principal from another account grants that principal access, subject to its own account's IAM policies.
- To be sure a repository is locked down, you must review the repository policy and every IAM policy in the account that touches ECR.
By default, only the AWS account that created a repository has access to it. Cross-account access and organisation-wide sharing are opt-in through repository policies, which makes those policies the first place to look in an access review.
The authorisation token step
Docker and other OCI clients do not speak IAM natively. ECR bridges the gap with an authorisation token. AWS states that callers need ecr:GetAuthorizationToken through an IAM policy before they can authenticate to a registry and push or pull any images. A repository policy alone cannot grant this.
The token returned has the username AWS and an encoded password. AWS documents that an authentication token is used to access any Amazon ECR registry that your IAM principal has access to and is valid for 12 hours, and that its permission scope matches the IAM principal that retrieved it. The token is therefore a bearer credential worth up to 12 hours of that role's ECR access. It is written to Docker's config file by docker login, and it ends up in CI logs when someone echoes it. Treat it as a secret.
Push and pull identities: least privilege for pipelines and workloads
Design ECR permissions around two roles per application: one that pushes and one that pulls.
| Identity | Typical ECR actions | Scope |
|---|---|---|
| Release pipeline (push) | ecr:GetAuthorizationToken, ecr:BatchCheckLayerAvailability, ecr:InitiateLayerUpload, ecr:UploadLayerPart, ecr:CompleteLayerUpload, ecr:PutImage | Only the repositories that pipeline builds |
| Runtime workload (pull) | ecr:GetAuthorizationToken, ecr:BatchGetImage, ecr:GetDownloadUrlForLayer | Only the repositories that workload runs |
| Registry administrator | Repository creation, policy, lifecycle and scanning configuration | Small group, change-controlled |
The action list above follows the standard ECR push and pull flow; confirm it against the IAM reference for your use case. Practical rules for each role:
- Federate pipelines, never store keys. CI systems should assume a role through OIDC federation rather than hold IAM user access keys. Our AWS Access Keys Security Guide covers the migration.
- Pin push roles to repository ARNs. A pipeline for one service should not be able to push to another service's repository.
- Keep delete separate.
ecr:BatchDeleteImageandecr:DeleteRepositorybelong to administrators and lifecycle policies, not pipelines. - Use the workload's own role for pulls. ECS task execution roles, EKS node or pod identities and Lambda execution roles should carry only pull actions on the repositories they need.
- Restrict cross-account principals. Name specific roles in the consuming account rather than the account root, and review those statements when teams or accounts change.
For how runtime services obtain and use registry credentials, see our Container Registry Pull Credentials Guide and the Amazon ECS and Fargate Security Guide.
Handling the token in CI and on hosts
The AWS CLI get-login-password command retrieves and decodes the token so it can be piped into docker login with --password-stdin. Piping avoids putting the token on a command line or in shell history. ECR also provides a Docker credential helper that fetches tokens on demand; AWS notes that the helper does not support multi-factor authentication. On build agents, clear Docker's credential store at the end of each job, and never cache the token between jobs on shared runners.
Tag immutability
Mutable tags let anyone with push rights replace what a tag points to. If production deploys service:v1.4.2 by tag, a compromised push role can overwrite that tag with a malicious image and the next deployment runs it.
ECR prevents this per repository. AWS states that after tag immutability is turned on, the ImageTagAlreadyExistsException error is returned if you push an image with a tag that is already in the repository. The settings are:
MUTABLE, with optional mutable tag exclusions to freeze a few named tags.IMMUTABLE, where all tags are protected.IMMUTABLE_WITH_EXCLUSION, with wildcard filters for tags that may still move, such aslatestordev-*.
Use IMMUTABLE or IMMUTABLE_WITH_EXCLUSION for every repository that feeds production. Keep exclusions to floating convenience tags that production never deploys. Even with immutability on, deploy by digest where your tooling allows it, because a digest is the only identifier that cannot be reassigned. AWS recommends MUTABLE for repositories used by pull through cache, so ECR can refresh cached images; handle those repositories as described below.
Image scanning: basic and enhanced
ECR offers two scanning types, configured at registry level.
Enhanced scanning with Amazon Inspector
AWS states that Amazon ECR integrates with Amazon Inspector to provide automated, continuous scanning of your repositories. Enhanced scanning covers both operating system packages and programming language packages, supports scan on push and continuous scanning, and updates results as new vulnerabilities appear, with Amazon Inspector emitting an event to Amazon EventBridge. Continuous rescanning matters because most images are clean on the day they are built and vulnerable a few weeks later.
Basic scanning
Basic scanning uses AWS native technology with the CVE database to scan operating system packages, on push or manually. Note that the current version returns results through the DescribeImageScanFindings API rather than the summary attributes in DescribeImages, so update any scripts that read the older fields.
Making scan results useful
- Switching between enhanced and basic scanning discards established scans; plan the switch and reconfigure rules straight after.
- Archived images cannot be scanned until they are restored, so do not assume archived images are covered.
- Route EventBridge findings to a queue that has an owner per repository, with severity thresholds that block promotion to production.
- Scanning finds known vulnerable packages. It does not reliably find hard-coded secrets in image layers. Run a secrets scanner in the build pipeline as well; see our Secrets in Container Images and Build Artefacts Guide.
Encryption at rest and KMS key policy
AWS documents that by default ECR uses server-side encryption with Amazon S3-managed keys and AES-256, at no extra charge and with no action needed. For more control you can use SSE-KMS with the AWS managed key aws/ecr or a customer managed key in the same Region. Dual-layer DSSE-KMS is available in the AWS GovCloud (US) Regions only.
The critical constraint: Repository Encryption Configuration can't be changed after a repository is created. If you need customer managed keys for separation of duties, audit or crypto-shredding, set that up before repositories are created, ideally through repository creation templates or infrastructure as code. A customer managed key adds a second access gate: principals need KMS permissions as well as ECR permissions, and the key policy becomes part of your registry access review.
Pull through cache rules and upstream credentials
Pull through cache lets ECR proxy and store images from upstream registries, so workloads pull public images from your own registry. That gives you scanning, private network pulls and resilience against upstream outages or rate limits. It also creates an NHI that holds credentials to third-party registries.
Upstream authentication
AWS lists upstreams that need no authentication (Amazon ECR Public, the Kubernetes container image registry and Quay), upstreams that need a Secrets Manager secret (including Docker Hub, GitHub Container Registry, GitLab Container Registry, Microsoft Azure Container Registry and Chainguard Registry), and Amazon ECR upstreams that use an IAM role. For secret-based upstreams, the secret name must use the ecr-pullthroughcache/ prefix and must be in the same account and Region as the rule. ECR uses a service-linked role, created automatically with the first rule, to create cached repositories, read the secret and push cached images.
Controls for those secrets:
- Use a dedicated, read-only upstream account or token for each upstream, never a person's personal access token.
- Record an owner and rotation date for every
ecr-pullthroughcache/secret, and rotate on staff changes and upstream incidents. - Restrict who can read or update those secrets in Secrets Manager; anyone who can change the secret can redirect what the cache authenticates as.
- Restrict who can create pull through cache rules, because a new rule can introduce an unvetted upstream namespace.
Behaviour to plan around
- Refresh cadence. For subsequent pulls of a cached tag, ECR checks upstream and attempts to update at least once every 24 hours. A compromised upstream tag can therefore reach your cache within a day.
- Stale fallback. If ECR cannot reach upstream, the last cached image is still pulled. That is good for availability, but means an upstream takedown of a malicious image does not remove it from your cache.
- Immutability conflict. Turning on tag immutability on cache repositories stops ECR from updating images with the same tag. Deploy cached images by digest, or promote vetted images from the cache into an immutable internal repository.
- No direct pushes. AWS states that pushing images directly to a pull through cache repository is not a supported pattern; keep cache and release repositories separate.
- First pull networking. With PrivateLink interface endpoints, the first pull still needs an internet route.
- Defaults. Cached repositories use the default AES256 encryption unless a repository creation template sets otherwise, and template settings only apply at creation.
Detection and monitoring
ECR API calls are recorded in AWS CloudTrail. Build detections around the identities, not just the images.
- Push from an unexpected principal. Alert on
PutImageby any role other than the approved release pipelines. - Policy changes. Alert on
SetRepositoryPolicy,DeleteRepositoryPolicy, registry policy changes, tag mutability changes and scanning configuration changes. - Token use from new places.
GetAuthorizationTokenfrom a role outside its normal network or schedule can indicate stolen workload credentials. - Bulk pulls. A principal pulling many repositories it does not normally use suggests reconnaissance or data theft.
- Cache rule and secret changes. New pull through cache rules and updates to
ecr-pullthroughcache/secrets.
Map detections to MITRE ATT&CK: Implant Internal Image for malicious images planted in your registry and Valid Accounts: Cloud Accounts for misuse of push and pull roles. Supply chain integrity guidance in NIST SP 800-190 and SLSA frames why build provenance and verification belong alongside these alerts.
Common failure patterns
- Account-wide
ecr:*on a CI role, so any pipeline can overwrite any image or delete any repository. - Mutable production tags, letting a stolen push credential replace a release tag in place.
- Repository policies granting a whole partner account rather than named roles, left in place after the partnership ends.
- Static IAM user keys in CI used to fetch authorisation tokens, leaked through build logs or forks.
- Tokens echoed in logs or cached in Docker config on shared runners.
- Scan on push only, so images are never rescanned after new CVEs are published.
- Secrets baked into image layers, readable by every principal with pull access.
- Personal tokens in pull through cache secrets, which stop working or keep working after the person leaves.
- Encryption decided too late, forcing repository rebuilds to adopt customer managed keys.
Practitioner checklist
- List every IAM policy and repository policy that grants ECR actions, and remove account-wide wildcards.
- Split push and pull roles per application and scope each to repository ARNs.
- Federate CI into AWS with OIDC and remove IAM user keys used for ECR.
- Pipe authorisation tokens with
--password-stdin, mask them in CI and clear credential stores after each job. - Set
IMMUTABLEorIMMUTABLE_WITH_EXCLUSIONon every production repository and deploy by digest. - Turn on enhanced scanning with continuous rescans and route findings to owners with blocking thresholds.
- Add secrets scanning to image builds.
- Choose KMS encryption settings before repository creation and include key policies in access reviews.
- Inventory
ecr-pullthroughcache/secrets with owners, rotation dates and least-privilege upstream tokens. - Alert on unexpected pushes, policy and mutability changes, and new pull through cache rules.
- Review cross-account repository policy statements quarterly.
Standards and references
- AWS: Private repository policies in Amazon ECR
- AWS: Private registry authentication in Amazon ECR
- AWS: Preventing image tags from being overwritten in Amazon ECR
- AWS: Scan images for software vulnerabilities in Amazon ECR
- AWS: Encryption at rest in Amazon ECR
- AWS: Sync an upstream registry with an Amazon ECR private registry
- NIST: SP 800-190 Application Container Security Guide
- OpenSSF: SLSA v1.0 Security Levels
Related NHI Mgmt Group resources: Container Registry Security Guide · Container Registry Pull Credentials Guide · Amazon ECS and Fargate Security Guide · Secrets in Container Images and Build Artefacts Guide