Your Docker Images are a Liability: How to Automate Container Security and Stop Supply Chain Attacks
If you're pulling base images from Docker Hub without scanning them, you are deploying vulnerabilities into production. Here is how to build an automated DevSecOps pipeline that catches CVEs before they reach your customers.
4 min readTL;DR
Every unscanned Docker image in your production cluster is a ticking time bomb.
- The Stack: Trivy (Container Scanning), Cosign (Image Signing), OPA/Kyverno (Admission Policies), and GitHub Actions (Automated Enforcement).
- The Verdict: The cost of a security breach is catastrophic. The cost of automating container security into your CI/CD pipeline is one afternoon of engineering work.
The Log4Shell Wake-Up Call
In December 2021, Log4Shell (CVE-2021-44228) exposed a brutal reality: a single vulnerable dependency buried deep inside a Docker image can compromise your entire infrastructure.
Companies that had automated container scanning caught it in hours. Companies that didn't spent weeks scrambling through thousands of containers, manually checking which ones were affected.
If your security strategy is "we'll scan it when we have time," you don't have a security strategy. You have a liability.
The question isn't if your Docker images have vulnerabilities. They do. The question is whether you catch them before or after an attacker does.
Why Docker Hub is Dangerous
Most engineering teams start their Dockerfiles with something like this:
FROM node:18That single line pulls an image from Docker Hub that contains an entire operating system, hundreds of packages, and potentially dozens of known CVEs. You are trusting that every maintainer of every package in that image has perfect security hygiene.
Spoiler: they don't.
The node:18 image contains over 400 packages. At any given time, 10 to 30 of those packages have known vulnerabilities ranging from medium to critical severity.
Deep Dive 1: Scanning Every Build with Trivy
Trivy (by Aqua Security) is an open-source vulnerability scanner that integrates directly into your CI/CD pipeline. It scans your Docker images, Terraform files, and even your package-lock.json for known CVEs.
Here is how to block vulnerable images from ever reaching production:
.github/workflows/security-scan.yml
name: Container Security Scan
on:
push:
branches: [main]
pull_request:
jobs:
scan:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Build Docker Image
run: docker build -t app:${{ github.sha }} .
- name: Run Trivy Scan
uses: aquasecurity/trivy-action@master
with:
image-ref: app:${{ github.sha }}
format: table
exit-code: 1 # FAIL the build on critical CVEs
severity: CRITICAL,HIGH
ignore-unfixed: trueWith exit-code: 1, the CI pipeline fails if Trivy finds any CRITICAL or HIGH severity vulnerability. The developer cannot merge the PR until the vulnerability is fixed. No exceptions. No "we'll fix it later."
Deep Dive 2: Signing Images with Cosign
Scanning catches known vulnerabilities. But how do you prevent someone from pushing a tampered or unauthorized image directly to your container registry?
Cosign (part of the Sigstore project) lets you cryptographically sign your Docker images during CI/CD. Then, your Kubernetes cluster can be configured to only accept images that carry a valid signature.
# Sign the image after building and scanning
cosign sign --key cosign.key ghcr.io/your-org/app:${{ github.sha }}If an attacker gains access to your registry and pushes a malicious image, Kubernetes will refuse to run it because it lacks a valid signature. This is the container equivalent of HTTPS for your supply chain.
Deep Dive 3: Admission Control (The Last Line of Defense)
Even with scanning and signing in CI/CD, a rogue engineer could kubectl apply a pod with a random, unscanned image from Docker Hub. You need a policy engine inside the cluster itself.
Kyverno is a Kubernetes-native policy engine that enforces rules at admission time:
block-unscanned-images.yaml
apiVersion: kyverno.io/v1
kind: ClusterPolicy
metadata:
name: require-image-scan
spec:
validationFailureAction: Enforce
rules:
- name: check-image-registry
match:
any:
- resources:
kinds:
- Pod
validate:
message: >-
Images must come from the approved registry
(ghcr.io/your-org). Public Docker Hub images
are blocked in production.
pattern:
spec:
containers:
- image: "ghcr.io/your-org/*"With this policy, any attempt to deploy an image from Docker Hub, a random registry, or an unsigned source is automatically rejected by the Kubernetes API server. The cluster protects itself.
The Operational Reality (What Breaks)
Implementing DevSecOps is not painless. Here is what to expect:
- False Positives: Trivy will flag vulnerabilities in OS packages your application doesn't even use. Use
.trivyignorefiles wisely, but document every exception with a justification. - Developer Friction: When a CI pipeline starts blocking PRs because of a CVE in a transitive dependency, developers will push back. You need buy-in from engineering leadership that security gates are non-negotiable.
- Base Image Maintenance: If you pin to
node:18.17.1-alpinefor security, you also need a process to regularly rebuild images when new patches are released. Stale pinned images become vulnerable too.
The Payoff
A single data breach costs an average of $4.45 million (IBM 2023). The entire DevSecOps pipeline described in this article can be implemented in a single sprint.
By shifting security scanning into CI/CD, signing images cryptographically, and enforcing admission policies at the cluster level, you create a defense-in-depth architecture that catches threats at every layer.
Your Docker images will stop being a liability and start being a hardened, auditable, production-grade artifact.
Are your containers a security risk? If your team is pulling unscanned images from Docker Hub and deploying them straight to production, you are one CVE away from a catastrophic breach.
I build automated DevSecOps pipelines that catch vulnerabilities before they reach your customers.
Don't wait for the breach. Book a Free Infrastructure Audit.
Get weekly DevOps insights
Join engineers who read my deep-dives on Kubernetes, AWS cost optimization, CI/CD, and infrastructure automation.

DevOps Engineer & Cloud Consultant | FinOps, GitOps & Kubernetes Expert
I build systems that run reliably, scale efficiently, and deploy intelligently. See how I can help your team.