Scanning DevContainer Images for Vulnerabilities
A pinned base image is reproducible but not automatically safe — it can carry known CVEs. This page scans the devcontainer image with trivy (or grype) and gates on criticals in CI, so a vulnerable base never reaches developers unnoticed.
Prerequisites
You need a scanner and the pinned image to scan.
trivyorgrypeinstalled (or a scan action in CI).- The digest-pinned image reference.
- A CI step to run and gate the scan.
Step-by-Step Implementation
- Scan the pinned image, failing on criticals.
trivy image --severity CRITICAL --exit-code 1 \
mcr.microsoft.com/devcontainers/base@sha256:PINNED
- Add it to CI so a vulnerable base fails the build.
- run: trivy image --severity CRITICAL,HIGH --exit-code 1 $IMAGE
- Generate an SBOM alongside for auditability.
syft $IMAGE -o spdx-json > sbom.spdx.json
- Refresh the pinned digest when a scan flags a fixable CVE.
Common Pitfalls
Scan gaps are no gate, scanning a tag not a digest, or never refreshing.
| Symptom | Root Cause | Remediation |
|---|---|---|
| Critical CVE reaches developers | No scan gate in CI | Add trivy/grype with --exit-code 1 |
| Scan result drifts from reality | Scanned a tag, not a digest | Scan the pinned @sha256 digest |
| Base never gets CVE fixes | Digest pinned, never refreshed | Refresh the digest on fixable CVEs |
| Can't answer 'are we affected?' | No SBOM | Generate and store an SBOM per build |
Conclusion
Pinning makes the base reproducible; scanning makes it safe. Run trivy or grype against the pinned digest in CI, fail on criticals, and refresh the pin when a fixable CVE appears. Add an SBOM and vulnerability response becomes a query instead of an investigation.
FAQ
Isn't a pinned image already safe? Pinning makes it reproducible, not safe — the exact bytes you pinned can still contain known CVEs discovered later. Scan the pinned digest against vulnerability databases and gate on criticals, so 'reproducible' and 'safe' are both guaranteed.
Should I scan the tag or the digest?
The digest — the exact image you ship. Scanning a tag can drift from what actually builds. Scan base@sha256:…, the same reference you pinned in devcontainer.json, so the scan result describes the real artifact.
How do I respond when a scan flags a CVE? If a fix exists upstream, refresh the pinned digest to the patched image, re-scan, regenerate the SBOM, and commit it as a reviewed change. The SBOM lets you quickly answer which projects are affected without rebuilding each one.
Related
- Up to DevContainer Security & Secrets Management — the overview of hardening.
- Generating an SBOM for a DevContainer Image — the provenance companion to scanning.
- Pinning Base Image Digests with sha256 — the pins you scan and refresh.