Container Image Vulnerability Scanning in Production Pipelines
Scan before push, block fixable high-risk findings, and fail builds.

Container image vulnerability scanning only protects production when it can stop a release. A report is not a gate. The useful design scans the built image before registry push, blocks fixable high-risk findings, and gives engineers a clear remediation path. That gate then becomes the foundation for checking what gets deployed, where it came from, and what still needs testing at runtime.
Why most container scanning programs fail to prevent vulnerable images from shipping
The failure starts when a scanner finds a vulnerability and the pipeline ships the image anyway. Running Trivy with exit-code set to 0 produces findings without making them a reason to stop. The report may be visible, but enforcement is absent. A finding that cannot fail the build is not a blocking security control.
This pattern persists when scanning sits outside the path between image build and registry push. Unset or permissive thresholds make that separation worse because engineers never encounter a failure that requires remediation. Vulnerable images then accumulate in registries and reach production through the normal release process. The pipeline is doing exactly what its configuration permits.
How container image scanning works and what it can and cannot see
An image scanner inspects layers, package databases, manifests, and filesystem contents, then compares discovered components against known vulnerability databases. The completed image can be inspected before the container runs and is a useful inspection point because it contains the OS packages and language dependencies that will ship, including those inherited from its base image.
Build-time checks can also examine Dockerfiles for configuration problems and look for secrets baked into image layers. Coverage depends on the tool and enabled checks. Vulnerability scanning, configuration checks, and secret detection are related but distinct capabilities. A clean package scan therefore does not establish that the container avoids root execution or that its layers contain no credentials.
The boundary becomes clearer after deployment. Static inspection cannot show how application logic behaves, whether an attacker can chain weaknesses, or whether a compromised workload tries lateral movement. Admission controllers enforce deployment policy, while runtime tools such as Falco and Tetragon detect anomalous behavior in running containers. Those tools can respond to exploitation-related activity, but they are not static image scanners.
Choosing between Trivy, Grype, and Snyk Container for a production gate
Scanner selection should turn on database coverage, CI behavior, and useful remediation guidance. The decision should produce a repeatable automated check. Trivy fits a general-purpose gate because it covers OS packages, language dependencies, infrastructure as code, and secrets, with CycloneDX and SPDX SBOM generation. Its native GitHub Actions and GitLab CI integration needs no dedicated server, and its moderate scan times suit most pipelines. It is open source under Apache 2.0.
Grype fits high-volume pipelines where scan latency is a bottleneck, including use as a secondary fast-pass filter with Trivy. It draws on NVD and OS vendor feeds and is also open source under Apache 2.0. Snyk Container serves a different need. Its curated Snyk Intel DB, remediation advice, and auto-fix pull requests suit teams that need guided fixes without dedicated security expertise. It is commercial with a limited free tier, supports standard SBOM formats, and has API-dependent CI performance.
No choice removes disagreement between vulnerability databases. Debian and Ubuntu assess their own builds and backport fixes, so their findings can differ from NVD on severity and patch availability. That affects both blocking decisions and remediation advice. A single scanner is not a complete picture, and disagreement deserves investigation rather than an assumption that the louder result is correct.
Where in the pipeline to place the scanning gate and how to configure it to actually block
The release path should run from code commit to image build, then blocking scan, registry push, and deployment. A failed scan must halt promotion before the image is tagged as latest or pushed to a shared registry. Placement alone is not enough. The scanner must return a failing exit code, and the push step must run only if the scan passes.
For a GitHub Actions gate, the relevant Trivy settings are exit-code set to '1', severity set to 'CRITICAL,HIGH', and ignore-unfixed set to true. SARIF output makes findings available for GitHub Security upload, while the push step uses if: success(). Each setting has a distinct job. The exit code enforces the decision, the severity filter defines the blocking class, and ignoring unfixed findings keeps the gate focused on available remediation.
The build environment needs protection too. Kaniko can build images without exposing the Docker socket on shared CI runners. Registry scanning then adds a second check for images that skip CI through manual pushes or legacy pipelines. AWS ECR, Google Artifact Registry, and Harbor support automated scanning on image push. That backstop does not replace the pre-push gate because the artifact has already reached the registry.
Setting severity thresholds that engineers will actually respect
Engineers lose trust in a gate when every finding becomes an emergency. But a gate cannot do its job if the threshold is raised until builds always pass. CRITICAL and HIGH findings that have fixes should block at once, and any exceptions must have their reasons written down. MEDIUM findings should get remediation tickets within a set time, while low-severity findings and vulnerabilities without fixes should go in the audit record for review on a schedule.
CISA Known Exploited Vulnerabilities hits come first because exploitation is confirmed in the wild. High-EPSS findings come next because they indicate a high probability of exploitation, followed by other fixable findings with severity ratings of Critical and High. This prioritization helps engineers address the most urgent failures while maintaining the blocking policy for the rest.
Unfixable critical findings are the obvious objection to this approach. Many arrive through base images, and stopping every build cannot create a patch that does not exist. Setting ignore-unfixed to true addresses that problem, while remaining unfixable criticals need a documented exception and migration ticket. A versioned .trivyignore file or its equivalent records why each exception was made and when it expires, so exceptions do not stay as verbal agreements with no end date.
Why base image selection is the highest-leverage remediation available
The base image determines most of the CVE count. Full OS images such as ubuntu:22.04 and debian:bookworm include a shell, a package manager, and many libraries the application may never call. Those extra components increase both the scanner’s workload and the potential attack surface.
Changing that starting point can remove more exposure than addressing findings one by one. Alpine-based images have fewer packages and less CVE exposure but still have a package manager. Distroless images narrow the contents to the application and its runtime, without a shell or package manager. The choice still depends on what the application needs. A scratch image has zero OS CVEs, but only works for fully static binaries without dynamic runtime dependencies, commonly from Go or Rust and also possible with C/C++.
The gate makes this an engineering decision rather than an aspiration by exposing the recurring cost of a bloated base. The same policy should require image references pinned to a specific digest rather than :latest, non-root execution, and a health check for every container. These checks address configuration as well as package risk. A smaller base is valuable, but it does not excuse an unsafe Dockerfile.
Reducing false positives without undermining the gate
A valid package finding can point to a weakness that the application cannot reach. Treating unused code paths like reachable critical vulnerabilities erodes trust. Some findings need a patched base image rather than lengthy triage, while others come from transitive dependencies the application never invokes. The same vulnerable library can also be reported more than once when it appears in more than one image layer.
Reachability analysis checks whether a vulnerable package is called at runtime, which helps tell whether it is used or just present. It is useful, but not conclusive. Dynamic loading can evade static import analysis, so an apparently unused dependency is not automatic grounds for suppression. The database disagreements described earlier also call for a look at vendor fixes and affected builds, rather than a rule that always accepts the scanner with fewer findings.
A .trivyignore entry should name the CVE and explain the rationale, such as a vendor advisory, an unreachable code path, or accepted risk linked to a ticket. It should also include an expiry date or migration condition so that the decision gets revisited. The file belongs in the repository and goes through code review, giving SOC 2 and ISO 27001 reviewers evidence of how exceptions were handled. A documented suppression is an audit asset, while an undocumented one is a liability.
Extending the gate with SBOM generation, image signing, and admission control
A passed scan describes an image at one point in time, but deployment also needs evidence of its origin and integrity. An SBOM generated by Syft or Trivy records the components present at build time. That inventory speeds up later scans and gives teams evidence for compliance. It supports vulnerability detection under SOC 2 CC7.1 and component inventory under FedRAMP CM-8, so teams have a record of more than whether the scan passed or failed.
Signing adds proof of the pipeline’s identity. With cosign keyless signing and OIDC, there are no signing keys for the team to manage or rotate. Signing after the gates pass ties that proof to the approved build process and helps meet software integrity requirements, including SOC 2 CC6.8 and SI-7. SLSA provenance then links the image digest to the exact source commit and build job. That answers the separate question of which code produced the artifact.
Kyverno or OPA Gatekeeper can block pods that lack a valid signature or provenance attestation. This is the last checkpoint before runtime. The combined policy can require a validated SBOM, an approved base image digest, trusted pipeline signatures, approved provenance, and no prohibited packages or licenses. CVE checks remain part of that policy, with any exceptions at deployment handled through the documented process.
For EU-facing products, the inventory also has a regulatory deadline. The European Commission’s CRA reporting page states that manufacturers must report actively exploited vulnerabilities and severe incidents from 11 September 2026. The EU Cyber Resilience Act requires a machine-readable SBOM from 11 December 2027. An inventory attached to the release process is more useful than documentation assembled only when an auditor asks for it.
What the pipeline gate cannot replace: runtime monitoring and penetration testing
A clean scan is not a clean bill of health for the application. SQL injection, SSRF, insecure deserialization, and secrets supplied through environment variables can survive image inspection. Chained attacks may also turn a low-severity CVE and an application misconfiguration into a critical outcome. Even when a scanner flags a kernel CVE, it cannot establish whether the deployed runtime is exposed to a container escape.
Runtime monitoring watches what happens after deployment, including exploitation, lateral movement, and persistence attempts. A human attacker can test authentication flows, chain weaknesses, and demonstrate exploitability with a working exploit. Whitebox testing brings source code, cloud configuration, and pipeline artifacts into that work, helping tell which vulnerabilities are absent and which the scanner missed.
This distinction also shapes compliance evidence. Scan history and SBOMs support monitoring controls, while verified penetration-test findings and a letter of attestation show that the attack surface was tested in more depth. Neither should stand in for the other. Rigor across the pipeline, deployment policy, and runtime makes penetration testing faster and more valuable because the scanner handles the mechanical known-CVE work. The human tester can then focus on the hard problems that a package inventory cannot answer.


