Trivy vulnerability scanner

From seaworld008/Commonly-used-high-value-skills · View interactive version

Trivy vulnerability scanner is an AI agent skill from the GitHub repository seaworld008/Commonly-used-high-value-skills. Use when scanning repos, container images, filesystems, SBOMs, Kubernetes, or IaC with Trivy for CVEs, misconfigurations, secrets, and license issues.

How to use this skill

Skill file

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:

Core Capabilities

Workflow

1. Identify the Target

Classify the target before running commands:

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

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:

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

For a container image:

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

For Kubernetes manifests:

trivy config --severity HIGH,CRITICAL ./deploy

For an unpacked Linux root filesystem:

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

4. Produce Machine-Readable Output

Use JSON for triage automation:

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

Use SARIF for GitHub code scanning:

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

Generate an SBOM when the user needs inventory:

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:

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:

Common Patterns

CI Gate for Containers

Set TRIVY_IMAGE to the reviewed Trivy CLI image pinned by digest. The hosted runner builds the target and passes its saved archive to that scanner.

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 with pinned Trivy
        env:
          TRIVY_IMAGE: ${{ vars.TRIVY_IMAGE }}
        run: |
          docker save "app:${{ github.sha }}" -o "${RUNNER_TEMP}/app.tar"
          docker run --rm "$TRIVY_IMAGE" --version
          docker run --rm -v "${RUNNER_TEMP}/app.tar:/input/app.tar:ro" "$TRIVY_IMAGE" \
            image --input /input/app.tar --exit-code 1 --severity HIGH,CRITICAL --ignore-unfixed

Repo Scan with SARIF Upload

The following steps assume the same reviewed Trivy version is provisioned on the job's PATH. Record trivy --version before scanning.

- 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

Use the expiry field supported by the pinned scanner's ignore-file format. Record the finding ID, scope, owner, reason and expiry together. If using a plain ID list, enforce the expiry in CI before invoking Trivy. A date in a comment does not expire an entry.

Check with a fixture containing an expired exception and a current one. The gate must fail for the expired entry or surface the finding again.

Interpretation Rules

Boundaries

Reference Sources

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.