Skill v1.0.1
currentAutomated scan100/100+8 new
name: scanning-container-images-with-grype description: >- Scans container images, filesystems, and SBOMs for known CVEs with Anchore Grype, matching Syft-generated SBOM packages against NVD, GitHub Advisories, and OS-specific feeds with configurable severity thresholds and failure gates. Use when Grype or Syft is the chosen toolchain, when scanning an existing SBOM rather than an image, or when gating a build on severity. Keywords: Grype, Syft, SBOM, NVD, GitHub Advisory, --fail-on, severity threshold. Do not use when the toolchain is Trivy - use scanning-docker-images-with-trivy. domain: cybersecurity subdomain: container-security tags:
- grype
- vulnerability-scanning
- container-security
- sbom
- anchore
- supply-chain
version: '1.0' author: mahipal license: Apache-2.0 nist_csf:
- PR.PS-01
- PR.IR-01
- ID.AM-08
- DE.CM-01
mitre_attack:
- T1610
- T1611
- T1609
- T1525
- T1195
Scanning Container Images with Grype
Overview
Grype is an open-source vulnerability scanner from Anchore that inspects container images, filesystems, and SBOMs for known CVEs. It leverages Syft-generated SBOMs to match packages against multiple vulnerability databases including NVD, GitHub Advisories, and OS-specific feeds.
When to Use
- When conducting security assessments that involve scanning container images with grype
- When following incident response procedures for related security events
- When performing scheduled security testing or auditing activities
- When validating security controls through hands-on testing
Prerequisites
- Docker or Podman installed
- Grype CLI installed (
curl -sSfL https://raw.githubusercontent.com/anchore/grype/main/install.sh | sh -s -- -b /usr/local/bin) - Syft CLI (optional, for SBOM generation)
- Network access to pull vulnerability databases
Core Commands
Install Grype
# Install via scriptcurl -sSfL https://raw.githubusercontent.com/anchore/grype/main/install.sh | sh -s -- -b /usr/local/bin# Verify installationgrype version# Install via Homebrew (macOS/Linux)brew install grype
Scan Container Images
# Scan a Docker Hub imagegrype nginx:latest# Scan from Docker daemongrype docker:myapp:1.0# Scan a local archivegrype docker-archive:image.tar# Scan an OCI directorygrype oci-dir:path/to/oci/# Scan a Singularity imagegrype sif:image.sif# Scan a local directory / filesystemgrype dir:/path/to/project
Output Formats
# Default table outputgrype alpine:3.18# JSON output for pipeline processinggrype alpine:3.18 -o json > results.json# CycloneDX SBOM outputgrype alpine:3.18 -o cyclonedx# SARIF output for GitHub Security tabgrype alpine:3.18 -o sarif > grype.sarif# Template-based custom outputgrype alpine:3.18 -o template -t /path/to/template.tmpl
Filtering and Thresholds
# Fail if vulnerabilities meet or exceed a severitygrype nginx:latest --fail-on critical# Show only fixed vulnerabilitiesgrype nginx:latest --only-fixed# Show only non-fixed vulnerabilitiesgrype nginx:latest --only-notfixed# Filter by severitygrype nginx:latest --only-fixed -o json | jq '[.matches[] | select(.vulnerability.severity == "High")]'# Explain a specific CVEgrype nginx:latest --explain --id CVE-2024-1234
Working with SBOMs
# Generate SBOM with Syft then scansyft nginx:latest -o spdx-json > nginx-sbom.jsongrype sbom:nginx-sbom.json# Scan CycloneDX SBOMgrype sbom:bom.json
Configuration File (.grype.yaml)
# .grype.yamlcheck-for-app-update: falsefail-on-severity: "high"output: "json"scope: "squashed" # or "all-layers"quiet: falseignore:- vulnerability: CVE-2023-12345reason: "False positive - not exploitable in our context"- vulnerability: CVE-2023-67890fix-state: unknowndb:auto-update: truecache-dir: "/tmp/grype-db"max-allowed-built-age: 120h # 5 daysmatch:java:using-cpes: truepython:using-cpes: truejavascript:using-cpes: false
CI/CD Integration
# GitHub Actions- name: Scan image with Grypeuses: anchore/scan-action@v4with:image: "myregistry/myapp:${{ github.sha }}"fail-build: trueseverity-cutoff: highoutput-format: sarifid: scan- name: Upload SARIFuses: github/codeql-action/upload-sarif@v3with:sarif_file: ${{ steps.scan.outputs.sarif }}
# GitLab CIcontainer_scan:stage: testimage: anchore/grype:latestscript:- grype ${CI_REGISTRY_IMAGE}:${CI_COMMIT_SHA} --fail-on high -o json > grype-report.jsonartifacts:reports:container_scanning: grype-report.json
Database Management
# Check database statusgrype db status# Manually update vulnerability databasegrype db update# Delete cached databasegrype db delete# List supported database providersgrype db list
Key Vulnerability Sources
| Source | Coverage | |
|---|---|---|
| NVD | CVEs across all ecosystems | |
| GitHub Advisories | Open source package vulnerabilities | |
| Alpine SecDB | Alpine Linux packages | |
| Amazon Linux ALAS | Amazon Linux AMI | |
| Debian Security Tracker | Debian packages | |
| Red Hat OVAL | RHEL, CentOS | |
| Ubuntu Security | Ubuntu packages | |
| Wolfi SecDB | Wolfi/Chainguard images |
Best Practices
- Pin image tags - Always scan specific digests, not
latest - Fail on severity - Set
--fail-on highorcriticalin CI gates - Use SBOMs - Generate SBOMs with Syft for reproducible scanning
- Suppress false positives - Use
.grype.yamlignore rules with documented reasons - Scan all layers - Use
--scope all-layersto catch vulnerabilities in intermediate layers - Automate database updates - Keep the vulnerability database current in CI runners
- Compare scans - Track vulnerability count over time for regression detection