Container Image Security: Minimal Bases, Scanning, SBOMs and Signing

Secure container images end to end: minimal and distroless bases, vulnerability scanning with Trivy or Grype, SBOM generation, signing with cosign.

Published December 2, 2026

A container image is a bundle of an operating system userland, language runtime, dependencies and your code. Every one of those layers can contain known vulnerabilities, and an attacker who can tamper with images in your pipeline can run anything in your cluster. Image security means shrinking what ships, knowing what is inside, and proving where it came from.

The concept

Start by shipping less. Minimal or distroless base images contain only what is needed to run your app, with no shell or package manager, which removes most OS-level vulnerabilities and makes post-exploitation harder. Rebuild images regularly so base image security patches are picked up.

Then make contents visible and verifiable. Scanners such as Trivy and Grype compare image contents to vulnerability databases. A Software Bill of Materials (SBOM, in SPDX or CycloneDX format) lists every package in the image. Signing images with Sigstore cosign and attaching provenance attestations lets clusters verify, via admission policies, that only images built by your pipeline are deployed.

The pipeline

imagepasspushdeployBuildminimal baseScan + SBOMTrivy / SyftSign + attestcosignRegistryAdmission policyverify signature
A secure image pipeline.

Fewer packages, fewer CVEs

Full OS base (e.g. ubuntu)≈120 known CVEsSlim base≈40Distroless / minimal≈5
Illustrative scanner findings by base image type; numbers vary over time.

Controls and what they stop

ControlTool examplesStops
Minimal base imagesdistroless, Chainguard/Wolfi, slimMost OS-level CVEs, shells for attackers
Vulnerability scanningTrivy, Grype, registry scannersShipping known-vulnerable packages
SBOMSyft, Trivy, BuildKit attestationsBlind spots during the next big CVE
Signing & provenancecosign, SLSA provenanceTampered or unofficial images
Admission policiesKyverno, Gatekeeper, Sigstore policy-controllerUnsigned images reaching the cluster

Practical examples

Scan in CI and fail on critical issues

Trivy exits non-zero when findings match the severity filter.

trivy image --severity CRITICAL,HIGH --ignore-unfixed --exit-code 1 registry.example.com/api:$GIT_SHA

Generate an SBOM and sign the image

Keyless signing uses your CI identity via OIDC.

syft registry.example.com/api:$GIT_SHA -o spdx-json > sbom.spdx.json
cosign sign --yes registry.example.com/api@$DIGEST
cosign attest --yes --predicate sbom.spdx.json --type spdxjson registry.example.com/api@$DIGEST

Kyverno policy requiring signed images

Reject images not signed by your pipeline.

apiVersion: kyverno.io/v1
kind: ClusterPolicy
metadata: { name: verify-images }
spec:
  validationFailureAction: Enforce
  rules:
    - name: signed-by-ci
      match: { any: [{ resources: { kinds: [Pod] } }] }
      verifyImages:
        - imageReferences: ["registry.example.com/*"]
          attestors:
            - entries:
                - keyless:
                    subject: "https://github.com/example/api/.github/workflows/release.yml@refs/heads/main"
                    issuer: "https://token.actions.githubusercontent.com"

Common mistakes

  • Scanning once at build time and never again as new CVEs are published.
  • Deploying by mutable tags instead of immutable digests.
  • Treating every CVE as equal instead of prioritising reachable, fixable, critical ones.
  • Debug tools and shells left in production images.

Key takeaways

  • Ship less: minimal and distroless bases.
  • Scan continuously and generate SBOMs.
  • Sign images and attest provenance with cosign.
  • Enforce signatures with admission policies; deploy by digest.

FAQ

How do I debug distroless containers without a shell?

Use kubectl debug with an ephemeral debug container, or a debug variant of the image in non-production.

Should builds fail on every high CVE?

Fail on critical and fixable issues; track others with SLAs, since some have no fix or are not reachable.

What is SLSA?

Supply-chain Levels for Software Artifacts, a framework of increasing guarantees about how artefacts are built, including provenance.

More DevOps articles