grype

容器镜像与文件系统漏洞扫描

补充说明

grype 使用 Anchore 漏洞库扫描容器镜像、目录和 SBOM,输出操作系统包和语言依赖的已知漏洞。它适合 CI 门禁和镜像发布前检查。

常用示例

grype alpine:3.20
grype registry.example.com/app:1.0
grype dir:.
grype sbom:app.spdx.json
grype docker:app:latest -o json > report.json
grype alpine:3.20 --fail-on high
grype alpine:3.20 --only-fixed
grype db update

.grype.yaml:

fail-on-severity: high
output: table
ignore:
  - vulnerability: CVE-2024-12345
    package:
      name: openssl

易错点与排错

相关命令

读完自测

合上页面,先回答,再展开对照。

  1. CI 门禁应该依据什么判断扫描是否失败?
  2. 使用 --only-fixed 是否意味着镜像没有漏洞风险?
  3. 大量漏洞来自基础镜像时,优先怎么处理?
答案
  1. 依据 --fail-on 的退出码,而不是只看输出内容。只看报告容易漏掉失败。
  2. 不是。它只显示有修复版本的漏洞,未修复的漏洞仍然存在。
  3. 优先升级基础镜像。误报通过 ignore 配置管理,不要直接关闭整个扫描。