Container Registry Security: Best Practices and Tools
Container registry security practices: immutable tags, digests, Trivy scanning, Cosign and Notation signing, SBOMs, retention and admission policies.
Container registry security comes down to a short list of controls: keep images in a private registry with least-privilege access, make release tags immutable and deploy by digest, scan every image on push and on a schedule, sign images and attach an SBOM, clean up old images with retention rules, and let a Kubernetes admission policy block anything unsigned.
The registry is the handoff point between your build system and every cluster that runs your code. If someone can overwrite a tag there, or push an image nobody scanned, every later security check is working on the wrong artifact. This guide walks through each practice with the commands for Amazon ECR, Azure Container Registry (ACR), Google Artifact Registry and Harbor. It is part of our DevSecOps series, alongside running ZAP in CI/CD. Commands were checked against vendor documentation in November 2026.
Key takeaways
- Never deploy a mutable tag such as
latestto production. Use immutable tags for releases and reference images by digest (@sha256:...) in manifests. - ECR, Artifact Registry and Harbor have repository-level tag immutability. ACR locks individual tags, manifests or whole repositories with
az acr repository update --write-enabled false. - Scan twice: in the pipeline before push, and in the registry continuously, because new CVEs are published against images you already shipped.
- Sign with Sigstore Cosign or Notary Project Notation, and attach an SBOM as a signed attestation. Amazon ECR added managed signing with AWS Signer in November 2025.
- Google Container Registry (gcr.io storage) shut down in 2025. New Google Cloud work belongs in Artifact Registry.
- Signing only helps if something checks the signature. Enforce it at admission time with Kyverno, Sigstore policy-controller or Ratify with Gatekeeper.
Why the registry matters for security and compliance
Most supply chain controls (code review, SAST, dependency scanning) run before the image exists. The registry is where the finished artifact lives, so it is the last place you can prove three things before deployment: the image is the one your pipeline built, it has no known critical vulnerabilities, and nobody changed it afterwards. Auditors working to frameworks such as NIST SP 800-190 (the NIST Application Container Security Guide), PCI DSS or SOC 2 ask for exactly this evidence: who pushed what, when, what was in it and what was allowed to run.
Registry security practices at a glance
| Practice | Risk it reduces | Where to enforce it |
|---|---|---|
| Private registry, no anonymous pull or push | Image theft, unauthorised uploads | Registry settings, network rules |
| Least-privilege access with short-lived CI credentials | Leaked long-lived passwords used to push malicious images | IAM / RBAC, OIDC federation from CI |
| Immutable tags and deploy by digest | Tag overwrite attacks, "works on my cluster" drift | Registry, Kubernetes manifests |
| Vulnerability scanning on push and continuously | Shipping known CVEs, missing new ones | CI pipeline and registry scanner |
| Image signing | Running images the pipeline did not build | CI signs, admission controller verifies |
| SBOM and provenance attestations | Slow incident response, audit gaps | CI generates, registry stores |
| Retention and cleanup rules | Old vulnerable images still pullable, storage cost | Registry lifecycle / cleanup policies |
| Admission policies | Bypassing all of the above | Kubernetes admission control |
| Audit logging | No evidence for auditors or incident responders | CloudTrail, Azure Monitor, Cloud Audit Logs, Harbor audit log |
1. Use a private registry with least-privilege access
Keep production images in a private registry in the same cloud account or network as your clusters. Then split permissions by role:
- CI pipelines get push rights only to the repositories they build.
- Clusters and nodes get pull-only rights.
- Very few humans get delete or admin rights, and those actions are logged.
Avoid static registry passwords in CI. GitHub Actions, GitLab CI and Azure Pipelines can all exchange an OIDC token for short-lived cloud credentials, so there is no long-lived secret to leak. In Harbor, use robot accounts scoped to one project with an expiry date instead of personal accounts.
Pull public base images through a cache or proxy (ECR pull through cache, Artifact Registry remote repositories, ACR artifact cache or a Harbor proxy project) so builds do not depend on the public internet and you can scan what comes in. For a broader comparison of hosted and self-managed options, see container registry platforms you should know.
2. Make tags immutable and deploy by digest
A tag is a movable pointer. Anyone with push rights can point myapp:1.4.2 at a different image, and every cluster that pulls it again gets the new content. A digest such as myapp@sha256:4f1c... identifies one exact image and cannot change.
Tag images with something unique (a Git commit SHA or a semantic version), turn on immutability for release repositories, and write the digest into your Kubernetes manifests or Helm values.
| Registry | Immutability option |
|---|---|
| Amazon ECR | Repository setting IMMUTABLE, or IMMUTABLE_WITH_EXCLUSION to leave chosen tags (for example latest) mutable |
| Azure Container Registry | Lock a tag, manifest or repository with --write-enabled false; --delete-enabled false prevents deletion only |
| Google Artifact Registry | Immutable tags setting on Docker repositories |
| Harbor | Tag immutability rules per project, matched by repository and tag patterns |
# Amazon ECR: make every tag in a repository immutable
aws ecr put-image-tag-mutability --repository-name myapp \
--image-tag-mutability IMMUTABLE --region ap-south-1
# Azure Container Registry: lock one released tag
az acr repository update --name myregistry \
--image myapp:1.4.2 --write-enabled false
Pushing an existing tag to an immutable ECR repository returns ImageTagAlreadyExistsException, which is the behaviour you want in a release pipeline.
3. Scan images in the pipeline and in the registry
Scan in CI so a vulnerable image never reaches the registry, then let the registry rescan stored images as new CVEs appear. Both layers matter: an image that was clean on Monday can have a critical CVE by Friday.
# Fail the build on fixable HIGH or CRITICAL vulnerabilities
trivy image --severity HIGH,CRITICAL --ignore-unfixed --exit-code 1 \
registry.example.com/myapp:${GIT_SHA}
| Registry | Built-in scanning |
|---|---|
| Amazon ECR | Basic scanning, or enhanced scanning with Amazon Inspector for continuous OS and language package scanning |
| Azure Container Registry | Microsoft Defender for Containers (vulnerability assessment for registry images) |
| Google Artifact Registry | Artifact Analysis on-push and continuous scanning |
| Harbor | Trivy as the bundled scanner, with pluggable scanners and project-level scan on push |
If you use a scanner as a GitHub Action, pin it to a full commit SHA. In March 2026 attackers force-pushed most version tags of aquasecurity/trivy-action to malicious code (GHSA-69fq-xp46-6x23), and pipelines that referenced tags ran it. Our list of image scanning tools for container security compares Trivy, Grype and the commercial options.
4. Sign images with Cosign or Notation
Signing proves that an image came from your pipeline and has not changed since. Two open standards dominate:
- Sigstore Cosign supports keyless signing: the CI job's OIDC identity (for example a GitHub Actions workflow) gets a short-lived certificate, and the signature is recorded in the public Rekor transparency log.
- Notary Project Notation uses X.509 certificates, often held in a cloud key manager. ACR documents Notation with Azure Key Vault, and AWS Signer works with Notation for ECR.
Always sign the digest, not the tag:
# Keyless signing from a CI job with an OIDC token
cosign sign --yes registry.example.com/myapp@sha256:4f1c...
# Verify: who signed it and which identity provider issued the certificate
cosign verify registry.example.com/myapp@sha256:4f1c... \
--certificate-identity-regexp 'https://github.com/myorg/myapp/.github/workflows/.*' \
--certificate-oidc-issuer https://token.actions.githubusercontent.com
On AWS, ECR managed signing (launched November 2025) signs images automatically on push using an AWS Signer profile, so the pipeline needs no signing client. Our article on artifact signing in supply chain security goes deeper into key management choices.
5. Attach an SBOM and provenance
A software bill of materials lists every package in the image. When the next widely exploited library flaw lands, an SBOM per image tells you in minutes which images contain it. Generate it in CI and store it next to the image as a signed attestation:
trivy image --format cyclonedx --output sbom.cdx.json \
registry.example.com/myapp@sha256:4f1c...
cosign attest --yes --type cyclonedx --predicate sbom.cdx.json \
registry.example.com/myapp@sha256:4f1c...
Build provenance (who built the image, from which commit, with which builder) adds the other half of the audit trail. BuildKit and the official Docker GitHub Actions can produce SBOM and provenance attestations at build time. See how SBOMs support DevOps compliance and why artifact provenance matters.
6. Set retention and cleanup rules
Old images are a quiet risk: they keep unpatched packages and stay pullable by anyone with access. Retention rules also keep storage costs in check.
- Amazon ECR: lifecycle policies expire images by age or count, for example untagged images after 14 days.
- Azure Container Registry: a retention policy for untagged manifests (preview, Premium tier) set with
az acr config retention update --status Enabled --days 30 --type UntaggedManifests, plusacr purgerun as a scheduled ACR task for tagged images. - Google Artifact Registry: cleanup policies with delete and keep rules and a dry-run mode. Tagged images in a repository with immutable tags cannot be deleted by cleanup policies.
- Harbor: tag retention rules per project, run on a schedule.
Before you enable deletion, check that no workload pulls by digest an image that has since lost its tag; the ACR docs warn about exactly this case. Keep release images for as long as your compliance rules require.
7. Enforce policies at Kubernetes admission
Signatures and scan results only protect you if the cluster refuses images that fail them. Kubernetes admission controllers intercept every pod creation and can reject it. Common choices:
- Kyverno: the
ImageValidatingPolicytype (stable since Kyverno 1.19) verifies Cosign and Notary signatures and attestations. The olderverifyImagesrule inClusterPolicybelongs to a policy type Kyverno now marks deprecated. - Sigstore policy-controller: verifies Cosign signatures and attestations against
ClusterImagePolicyresources. - Ratify with OPA Gatekeeper: verifies Notation and Cosign signatures through Gatekeeper constraints.
A trimmed Kyverno policy that only admits images signed by your GitHub Actions workflows:
apiVersion: policies.kyverno.io/v1
kind: ImageValidatingPolicy
metadata:
name: require-signed-images
spec:
matchConstraints:
resourceRules:
- apiGroups: ['']
apiVersions: ['v1']
operations: ['CREATE']
resources: ['pods']
matchImageReferences:
- glob: 'ghcr.io/myorg/*'
attestors:
- name: cosign
cosign:
keyless:
identities:
- subject: 'https://github.com/myorg/myapp/.github/workflows/*'
issuer: 'https://token.actions.githubusercontent.com'
ctlog:
url: 'https://rekor.sigstore.dev'
validations:
- expression: >-
images.containers.map(image, verifyImageSignatures(image, [attestors.cosign])).all(e, e > 0)
message: 'Image is not signed by the release workflow'
Use the same admission layer to require digests, block latest and restrict which registries pods may pull from. Our comparison of Gatekeeper and Kyverno helps you pick one.
Registry feature comparison
| Feature | Amazon ECR | Azure ACR | Google Artifact Registry | Harbor (self-hosted) |
|---|---|---|---|---|
| Tag immutability | Repository setting, with exclusion filters | Per tag, manifest or repository lock | Repository setting | Project rules |
| Vulnerability scanning | Basic or Amazon Inspector enhanced | Microsoft Defender for Containers | Artifact Analysis | Trivy (pluggable) |
| Signing support | Managed signing with AWS Signer; Notation; Cosign | Notation with Key Vault; Cosign | Cosign; Binary Authorization attestations | Cosign and Notation |
| Retention | Lifecycle policies | Untagged manifest retention (preview), acr purge | Cleanup policies | Tag retention rules |
| Access control | IAM and repository policies | Microsoft Entra ID and Azure RBAC | IAM | Projects, roles, robot accounts, OIDC |
| Audit log | AWS CloudTrail | Azure Monitor resource logs | Cloud Audit Logs | Built-in audit log |
Compliance checklist for auditors
- Every production image is referenced by digest and comes from an approved private registry.
- Release repositories have immutability turned on.
- Scan reports exist for every deployed image, and critical findings have a ticket or an approved exception.
- Every deployed image has a verified signature from the release pipeline identity.
- An SBOM is stored for every release image.
- Registry push, delete and permission changes are logged and retained.
- Admission policies block unsigned images, mutable tags and unapproved registries, and policy changes go through code review.
To build these controls hands-on, our DevSecOps training covers image scanning, signing and admission policies, and the Docker training covers image builds and registries from the ground up. Both run in Kharadi, Pune and live online across India.
Official references
- Amazon ECR: preventing image tags from being overwritten
- Amazon ECR managed container image signing
- Azure Container Registry: lock images
- Azure Container Registry: retention policy for untagged manifests
- Artifact Registry: configure cleanup policies
- Prepare for Container Registry shutdown
- Harbor vulnerability scanning
- Sigstore Cosign: verifying signatures
- Kyverno ImageValidatingPolicy
- NIST SP 800-190 Application Container Security Guide
FAQs
Why should I avoid the latest tag in production?
The latest tag moves every time someone pushes, so two nodes can run different code under the same name and a rollback has nothing fixed to return to. Use a unique tag per build, make release tags immutable, and deploy by digest.
What is the difference between a tag and a digest?
A tag is a human-readable label that can be moved to another image. A digest is the SHA-256 hash of the image manifest, so it always points to the same content. Signatures and admission policies should work on digests.
Does Azure Container Registry support immutable tags?
ACR does not have a single repository-wide immutability switch like ECR. Instead you lock a tag, a manifest or a whole repository with az acr repository update --write-enabled false, and you can block deletion separately with --delete-enabled false.
Should I use Cosign or Notation to sign images?
Choose Cosign if you want keyless signing tied to your CI identity and a public transparency log. Choose Notation if your organisation manages X.509 certificates in a key vault, or if you are on ACR or AWS Signer, which document it first. Kyverno and Ratify can verify both.
Is registry scanning enough, or do I also need to scan in CI?
Do both. CI scanning stops a vulnerable image before it is pushed and gives developers fast feedback. Registry scanning keeps checking stored images as new CVEs are published, which CI alone cannot do for images built weeks ago.
What happened to Google Container Registry?
Google shut down Container Registry on 18 March 2025, when writing images to it stopped. Projects that set up gcr.io repositories in Artifact Registry keep their gcr.io URLs, now served by Artifact Registry. New work should use Artifact Registry directly.
How do I stop unsigned images from running in Kubernetes?
Install an admission controller that verifies signatures, such as Kyverno with an ImageValidatingPolicy, Sigstore policy-controller, or Ratify with Gatekeeper. Configure it with the signing identity or key of your release pipeline so pods with unsigned or wrongly signed images are rejected.
Which compliance frameworks cover container registries?
NIST SP 800-190 addresses registry risks directly, including stale images and insecure connections. Broader frameworks such as PCI DSS and SOC 2 expect change control, vulnerability management and audit logs, which immutability, scanning, signing and registry logging provide.
What's Your Reaction?
Like
0
Dislike
0
Love
0
Funny
0
Angry
0
Sad
0
Wow
0