Grype 的退出码语义:--fail-on 触发时返回 2,扫描失败另算
Grype 是 Anchore 的漏洞扫描器,覆盖容器镜像、文件系统和 SBOM。它在 CI 里最容易被误用的部分不是扫描能力,而是退出码和过滤选项的组合:阈值是否触发、过滤是否把结果清空、扫描本身有没有跑完,这三件事必须区分开。
以下 CLI 行为以 Grype 0.119.0 的文档为准。
安装:
curl -sSfL https://get.anchore.io/grype | sudo sh -s -- -b /usr/local/bin
基本用法:
grype alpine:latest
grype ./my-project
grype sbom:./sbom.json
cat ./sbom.json | grype
grype --from containers-storage localhost/myimage:latest # rootless: podman unshare grype ...
--fail-on 触发时返回 2
CLI 参考里的定义:
-f, --fail-on string set the return code to 2 if a vulnerability is found with a severity >= the given severity,
options=[negligible low medium high critical]
示例输出:
grype alpine:3.10 --fail-on high
[0026] ERROR discovered vulnerabilities at or above the severity threshold, Exit code: 2
严重度由低到高:`negligible
命令组:
completion, config (locations, --load validate), db (check, search, vuln), explain, version
## 参考
- 项目与源码:[github.com/anchore/grype](https://github.com/anchore/grype)
- CLI 参考(0.119.0 生成):[oss.anchore.com/docs/reference/grype/cli/](https://oss.anchore.com/docs/reference/grype/cli/)
- Filter scan results:[oss.anchore.com/docs/guides/filter-results/](https://oss.anchore.com/docs/guides/filter-results/)