Performing Container Security Scanning with Trivy
Overview
Trivy is an open-source security scanner by Aqua Security that detects vulnerabilities in OS packages and language-specific dependencies, infrastructure-as-code misconfigurations, exposed secrets, and software license issues across container images, filesystems, Git repositories, and Kubernetes clusters. Trivy generates Software Bill of Materials (SBOM) in CycloneDX and SPDX formats for supply chain transparency. This skill covers comprehensive container image scanning, CI/CD pipeline integration, Kubernetes operator deployment, and scan result triage for security operations.
When to Use
Trigger phrases:
"performing container security scanning with trivy"
"Scan container images, filesystems, and Kubernetes manifests for vulnerabilities"
When conducting security assessments that involve performing container security scanning with trivy
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
- Trivy v0.50+ installed (binary, Docker, or Homebrew)
- Docker daemon access for local image scanning
- Container registry credentials for remote image scanning
- CI/CD platform (GitHub Actions, GitLab CI, Jenkins) for pipeline integration
- Kubernetes cluster for Trivy Operator deployment (optional)
Steps
# Example: IOC detection
import re
IOC_PATTERNS = {
"ip": r"\b(?:\d{1,3}\.){3}\d{1,3}\b",
"domain": r"\b[a-z0-9-]+\.[a-z]{2,}\b",
"hash_md5": r"\b[a-f0-9]{32}\b",
"hash_sha256": r"\b[a-f0-9]{64}\b",
}
def extract_iocs(text: str) -> dict:
return {k: re.findall(v, text) for k, v in IOC_PATTERNS.items()}
- Prepare the environment — ensure write-blocker is connected and test workstation is ready
- Document the source — record device serial, model, and pre-acquisition hash
- Acquire the image — use the appropriate tool with hash verification enabled
- Verify integrity — compare source and image hashes; document any discrepancies
- Analyze and report — perform the analysis and document findings with chain of custody
Step 1: Scan Container Images
Run vulnerability and secret scanning against container images from local builds or remote registries. Configure severity thresholds and ignore unfixed vulnerabilities.
Step 2: Generate SBOM
Produce CycloneDX or SPDX SBOM documents from scanned images for supply chain compliance and vulnerability tracking across the software lifecycle.
Step 3: Scan IaC and Kubernetes Manifests
Detect misconfigurations in Dockerfiles, Kubernetes YAML, Terraform, and Helm charts using built-in policy checks aligned with CIS benchmarks.
Step 4: Integrate into CI/CD
Add Trivy scanning as a pipeline gate that blocks builds with critical/high vulnerabilities, generates SARIF reports for GitHub Advanced Security, and produces JUnit XML for test dashboards.
Expected Output
JSON/table report listing CVEs with severity, CVSS scores, fixed versions, affected packages, misconfiguration findings, and exposed secrets with file locations.
When NOT to Use
- You don't have explicit written authorization to test
- Task is about defense/detection, not offense (use detection skills)
- You need to implement security controls (use implementing-* skills)
- Task requires compliance auditing (use auditing-* skills)
- You're investigating an incident (use incident response skills)
- Target is out of scope for your engagement
- Task is about vulnerability scanning only (use scanning tools)
Red Flags
- Performing actions without explicit written authorization from the asset owner
- Testing against production systems without a defined scope and rules of engagement
- Failing to use write-blockers when acquiring forensic evidence
- Not verifying hash integrity before and after imaging
- Modifying original evidence during analysis
Process
- Reconnaissance — Gather target information, identify attack surface, enumerate services
- Analysis/Exploitation — Execute the technique, analyze results, document findings
- Reporting — Document IOCs, write findings, provide remediation recommendations
Verification
- All steps executed successfully against a test environment before production use
- Output documented with screenshots or logs demonstrating expected behavior
- Hash values computed and verified match between source and image
- Chain of custody log complete with timestamps and examiner names
- Analysis tools and versions documented for reproducibility
Anti-Rationalization Table
| Rationalization |
Reality |
| "We are too small to be targeted" |
Automated attacks target everyone. Size does not matter. |
| "Security slows us down" |
A breach slows you down 100x more. Build security in from the start. |
| "We will fix it after launch" |
Vulnerabilities in production are exploited within hours. Fix before deploy. |
1---2name: performing-container-security-scanning-with-trivy3description: Use when scan container images, filesystems, and Kubernetes manifests4 for vulnerabilities, misconfigurations, exposed secrets, and license compliance5 issues using Aqua Security Trivy with SBOM generation and CI/CD integration. Use6 when scaning container images, filesystems, and kubernetes manifests for vulnerabilities,7 misconfigurations,.8domain: cybersecurity9subdomain: container-security10tags:11- trivy12- container-security13- vulnerability-scanning14- sbom15- docker16- kubernetes17- devsecops18- supply-chain19version: '1.0'20author: oyi7721license: Apache-2.022nist_csf:23- PR.PS-0124- PR.IR-0125- ID.AM-0826- DE.CM-0127category: cybersecurity28metadata:29 source: https://skillmd.com/skills/oyi77/performing-container-security-scanning-with-trivy30---313233# Performing Container Security Scanning with Trivy3435## Overview3637Trivy is an open-source security scanner by Aqua Security that detects vulnerabilities in OS packages and language-specific dependencies, infrastructure-as-code misconfigurations, exposed secrets, and software license issues across container images, filesystems, Git repositories, and Kubernetes clusters. Trivy generates Software Bill of Materials (SBOM) in CycloneDX and SPDX formats for supply chain transparency. This skill covers comprehensive container image scanning, CI/CD pipeline integration, Kubernetes operator deployment, and scan result triage for security operations.383940## When to Use41**Trigger phrases:**42- "performing container security scanning with trivy"43- "Scan container images, filesystems, and Kubernetes manifests for vulnerabilities"444546- When conducting security assessments that involve performing container security scanning with trivy47- When following incident response procedures for related security events48- When performing scheduled security testing or auditing activities49- When validating security controls through hands-on testing5051## Prerequisites5253- Trivy v0.50+ installed (binary, Docker, or Homebrew)54- Docker daemon access for local image scanning55- Container registry credentials for remote image scanning56- CI/CD platform (GitHub Actions, GitLab CI, Jenkins) for pipeline integration57- Kubernetes cluster for Trivy Operator deployment (optional)5859## Steps6061```python62# Example: IOC detection63import re6465IOC_PATTERNS = {66 "ip": r"\b(?:\d{1,3}\.){3}\d{1,3}\b",67 "domain": r"\b[a-z0-9-]+\.[a-z]{2,}\b",68 "hash_md5": r"\b[a-f0-9]{32}\b",69 "hash_sha256": r"\b[a-f0-9]{64}\b",70}7172def extract_iocs(text: str) -> dict:73 return {k: re.findall(v, text) for k, v in IOC_PATTERNS.items()}74```75761. **Prepare the environment** — ensure write-blocker is connected and test workstation is ready772. **Document the source** — record device serial, model, and pre-acquisition hash783. **Acquire the image** — use the appropriate tool with hash verification enabled794. **Verify integrity** — compare source and image hashes; document any discrepancies805. **Analyze and report** — perform the analysis and document findings with chain of custody81### Step 1: Scan Container Images8283Run vulnerability and secret scanning against container images from local builds or remote registries. Configure severity thresholds and ignore unfixed vulnerabilities.8485### Step 2: Generate SBOM8687Produce CycloneDX or SPDX SBOM documents from scanned images for supply chain compliance and vulnerability tracking across the software lifecycle.8889### Step 3: Scan IaC and Kubernetes Manifests9091Detect misconfigurations in Dockerfiles, Kubernetes YAML, Terraform, and Helm charts using built-in policy checks aligned with CIS benchmarks.9293### Step 4: Integrate into CI/CD9495Add Trivy scanning as a pipeline gate that blocks builds with critical/high vulnerabilities, generates SARIF reports for GitHub Advanced Security, and produces JUnit XML for test dashboards.9697## Expected Output9899JSON/table report listing CVEs with severity, CVSS scores, fixed versions, affected packages, misconfiguration findings, and exposed secrets with file locations.100## When NOT to Use101102- You don't have explicit written authorization to test103- Task is about defense/detection, not offense (use detection skills)104- You need to implement security controls (use implementing-* skills)105- Task requires compliance auditing (use auditing-* skills)106- You're investigating an incident (use incident response skills)107- Target is out of scope for your engagement108- Task is about vulnerability scanning only (use scanning tools)109110111## Red Flags112113- Performing actions without explicit written authorization from the asset owner114- Testing against production systems without a defined scope and rules of engagement115- Failing to use write-blockers when acquiring forensic evidence116- Not verifying hash integrity before and after imaging117- Modifying original evidence during analysis118119## Process1201211. **Reconnaissance** — Gather target information, identify attack surface, enumerate services1221. **Analysis/Exploitation** — Execute the technique, analyze results, document findings1231. **Reporting** — Document IOCs, write findings, provide remediation recommendations124125## Verification126127- All steps executed successfully against a test environment before production use128- Output documented with screenshots or logs demonstrating expected behavior129- Hash values computed and verified match between source and image130- Chain of custody log complete with timestamps and examiner names131- Analysis tools and versions documented for reproducibility132133## Anti-Rationalization Table134135| Rationalization | Reality |136|---|---|137| "We are too small to be targeted" | Automated attacks target everyone. Size does not matter. |138| "Security slows us down" | A breach slows you down 100x more. Build security in from the start. |139| "We will fix it after launch" | Vulnerabilities in production are exploited within hours. Fix before deploy. |