trivy-db 是一个用于操作 Trivy DB 的 CLI 工具和库。
Trivy 在内部使用 trivy-db 来操作漏洞数据库。该数据库包含来自 NVD、Red Hat、Debian 等的漏洞信息。
trivy-db CLI 工具用于构建漏洞数据库。GitHub Actions 工作流 会定期使用 trivy-db 构建新版本的漏洞数据库,并将其上传到 GitHub Container Registry(请参阅下面的下载漏洞数据库)。
NAME:
trivy-db - Trivy DB builder
USAGE:
main [global options] command [command options] image_name
VERSION:
0.0.1
COMMANDS:
build build a database file
help, h Shows a list of commands or help for one command
GLOBAL OPTIONS:
--help, -h show help
--version, -v print the version
要在本地构建 trivy-db,可以按以下顺序使用 Makefile 中的命令:
make db-fetch-langs db-fetch-vuln-list # To download all advisories and other required files (`./cache` dir by default)
make build # Build `trivy-db` binary
make db-build # Build database (`./out` dir by default)
make db-compact # Compact database (`./assets` dir by default)
make db-compress # Compress database into `db.tar.gz` file
要构建 trivy-db 镜像并推送到 registry,你需要使用 Oras CLI。例如对于 ghcr:
./oras push --artifact-type application/vnd.aquasec.trivy.config.v1+json \
"ghcr.io/aquasecurity/trivy-db:2" \
db.tar.gz:application/vnd.aquasec.trivy.db.layer.v1.tar+gzip
Trivy DB 每 6 小时构建一次。 默认情况下,元数据文件中指定的更新间隔为 24 小时。 如果你需要更频繁地更新 Trivy DB,你可以手动上传一个新的 Trivy DB。
Trivy DB v1 已于 2023 年 2 月停止支持。请升级 Trivy 至 v0.23.0 或更高版本。
在讨论中阅读更多关于 Trivy DB v1 弃用的信息。
Trivy DB v2 托管在 GHCR 上。
虽然 GitHub 默认显示 docker pull 命令,但请注意它不能被 docker pull 下载,因为它不是容器镜像。
你可以通过 Trivy 或 Oras CLI 下载实际编译好的数据库。
Trivy:
TRIVY_TEMP_DIR=$(mktemp -d)
trivy --cache-dir $TRIVY_TEMP_DIR image --download-db-only
tar -cf ./db.tar.gz -C $TRIVY_TEMP_DIR/db metadata.json trivy.db
rm -rf $TRIVY_TEMP_DIR
oras >= v0.13.0:
$ oras pull ghcr.io/aquasecurity/trivy-db:2
oras < v0.13.0:
$ oras pull -a ghcr.io/aquasecurity/trivy-db:2
该数据库可用于离线环境。