trivy-vulnerability-scanner

$npx mdskill add seaworld008/Commonly-used-high-value-skills/trivy-vulnerability-scanner

Scan codebases, containers, and K8s for CVEs and misconfigurations using Trivy.

  • Scans repositories, container images, filesystems, and Kubernetes for vulnerabilities.
  • Uses Trivy CLI to analyze OS packages, dependencies, IaC, and secrets.
  • Determines scan type based on user request: image, repo, fs, k8s, or sbom.
  • Outputs results as SARIF, JSON, or table for CI or agent consumption.

SKILL.md

.github/skills/trivy-vulnerability-scannerView on GitHub ↗
---
name: trivy-vulnerability-scanner
description: '用于通过 Trivy 扫描仓库、容器镜像、文件系统、rootfs、SBOM、Kubernetes、IaC、密钥、许可证和系统 CVE。'
zh_description: "用于通过 Trivy 扫描仓库、容器镜像、文件系统、rootfs、SBOM、Kubernetes、IaC、密钥、许可。"
version: "1.0.0"
author: seaworld008
source: "in-house"
source_url: ""
tags: '[security, vulnerability-scanning, cve, container-security, kubernetes, sbom, iac, secrets]'
created_at: "2026-05-20"
updated_at: "2026-05-20"
quality: 4
complexity: advanced
---

# Trivy Vulnerability Scanner

## Trigger / When to Use

Use this skill when the user asks to scan a codebase, container image, Linux root filesystem, Kubernetes cluster, SBOM, or repository for CVEs, misconfigurations, exposed secrets, or license risks with Trivy.

Good trigger phrases:
- "scan this Docker image for CVEs"
- "run Trivy on this repo"
- "check Kubernetes manifests for vulnerabilities"
- "generate a SARIF vulnerability report"
- "scan a Linux rootfs or container filesystem"
- "fail CI on critical fixable CVEs"

## Core Capabilities

- Vulnerability scanning for OS packages and application dependencies.
- Container image scanning from local engines or remote registries.
- Filesystem and root filesystem scanning for source trees and unpacked images.
- Repository scanning for git URLs or local project directories.
- Kubernetes scanning for cluster and resource risk review.
- IaC misconfiguration checks for Kubernetes YAML, Dockerfiles, Terraform, and related config.
- Secret scanning for committed tokens, keys, and credentials.
- License scanning and SPDX/CycloneDX SBOM workflows.
- SARIF, JSON, table, template, and GitHub-friendly reporting.

## Workflow

### 1. Identify the Target

Classify the target before running commands:
- Source repository: use `trivy repo` or `trivy fs`.
- Container image: use `trivy image`.
- Unpacked root filesystem: use `trivy rootfs`.
- Kubernetes cluster or manifests: use `trivy k8s` or `trivy config`.
- SBOM file: use `trivy sbom`.
- VM image or filesystem archive: prefer image/rootfs modes when supported.

Ask only if the target is ambiguous and a wrong scan could be destructive or very slow. Otherwise choose the narrowest safe scan mode.

### 2. Install or Verify Trivy

```bash
trivy --version
```

If missing, recommend the official installation path for the user's OS. Avoid piping remote install scripts into a privileged shell unless the user explicitly approves.

### 3. Run a Baseline Scan

Use a read-only baseline first:

```bash
trivy fs --scanners vuln,secret,misconfig --severity HIGH,CRITICAL --ignore-unfixed .
```

For a container image:

```bash
trivy image --scanners vuln,secret,misconfig --severity HIGH,CRITICAL nginx:latest
```

For Kubernetes manifests:

```bash
trivy config --severity HIGH,CRITICAL ./deploy
```

For an unpacked Linux root filesystem:

```bash
trivy rootfs --severity HIGH,CRITICAL /mnt/rootfs
```

### 4. Produce Machine-Readable Output

Use JSON for triage automation:

```bash
trivy fs --format json --output trivy-results.json .
```

Use SARIF for GitHub code scanning:

```bash
trivy fs --format sarif --output trivy-results.sarif .
```

Generate an SBOM when the user needs inventory:

```bash
trivy fs --format cyclonedx --output sbom.cdx.json .
trivy image --format spdx-json --output image.spdx.json registry.example.com/app:tag
```

### 5. Triage Findings

For each HIGH or CRITICAL finding, capture:
- Package or dependency name.
- Installed version and fixed version.
- Vulnerability ID.
- Target path or image layer when available.
- Whether the finding is fixable.
- Runtime reachability or deployment exposure, if known.

Prioritize in this order:
1. Critical fixable vulnerabilities in internet-facing services.
2. High fixable vulnerabilities in runtime packages.
3. Secret findings with active credentials.
4. Misconfigurations that expose privilege escalation or public access.
5. License violations that affect distribution.

### 6. Remediate Safely

Common remediation moves:
- Upgrade base images to patched digests.
- Rebuild images after OS package updates.
- Upgrade direct dependencies before forcing transitive overrides.
- Remove unused OS packages from images.
- Replace broad Kubernetes permissions with least-privilege RBAC.
- Rotate leaked secrets before removing them from git history.
- Document accepted false positives with `.trivyignore` and an expiration date.

## Common Patterns

### CI Gate for Containers

```yaml
name: trivy
on: [pull_request]
jobs:
  scan:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - name: Build image
        run: docker build -t app:${{ github.sha }} .
      - name: Scan image
        run: |
          trivy image \
            --exit-code 1 \
            --severity HIGH,CRITICAL \
            --ignore-unfixed \
            app:${{ github.sha }}
```

### Repo Scan with SARIF Upload

```yaml
- name: Trivy repo scan
  run: trivy fs --format sarif --output trivy.sarif .
- name: Upload SARIF
  uses: github/codeql-action/upload-sarif@v3
  with:
    sarif_file: trivy.sarif
```

### Ignore File with Expiration

```text
# .trivyignore
# CVE accepted until 2026-06-30 because upstream has no fixed Alpine package.
CVE-2026-0000
```

## Interpretation Rules

- Do not treat every CVE as equally exploitable.
- Vendor package status matters; Debian, Ubuntu, Red Hat, Alpine, and language ecosystems may report fixes differently.
- Prefer fixed-version and vendor advisory evidence over raw CVSS alone.
- Treat scanner output as a queue for triage, not as final proof of exploitability.
- Keep a record of accepted risks with owner, reason, and review date.

## Boundaries

- Do not run destructive cleanup commands during scanning.
- Do not upload proprietary SBOMs or source metadata to third-party services without user approval.
- Do not suppress findings globally to make CI green.
- Do not claim a clean scan proves the system is secure.
- Do not scan production Kubernetes clusters with broad permissions unless the user has authorized that scope.

## Reference Sources

- Trivy docs: https://trivy.dev/latest/docs/
- Vulnerability scanning: https://trivy.dev/docs/latest/scanner/vulnerability/
- Secret scanning: https://www.trivy.dev/docs/v0.55/guide/scanner/secret/
- License scanning: https://www.trivy.dev/docs/latest/scanner/license/

More from seaworld008/Commonly-used-high-value-skills

SkillDescription
agent-hubMulti-agent collaboration plugin that spawns N parallel subagents competing on the same task via git worktree isolation. Agents work independently, results are evaluated by metric or LLM judge, and the best branch is merged. Use when: user wants multiple approaches tried in parallel — code optimization, content variation, research exploration, or any task that benefits from parallel competition. Requires: a git repo.
andrej-karpathy-skillsKarpathy-inspired coding discipline for AI agents: think before coding, keep changes simple, edit surgically, and define verifiable success criteria before implementation.
arenaSpecialist orchestrating codex exec / Antigravity CLI through dual paradigms — COMPETE (multi-variant comparison, select best) and COLLABORATE (decompose tasks across engines, integrate). Supports Solo/Team/Quick execution modes.
azure-kubernetesPlan, create, and configure production-ready Azure Kubernetes Service (AKS) clusters. Covers Day-0 checklist, SKU selection (Automatic vs Standard), networking options (private API server, Azure CNI Overlay, egress configuration), security, and operations (autoscaling, upgrade strategy, cost analysis). WHEN: create AKS environment, provision AKS, enable AKS observability, design AKS networking, choose AKS SKU, secure AKS, optimize AKS, AKS spot nodes, AKS cluster-autoscaler, rightsize AKS pod, pod rightsizing, over-provisioned AKS pod, pod resource requests and limits, Vertical Pod Autoscaler, VPA recommendations.
azure-kubernetes-automatic-readinessAssess Kubernetes workloads and cluster configuration for AKS Automatic compatibility. Identifies incompatibilities, generates fixes, and guides migration from AKS Standard to AKS Automatic. WHEN: migrate to AKS Automatic, check AKS Automatic readiness, validate manifests for Automatic, assess cluster for Automatic compatibility, fix deployment for Automatic compatibility, identify AKS Automatic migration blockers, is my cluster ready for AKS Automatic.
cc-devops-skillsSRE, DevOps, Kubernetes, CI/CD, PromQL, Terraform, Docker, and incident operations playbook for building reliable delivery and operations workflows.
chatgpt-appsBuild, scaffold, refactor, and troubleshoot ChatGPT Apps SDK applications that combine an MCP server and widget UI. Use when Codex needs to design tools, register UI resources, wire the MCP Apps bridge or ChatGPT compatibility APIs, apply Apps SDK metadata or CSP or domain settings, or produce a docs-aligned project scaffold. Prefer a docs-first workflow by invoking the openai-docs skill or OpenAI developer docs MCP tools before generating code.
clayAI 3D model generation agent. Generates text-to-3D and image-to-3D code (Python/JS/OpenSCAD) using Meshy, Tripo, Hunyuan3D, Rodin, Sloyd, and Stability APIs. Handles game pipeline integration, LOD, retopology, UV, and QC validation.
codeql-security-scanner用于通过 CodeQL 执行语义代码扫描、安全查询、自定义规则、SARIF 报告和 GitHub Code Scanning 集成。
complyRegulatory compliance and audit agent. Maps business regulatory requirements (SOC2/PCI-DSS/HIPAA/ISO 27001), checks control implementations, designs audit trails, and implements Policy as Code. Use when compliance auditing is needed.