Writing Skills
writing-skills
效率与协作技能,来自 obra/superpowers,查看原文获取完整用途和操作说明。
trivy【部署与运维】Trivy is an open-source scanner from Aqua Security that finds vulnerabilities, exposed secrets, misconfigurations and license problems in container images, filesystems, git repos and IaC files. Use when a user asks to scan a Docker image for CVEs, audit a repo for leaked secrets, check Terraform or Kubernetes manifests for misconfigurations, generate…
独立 GitHub 快照 · 自动分类 · 以原作者文档为准
Trivy is an open-source vulnerability scanner by Aqua Security (current release v0.75.0). One binary scans container images, filesystems and lockfiles, git repositories, SBOMs, and IaC (Terraform, Kubernetes, Dockerfile, CloudFormation, Helm) for known CVEs, misconfigurations, hard-coded secrets and licenses. It needs no account; it downloads a vulnerability database on first use and caches it. Docs: https://trivy.dev/docs/.
Use a package manager, or a release archive verified against its published checksum. Do not pipe the install script into a shell.
brew install trivy # macOS / Linux
# Debian/Ubuntu: add the signed apt repository from the install docs, then: sudo apt-get install trivy
# Or a release archive, verified:
VERSION=0.75.0
curl -sLO https://github.com/aquasecurity/trivy/releases/download/v${VERSION}/trivy_${VERSION}_Linux-64bit.tar.gz
curl -sLO https://github.com/aquasecurity/trivy/releases/download/v${VERSION}/trivy_${VERSION}_checksums.txt
sha256sum --check --ignore-missing trivy_${VERSION}_checksums.txt
tar -xzf trivy_${VERSION}_Linux-64bit.tar.gz trivy
trivy --version
Official container images: aquasec/trivy, ghcr.io/aquasecurity/trivy. Never use v0.69.4 (see Guidelines).
trivy image node:20-alpine
trivy image --severity HIGH,CRITICAL --ignore-unfixed registry.lumenshop.io/api:1.8.2
trivy image --format json --output results.json registry.lumenshop.io/api:1.8.2
trivy image --input api-image.tar # image saved with `docker save`
By default Trivy looks for the image in the local Docker, containerd and Podman stores, then the remote registry (--image-src changes the order). It scans OS packages and language dependencies inside the image.
trivy fs reads lockfiles (package-lock.json, poetry.lock, go.mod, Gemfile.lock ...) without installing anything. Default scanners are vuln,secret; add misconfig or license explicitly.
trivy fs .
trivy fs --scanners vuln,secret,misconfig --severity HIGH,CRITICAL .
trivy fs --scanners license .
trivy repo https://github.com/aquasecurity/trivy-ci-test # scan a remote git repo
trivy config ./terraform/
trivy config --severity HIGH,CRITICAL ./k8s/
Each finding has an ID (for example AWS-0107), the file and line range, and a link to the check at avd.aquasec.com.
trivy fs --format cyclonedx --output sbom.cdx.json . # also: spdx-json
trivy image --format sarif --output trivy.sarif registry.lumenshop.io/api:1.8.2
trivy sbom sbom.cdx.json # scan an existing SBOM for vulnerabilities
trivy image --exit-code 1 --severity CRITICAL --ignore-unfixed registry.lumenshop.io/api:1.8.2
--exit-code 1 makes the command fail when findings match the severity filter (the default exit code is 0 even with findings). Suppress accepted risks with a .trivyignore file (one ID per line, for example CVE-2020-8203) or .trivyignore.yaml with expiry dates. In air-gapped or rate-limited CI, cache ~/.cache/trivy and use --skip-db-update after a first download.
User request: "Check this Node project for vulnerable dependencies and leaked keys before I tag a release."
trivy fs --scanners vuln,secret --severity HIGH,CRITICAL .
Result (tested against a lockfile pinning lodash 4.17.15): a summary table with package-lock.json npm 4 vulnerabilities, then rows such as lodash CVE-2020-8203 HIGH fixed 4.17.15 4.17.19. The agent bumps lodash to the fixed version, reinstalls to refresh the lockfile, and re-runs the scan until the table shows 0.
User request: "Fail the pipeline if our Docker image has fixable critical CVEs, and check the Terraform in infra/."
trivy image --exit-code 1 --severity CRITICAL --ignore-unfixed registry.lumenshop.io/api:${GIT_SHA}
trivy config --exit-code 1 --severity HIGH,CRITICAL infra/
On a bucket without a public access block and a security group open to 0.0.0.0/0 on port 22, trivy config reports AWS-0093 and AWS-0107 with the offending lines and exits 1, which fails the job. Install Trivy in the CI job with the verified-download steps above.
aquasecurity/trivy-action and setup-trivy were replaced with credential-stealing code. Use current releases, verify checksums, and in GitHub Actions pin third-party actions to a full commit SHA, never a tag. Details: https://github.com/aquasecurity/trivy/security/advisories/GHSA-69fq-xp46-6x23.--skip-db-update is set.--ignore-unfixed hides CVEs with no patch yet, which keeps CI actionable but also hides real exposure; report them separately.--skip-dirs, .trivyignore and per-check IDs rather than disabling whole scanners.--input) or a registry image.trivy fs and trivy image scan one target per run, so loop over images in CI.