Amazon ECR stores the container images that run in your environments, which makes it a central point of the supply chain. All it takes is one image with known vulnerabilities, a mutable tag that quietly starts pointing to something else or a repository with overly broad permissions to compromise everything that runs from there. That is why ECR security revolves around the provenance, integrity and freshness of images.
ECR security best practices have one goal: every image promoted to production should be trustworthy and traceable. To get there, you need to take care of vulnerability scanning, tag immutability, the image lifecycle and push and pull permissions. Signing and a gate in the pipeline round out the supply chain safeguards.
Vulnerability scanning and CVEs
Turn on ECR image scanning to identify CVEs in the packages of each image. Scan on push catches problems early, and continuous scanning re-evaluates stored images as new vulnerabilities are published. This matters because an image that was clean a few months ago can pile up CVEs without any change to your code. Without continuous scanning, you end up running those vulnerabilities in production without knowing it.
Basic scanning and enhanced scanning
ECR has two scanning modes. Basic scanning uses a database of operating system CVEs and runs on push. Enhanced scanning is done by Amazon Inspector: it also covers programming language dependencies, re-evaluates images continuously as new CVEs appear and sends findings to Security Hub. In production, enhanced scanning with continuous re-evaluation usually pays for itself, because it is what notices the image aging.
aws ecr put-image-scanning-configuration \ --repository-name my-app \ --image-scanning-configuration scanOnPush=trueaws ecr put-image-tag-mutability \ --repository-name my-app \ --image-tag-mutability IMMUTABLEDecide in advance what to do with the findings: block promotion of images with critical vulnerabilities, prioritize the fixes and update the base image. Without a handling process, the scan turns into a report nobody reads, and it reduces no risk at all.
Immutable tags and lifecycle
Mutable tags are a trap. The same tag can point to different images over time, so the image you tested is not necessarily the one that is running. With tag immutability enabled, a published tag always refers to the same image. For reproducible builds, reference images by digest.
Lifecycle policies clean up old and unused images. That reduces cost and lowers the chance of someone deploying an obsolete, vulnerable version. Keep what you need for rollback and expire the rest. The rule below, for example, expires untagged images after 14 days, since they tend to pile up in the repository.
{ "rules": [ { "rulePriority": 1, "description": "Expire untagged images after 14 days", "selection": { "tagStatus": "untagged", "countType": "sinceImagePushed", "countUnit": "days", "countNumber": 14 }, "action": { "type": "expire" } } ]}- Enable scan on push and continuous enhanced scanning
- Act on findings instead of just producing reports
- Turn on tag immutability
- Reference production images by digest
- Create a lifecycle policy that expires old images
Permissions and the supply chain
Use repository and IAM policies, with least privilege, to restrict who pushes and who pulls images. Take extra care with public repositories: they expose images to anyone and can leak whatever sensitive content is baked into them. Also control the provenance of base images, prefer trusted sources and rebuild your images from time to time to inherit fixes from the base.
The repository policy defines who can pull the image. Allowing pulls only from the deploy role of the right workload, instead of leaving them open to the whole account, reduces the reach of a compromised credential and keeps any identity in the organization from pulling images it should not.
{ "Version": "2012-10-17", "Statement": [ { "Sid": "AllowPullOnlyFromDeployRole", "Effect": "Allow", "Principal": { "AWS": "arn:aws:iam::ACCOUNT:role/deploy-my-app" }, "Action": [ "ecr:GetDownloadUrlForLayer", "ecr:BatchGetImage" ] } ]}Provenance: signing and verifying images
Scanning and immutability tell you the image has few CVEs and that the tag does not change, but they do not prove who built the image. Signing closes that gap. The pipeline signs each promoted image, and the runtime environment only accepts images with a valid signature from a trusted key. This way, an image injected from outside the pipeline is rejected at deployment, even if it carries the expected tag.
In practice, this combines a signing tool (AWS Signer with Notation, or a sigstore signer) with a check at deploy time. In Kubernetes, an admission controller validates the signature before letting the pod start. Outside Kubernetes, verification becomes a step of the deploy itself. From then on, trust stops depending on the tag and starts depending on the signature.
A gate in the pipeline: from build to deploy
Image governance only reduces risk for real when it becomes a barrier on the way to production. Make the checks mandatory pipeline steps, because in practice nobody reads an optional report.
- Run the scan and fail the build if there is a critical CVE without an approved exception
- Sign the approved image and promote it by digest, never by a tag that can change
- Block any image without a valid signature at deploy time
- Record who approved each vulnerability exception and until when it is valid
- Rebuild images periodically to inherit fixes from the base image
There will be exceptions, because not every critical CVE has an immediate fix. In a healthy process, an exception is a conscious decision, with an owner and a deadline. What must not happen is someone quietly turning off the block the first time it gets in the way.
Practical checklist
- Enable scan on push and continuous enhanced scanning through Inspector
- Define how CVE findings will be handled
- Prevent promotion of images with critical vulnerabilities
- Enable tag immutability on repositories
- Point production deployments at the image digest
- Expire old images with a lifecycle policy
- Limit push and pull with repository and IAM policies
- Keep internal images out of public repositories
- Sign promoted images and verify the signature at deploy time
- Record each vulnerability exception with an owner and a deadline
- Check the provenance of base images
- Rebuild images from time to time to inherit fixes
Best practices
- Remember that everything that runs passes through the registry, a critical point in the supply chain
- Use continuous enhanced scanning, because new CVEs appear after the build
- Use tag immutability so what was tested is what runs
- Apply least privilege to push and pull
- Sign images and reject any without a valid signature at deploy time
- Control your base images and rebuild to inherit fixes
- Expire old images, which only bring risk and cost
Common mistakes
- Mutable tags in production
- The same tag starts pointing to another image, and what was tested is no longer what runs.
- Trusting the tag alone, without verifying signatures
- An image injected outside the pipeline, with the expected tag, goes live with no barrier at all.
- Pull open to the whole account
- Any compromised identity can pull internal images it should not be able to reach.
- Scan on push only, with no continuous re-evaluation
- Images pile up CVEs discovered after the build, and nobody finds out.
- Public repository holding an internal image
- Sensitive content baked into the image is visible to anyone.
- Ignored scan findings
- Known vulnerabilities reach production without being addressed.
- No lifecycle policy configured
- Obsolete, vulnerable images remain available for deployment.
Authorship and review
Cesar Gargiulo
CEO and founder of GUARDIASEC. Technical and editorial lead for the content published in this library.
Published on . Found a technical error? Write to [email protected] and we will correct it and keep a record of the change.