scanning-container-images-with-grype
使用 Anchore Grype 扫描容器镜像的已知漏洞(Vulnerability),支持基于 SBOM 的匹配和可配置的严重性阈值。
Best use case
scanning-container-images-with-grype is best used when you need a repeatable AI agent workflow instead of a one-off prompt.
使用 Anchore Grype 扫描容器镜像的已知漏洞(Vulnerability),支持基于 SBOM 的匹配和可配置的严重性阈值。
Teams using scanning-container-images-with-grype should expect a more consistent output, faster repeated execution, less prompt rewriting.
When to use this skill
- You want a reusable workflow that can be run more than once with consistent structure.
When not to use this skill
- You only need a quick one-off answer and do not need a reusable workflow.
- You cannot install or maintain the underlying files, dependencies, or repository context.
Installation
Claude Code / Cursor / Codex
Manual Installation
- Download SKILL.md from GitHub
- Place it in
.claude/skills/scanning-container-images-with-grype/SKILL.mdinside your project - Restart your AI agent — it will auto-discover the skill
How scanning-container-images-with-grype Compares
| Feature / Agent | scanning-container-images-with-grype | Standard Approach |
|---|---|---|
| Platform Support | Not specified | Limited / Varies |
| Context Awareness | High | Baseline |
| Installation Complexity | Unknown | N/A |
Frequently Asked Questions
What does this skill do?
使用 Anchore Grype 扫描容器镜像的已知漏洞(Vulnerability),支持基于 SBOM 的匹配和可配置的严重性阈值。
Where can I find the source code?
You can find the source code on GitHub using the link provided at the top of the page.
SKILL.md Source
# 使用 Grype 扫描容器镜像
## 概述
Grype 是 Anchore 开源的漏洞扫描器,用于检查容器镜像、文件系统和 SBOM 中的已知 CVE。它利用 Syft 生成的 SBOM,将软件包与多个漏洞数据库进行匹配,包括 NVD、GitHub Advisory 和特定操作系统的漏洞数据源。
## 前置条件
- 已安装 Docker 或 Podman
- 已安装 Grype CLI(`curl -sSfL https://raw.githubusercontent.com/anchore/grype/main/install.sh | sh -s -- -b /usr/local/bin`)
- Syft CLI(可选,用于生成 SBOM)
- 网络访问权限(用于拉取漏洞数据库)
## 核心命令
### 安装 Grype
```bash
# 通过脚本安装
curl -sSfL https://raw.githubusercontent.com/anchore/grype/main/install.sh | sh -s -- -b /usr/local/bin
# 验证安装
grype version
# 通过 Homebrew 安装(macOS/Linux)
brew install grype
```
### 扫描容器镜像
```bash
# 扫描 Docker Hub 镜像
grype nginx:latest
# 从 Docker daemon 扫描
grype docker:myapp:1.0
# 扫描本地存档
grype docker-archive:image.tar
# 扫描 OCI 目录
grype oci-dir:path/to/oci/
# 扫描 Singularity 镜像
grype sif:image.sif
# 扫描本地目录/文件系统
grype dir:/path/to/project
```
### 输出格式
```bash
# 默认表格输出
grype alpine:3.18
# JSON 格式输出(用于流水线处理)
grype alpine:3.18 -o json > results.json
# CycloneDX SBOM 输出
grype alpine:3.18 -o cyclonedx
# SARIF 格式输出(用于 GitHub Security 标签页)
grype alpine:3.18 -o sarif > grype.sarif
# 基于模板的自定义输出
grype alpine:3.18 -o template -t /path/to/template.tmpl
```
### 过滤与阈值
```bash
# 发现达到或超过指定严重性时失败
grype nginx:latest --fail-on critical
# 仅显示有修复版本的漏洞
grype nginx:latest --only-fixed
# 仅显示无修复版本的漏洞
grype nginx:latest --only-notfixed
# 按严重性过滤
grype nginx:latest --only-fixed -o json | jq '[.matches[] | select(.vulnerability.severity == "High")]'
# 解释特定 CVE
grype nginx:latest --explain --id CVE-2024-1234
```
### 使用 SBOM
```bash
# 用 Syft 生成 SBOM 后扫描
syft nginx:latest -o spdx-json > nginx-sbom.json
grype sbom:nginx-sbom.json
# 扫描 CycloneDX SBOM
grype sbom:bom.json
```
### 配置文件(.grype.yaml)
```yaml
# .grype.yaml
check-for-app-update: false
fail-on-severity: "high"
output: "json"
scope: "squashed" # 或 "all-layers"
quiet: false
ignore:
- vulnerability: CVE-2023-12345
reason: "误报 - 在我们的环境中不可利用"
- vulnerability: CVE-2023-67890
fix-state: unknown
db:
auto-update: true
cache-dir: "/tmp/grype-db"
max-allowed-built-age: 120h # 5 天
match:
java:
using-cpes: true
python:
using-cpes: true
javascript:
using-cpes: false
```
### CI/CD 集成
```yaml
# GitHub Actions
- name: 使用 Grype 扫描镜像
uses: anchore/scan-action@v4
with:
image: "myregistry/myapp:${{ github.sha }}"
fail-build: true
severity-cutoff: high
output-format: sarif
id: scan
- name: 上传 SARIF
uses: github/codeql-action/upload-sarif@v3
with:
sarif_file: ${{ steps.scan.outputs.sarif }}
```
```yaml
# GitLab CI
container_scan:
stage: test
image: anchore/grype:latest
script:
- grype ${CI_REGISTRY_IMAGE}:${CI_COMMIT_SHA} --fail-on high -o json > grype-report.json
artifacts:
reports:
container_scanning: grype-report.json
```
## 数据库管理
```bash
# 检查数据库状态
grype db status
# 手动更新漏洞数据库
grype db update
# 删除缓存的数据库
grype db delete
# 列出支持的数据库提供者
grype db list
```
## 关键漏洞数据源
| 数据源 | 覆盖范围 |
|--------|----------|
| NVD | 所有生态系统的 CVE |
| GitHub Advisories | 开源软件包漏洞 |
| Alpine SecDB | Alpine Linux 软件包 |
| Amazon Linux ALAS | Amazon Linux AMI |
| Debian Security Tracker | Debian 软件包 |
| Red Hat OVAL | RHEL、CentOS |
| Ubuntu Security | Ubuntu 软件包 |
| Wolfi SecDB | Wolfi/Chainguard 镜像 |
## 最佳实践
1. **固定镜像标签** - 始终扫描特定摘要,而非 `latest`
2. **设置严重性失败阈值** - 在 CI 门控中设置 `--fail-on high` 或 `critical`
3. **使用 SBOM** - 用 Syft 生成 SBOM 以实现可复现的扫描
4. **抑制误报** - 使用带记录原因的 `.grype.yaml` 忽略规则
5. **扫描所有层** - 使用 `--scope all-layers` 捕获中间层中的漏洞
6. **自动化数据库更新** - 在 CI runner 中保持漏洞数据库为最新
7. **比较扫描结果** - 随时间追踪漏洞数量变化以检测回归Related Skills
securing-container-registry-with-harbor
Harbor 是一个开源容器镜像仓库,提供安全功能包括漏洞扫描(集成 Trivy)、镜像签名(Notary/Cosign)、RBAC、内容信任策略(Content Trust)、复制和审计日志。配置这些功能以强制执行镜像来源验证、防止有漏洞镜像部署并维护仓库访问控制。
securing-container-registry-images
通过使用 Trivy 和 Grype 实施漏洞扫描、使用 Cosign 和 Sigstore 强制执行镜像签名、配置镜像仓库访问控制,以及构建阻止部署未扫描或未签名镜像的 CI/CD 流水线,来保护容器仓库(Container Registry)中的镜像安全。
scanning-network-with-nmap-advanced
使用 Nmap 的脚本引擎、时序控制、规避技术和输出解析,对授权目标网络执行高级网络侦察, 发现主机、枚举服务、检测漏洞并识别操作系统。
scanning-kubernetes-manifests-with-kubesec
使用 Kubesec 对 Kubernetes 资源清单执行安全风险分析,识别错误配置、权限提升风险以及与安全最佳实践的偏差。
scanning-infrastructure-with-nessus
Tenable Nessus 是业界领先的漏洞扫描器,用于识别网络基础设施(包括服务器、工作站、网络设备和操作系统)中的安全弱点。
scanning-docker-images-with-trivy
Trivy 是 Aqua Security 开源的综合性漏洞扫描器,用于检测容器镜像中操作系统软件包、语言特定依赖项的漏洞、错误配置、密钥和许可证违规,并集成到 CI/CD 流水线,支持 SARIF、CycloneDX 和 SPDX 等多种输出格式。
scanning-containers-with-trivy-in-cicd
本技能涵盖将 Aqua Security 的 Trivy 扫描器集成到 CI/CD 流水线中,用于全面的容器镜像漏洞检测。包括扫描 Docker 镜像中的操作系统包和应用依赖 CVE、检测 Dockerfile 中的错误配置、扫描文件系统和 Git 仓库,以及建立基于严重性的质量门禁以阻止有漏洞的镜像部署。
performing-web-application-scanning-with-nikto
Nikto 是一款开源 Web 服务器和 Web 应用程序扫描器,可针对超过 7,000 个潜在危险文件/程序进行测试,检查超过 1,250 个服务器的过期版本,并识别超过 270 个服务器的版本特定问题。
performing-vulnerability-scanning-with-nessus
使用 Tenable Nessus 执行认证和未认证漏洞扫描,识别网络基础设施、服务器和应用程序中的已知漏洞、 错误配置、默认凭据和缺失补丁。扫描器将发现与 CVE 数据库和 CVSS 评分关联,生成优先级修复指导。 适用于漏洞扫描、Nessus 评估、补丁合规检查或自动化漏洞检测等请求场景。
performing-sca-dependency-scanning-with-snyk
本技能涵盖使用 Snyk 实施软件成分分析(SCA, Software Composition Analysis),在 CI/CD 流水线中检测存在漏洞的开源依赖项。内容包括扫描包清单和锁文件、自动修复拉取请求生成、许可证合规检查、已部署应用程序的持续监控,以及与 GitHub、GitLab 和 Jenkins 流水线的集成。
performing-ot-vulnerability-scanning-safely
使用被动监控、原生协议查询和经过精心控制的Tenable OT Security主动扫描,在OT/ICS环境中安全执行漏洞扫描,在不破坏工业过程或导致旧版控制器崩溃的情况下识别漏洞。
performing-container-security-scanning-with-trivy
使用 Aqua Security Trivy 扫描容器镜像、文件系统和 Kubernetes 清单,检测漏洞(Vulnerability)、错误配置、暴露的密钥和许可证合规问题,并生成 SBOM(Software Bill of Materials,软件物料清单)及集成到 CI/CD 流水线。