Skills2026年4月10日·1 分钟阅读

Trivy — All-in-One Security Scanner for Containers & Code

Trivy is an open-source, comprehensive security scanner that finds vulnerabilities, misconfigurations, secrets, and SBOM issues in containers, Kubernetes, code repos, and clouds.

Agent 就绪

先审查再安装

这个资产需要先审查。复制的指令会要求 Agent dry-run、列出写入项,确认后再继续。

Needs Confirmation · 64/100策略:需确认
Agent 入口
任意 MCP/CLI Agent
类型
Skill
安装
Single
信任
信任等级:Established
入口
step-1.md
先审查命令
npx -y tokrepo@latest install 302fe2bb-3535-11f1-9bc6-00163e2b0d79 --target codex

先 dry-run,确认写入项后再运行此命令。

TL;DR
Trivy finds vulnerabilities, misconfigurations, and secrets across containers, code, and Kubernetes in one scan.
§01

What it is

Trivy is an open-source security scanner by Aqua Security that detects vulnerabilities in OS packages and language dependencies, misconfigurations in Terraform and Dockerfiles, leaked secrets like API keys, and SBOM issues -- all from a single binary with zero configuration. It scans Docker images, Git repositories, Kubernetes clusters, and local filesystems.

Trivy targets DevSecOps engineers, platform teams, and developers who need security scanning integrated into CI/CD pipelines without managing multiple specialized tools.

§02

How it saves time or tokens

Trivy consolidates what used to require four or five separate tools (vulnerability scanner, secret detector, IaC linter, SBOM generator, Kubernetes auditor) into one binary. A single trivy image nginx:latest command replaces a chain of Grype, detect-secrets, checkov, and kube-bench commands. The scanner runs offline-capable with a local vulnerability database, so CI pipelines avoid network round-trips to external APIs.

§03

How to use

  1. Install Trivy:
# macOS
brew install trivy

# Debian/Ubuntu
sudo apt install trivy
  1. Scan a Docker image for vulnerabilities:
trivy image nginx:latest
  1. Scan a Git repository for secrets and misconfigurations:
trivy repo https://github.com/your-org/your-repo
  1. Audit a running Kubernetes cluster:
trivy k8s --report=summary cluster
§04

Example

# Scan a project filesystem with all scanners enabled
trivy fs --scanners vuln,misconfig,secret /path/to/project

# Output as JSON for CI/CD integration
trivy image --format json --output results.json myapp:v2.1

# Fail the build if critical vulnerabilities are found
trivy image --exit-code 1 --severity CRITICAL myapp:v2.1

# Generate an SBOM in CycloneDX format
trivy image --format cyclonedx --output sbom.json myapp:v2.1
§05

Related on TokRepo

§06

Common pitfalls

  • The first scan downloads a vulnerability database (~30MB) which can timeout in air-gapped environments; pre-download with trivy image --download-db-only before going offline
  • Scanning large monorepo filesystems with all scanners enabled can be slow; use --scanners flag to limit to specific scan types
  • The --exit-code 1 flag only triggers on findings matching the specified severity; omitting --severity means any finding fails the build

常见问题

What types of targets can Trivy scan?+

Trivy scans container images, local filesystems, Git repositories, Kubernetes clusters, and cloud infrastructure (AWS, GCP, Azure). Each target type supports the full range of scanners: vulnerabilities, misconfigurations, secrets, and SBOM generation.

How does Trivy compare to Grype or Snyk?+

Grype focuses solely on vulnerability scanning for container images. Snyk is a commercial platform covering vulnerabilities and IaC. Trivy covers vulnerabilities, misconfigurations, secrets, and SBOM in a single open-source binary, making it broader in scope than Grype and free unlike Snyk.

Can Trivy run in CI/CD pipelines?+

Yes. Trivy provides JSON, SARIF, and table output formats. The --exit-code flag lets you fail builds on findings. Official GitHub Actions, GitLab CI templates, and Jenkins plugins are available. The scanner runs as a single binary with no daemon or server dependency.

Does Trivy work offline?+

Trivy can work offline after the initial vulnerability database download. Run 'trivy image --download-db-only' to cache the database, then use '--skip-db-update' for subsequent scans. This is useful for air-gapped environments.

What secret types does Trivy detect?+

Trivy detects API keys, passwords, tokens, private keys, and other credentials embedded in source code, Dockerfiles, and container image layers. It uses pattern matching and entropy analysis to minimize false positives.

引用来源 (3)

讨论

登录后参与讨论。
还没有评论,来写第一条吧。

相关资产