mcpField
S
scanning-container-images-with-grype

scanning-container-images-with-grype

github.com/mukul975セキュリティ35.2k109 回インストール8 週間前に更新
リポジトリ

scanning-container-images-with-grype について

Anchoreのオープンソース脆弱性スキャナーGrypeで、コンテナイメージ、ファイルシステム、SBOMの既知CVEを調べるスキルです。絞り込み、出力形式、データベース管理、CI/CDでの利用を扱います。

主な機能

  1. 01イメージ、ファイルシステム、SBOMのスキャン
  2. 02深刻度と修正状況による絞り込み
  3. 03JSON・CycloneDX形式での出力
  4. 04脆弱性の除外ルール設定
  5. 05CI/CDパイプラインでのスキャン

活用シーン

  1. 01デプロイ前のコンテナイメージ検査
  2. 02深刻度のしきい値によるCIビルド失敗
  3. 03Syftで生成したSBOMのスキャン

インストール

コマンドをコピーしてターミナルで実行します。

$npx skills add https://github.com/mukul975/anthropic-cybersecurity-skills --skill scanning-container-images-with-grype

インストール後、Claude Code で/scanning-container-images-with-grypeを入力して読み込まれたか確認します。

同梱ファイル

SKILL.md と一緒にインストールされる参考資料やスクリプト。

LICENSE
assets/
template.md
references/
api-reference.md
standards.md
workflows.md
scripts/
agent.py
process.py

詳細

Grype によるコンテナイメージのスキャン

概要

Grype は Anchore が提供するオープンソースの脆弱性スキャナーで、コンテナイメージ、ファイルシステム、SBOM を調査し、既知の CVE を検出します。Syft が生成した SBOM を活用して、パッケージを NVD、GitHub Advisories、OS 固有のフィードなど、複数の脆弱性データベースと照合します。

使用する場面

  • Grype を使用してコンテナイメージをスキャンするセキュリティ評価を実施する場合
  • 関連するセキュリティイベントに対するインシデント対応手順に従う場合
  • 定期的なセキュリティテストや監査を実施する場合
  • 実地テストを通じてセキュリティ制御を検証する場合

前提条件

  • 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 のインストール
# Install via script
curl -sSfL https://raw.githubusercontent.com/anchore/grype/main/install.sh | sh -s -- -b /usr/local/bin

# Verify installation
grype version

# Install via Homebrew (macOS/Linux)
brew install grype
コンテナイメージのスキャン
# Scan a Docker Hub image
grype nginx:latest

# Scan from Docker daemon
grype docker:myapp:1.0

# Scan a local archive
grype docker-archive:image.tar

# Scan an OCI directory
grype oci-dir:path/to/oci/

# Scan a Singularity image
grype sif:image.sif

# Scan a local directory / filesystem
grype dir:/path/to/project
出力形式
# Default table output
grype alpine:3.18

# JSON output for pipeline processing
grype alpine:3.18 -o json > results.json

# CycloneDX SBOM output
grype alpine:3.18 -o cyclonedx

# SARIF output for GitHub Security tab
grype alpine:3.18 -o sarif > grype.sarif

# Template-based custom output
grype alpine:3.18 -o template -t /path/to/template.tmpl
フィルタリングとしきい値
# Fail if vulnerabilities meet or exceed a severity
grype nginx:latest --fail-on critical

# Show only fixed vulnerabilities
grype nginx:latest --only-fixed

# Show only non-fixed vulnerabilities
grype nginx:latest --only-notfixed

# Filter by severity
grype nginx:latest --only-fixed -o json | jq '[.matches[] | select(.vulnerability.severity == "High")]'

# Explain a specific CVE
grype nginx:latest --explain --id CVE-2024-1234
SBOM の操作
# Generate SBOM with Syft then scan
syft nginx:latest -o spdx-json > nginx-sbom.json
grype sbom:nginx-sbom.json

# Scan CycloneDX SBOM
grype sbom:bom.json
設定ファイル(.grype.yaml)
# .grype.yaml
check-for-app-update: false
fail-on-severity: "high"
output: "json"
scope: "squashed"  # or "all-layers"
quiet: false

ignore:
  - vulnerability: CVE-2023-12345
    reason: "False positive - not exploitable in our context"
  - vulnerability: CVE-2023-67890
    fix-state: unknown

db:
  auto-update: true
  cache-dir: "/tmp/grype-db"
  max-allowed-built-age: 120h  # 5 days

match:
  java:
    using-cpes: true
  python:
    using-cpes: true
  javascript:
    using-cpes: false
CI/CD との統合
# GitHub Actions
- name: Scan image with Grype
  uses: anchore/scan-action@v4
  with:
    image: "myregistry/myapp:${{ github.sha }}"
    fail-build: true
    severity-cutoff: high
    output-format: sarif
  id: scan

- name: Upload SARIF
  uses: github/codeql-action/upload-sarif@v3
  with:
    sarif_file: ${{ steps.scan.outputs.sarif }}
# 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

データベース管理

# Check database status
grype db status

# Manually update vulnerability database
grype db update

# Delete cached database
grype db delete

# List supported database providers
grype db list

主な脆弱性情報源

情報源対象範囲
NVDあらゆるエコシステムの CVE
GitHub Advisoriesオープンソースパッケージの脆弱性
Alpine SecDBAlpine Linux パッケージ
Amazon Linux ALASAmazon Linux AMI
Debian Security TrackerDebian パッケージ
Red Hat OVALRHEL、CentOS
Ubuntu SecurityUbuntu パッケージ
Wolfi SecDBWolfi/Chainguard イメージ

ベストプラクティス

  1. イメージタグを固定する - latest ではなく、常に特定のダイジェストをスキャンします
  2. 深刻度に基づいて失敗させる - CI のゲートで --fail-on high または critical を設定します
  3. SBOM を使用する - 再現可能なスキャンのために Syft で SBOM を生成します
  4. 誤検知を抑制する - 理由を記録した .grype.yaml の無視ルールを使用します
  5. すべてのレイヤーをスキャンする - 中間レイヤーの脆弱性を検出するために --scope all-layers を使用します
  6. データベースの更新を自動化する - CI ランナーの脆弱性データベースを最新の状態に保ちます
  7. スキャン結果を比較する - 脆弱性の件数を継続的に追跡し、リグレッションを検出します

コメント