Skip to content

Security & secrets: Trivy

Trivy commands from the Security & secrets folder.

Index
6 items

Trivy: Scan an image for high and critical CVEs

Safe

Only vulnerabilities that actually have a fix available.

trivy image --severity HIGH,CRITICAL --ignore-unfixed <image>:<tag>
What each part does
  1. trivy imagescan a container image (OS packages + app dependencies)
  2. --severity HIGH,CRITICALonly show these severities
  3. --ignore-unfixedhide vulnerabilities with no fix available
  4. <image>:<tag>the image

Also known as: cve scan · image scan

Trivy: Fail CI on critical vulnerabilities

Safe

Non-zero exit when a fixable critical CVE is found: use as a pipeline gate.

trivy image --exit-code 1 --severity CRITICAL --ignore-unfixed <image>:<tag>
What each part does
  1. trivy imagescan a container image
  2. --exit-code 1exit with 1 if anything is found, so the CI job fails
  3. --severity CRITICALonly count critical findings
  4. --ignore-unfixedskip vulnerabilities with no fixed version yet
  5. <image>:<tag>the image to scan

Also known as: security gate · pipeline scan

Trivy: Scan a repo for secrets and misconfigurations

Safe

Dependencies, hard-coded secrets and IaC misconfigurations in a directory.

trivy fs --scanners vuln,secret,misconfig <path>
What each part does
  1. trivy fsscan a local directory
  2. --scanners vuln,secret,misconfigdependency CVEs, hard-coded secrets, and IaC / Dockerfile misconfigurations
  3. <path>the directory, e.g. .

Also known as: leaked secret · secret scanning

Trivy: Scan Terraform or Kubernetes manifests

Safe

Misconfiguration checks for Terraform, Kubernetes YAML, Helm charts and Dockerfiles.

trivy config <path>
What each part does
  1. trivy configscan IaC files: Terraform, Kubernetes YAML, Helm, Dockerfiles, CloudFormation
  2. <path>directory or file to scan

Also known as: tfsec · iac scan · kubernetes misconfig

Trivy: Generate an SBOM for an image

Safe

Software bill of materials in CycloneDX format (use spdx-json for SPDX).

trivy image --format cyclonedx --output sbom.json <image>:<tag>
What each part does
  1. trivy imagescan a container image
  2. --format cyclonedxoutput a CycloneDX SBOM (or spdx-json)
  3. --output sbom.jsonwrite to this file
  4. <image>:<tag>the image
  • #trivy
  • #sbom

Also known as: sbom · cyclonedx · spdx

Trivy: Scan the current Kubernetes cluster

Safe

Vulnerabilities and misconfigurations across workloads in the current kube context.

trivy k8s --report summary
What each part does
  1. trivy k8sscan the cluster in the current kubeconfig context: workload images, configs, RBAC
  2. --report summaryone table of counts per resource instead of every finding (all for full detail)

Also known as: cluster scan · k8s

My DevOps Playbook by Angelo John Calleja

New runbook

GitHub not connected

Saving is handled by the site: the GitHub token is stored in Cloudflare, not in your browser. Enter the editor password (the EDITOR_PASSWORD secret) to unlock saving in this browser.

Saving commits to gelogrammer/My_DevOps_Playbook. Create a fine-grained token with access to only this repo andContents: Read and write, then paste it here. It is stored only in this browser.

src/content/docs/…