implementing-aqua-security-for-container-scanning について
Aqua Security の Trivy を使ったコンテナなどのセキュリティスキャン実践ガイドです。セキュリティや CI/CD を担うチーム向けに、脆弱性・設定チェック、Kubernetes スキャン、ポリシー適用、SBOM 管理を扱います。
主な機能
- 01コンテナイメージの脆弱性スキャン
- 02ファイルシステムとリポジトリのスキャン
- 03Kubernetes ワークロードの継続スキャン
- 04IaC 設定チェック
- 05CI/CD 統合とポリシー適用
- 06SBOM の生成とスキャン
活用シーン
- 01CI パイプラインで重大な脆弱性を含むイメージを拒否
- 02Kubernetes ワークロードの脆弱性と設定を確認
- 03Terraform ファイルと Kubernetes マニフェストをスキャン
- 04イメージの SBOM を生成して再スキャン
インストール
コマンドをコピーしてターミナルで実行します。
npx skills add https:/ / github.com/ mukul975/ anthropic-cybersecurity-skills --skill implementing-aqua-security-for-container-scanningインストール後、Claude Code で/implementing-aqua-security-for-container-scanningを入力して読み込まれたか確認します。
同梱ファイル
SKILL.md と一緒にインストールされる参考資料やスクリプト。
LICENSEassets/template.mdreferences/api-reference.mdstandards.mdworkflows.mdscripts/agent.pyprocess.py詳細
コンテナスキャン向け Aqua Security の実装
概要
Aqua Security は、世界で最も人気のあるオープンソースの汎用セキュリティスキャナーである Trivy を提供しています。Trivy は、コンテナ、Kubernetes、コードリポジトリ、クラウド環境の脆弱性、設定ミス、シークレット、SBOM データ、ライセンスの問題を検出するように設計されています。Trivy は、OS パッケージ(Alpine、Debian、Ubuntu、RHEL など)と、言語固有の依存関係(npm、pip、Maven、Go モジュール、Cargo など)をスキャンし、NVD、ベンダーのアドバイザリ、GitHub Security Advisories から取得した脆弱性データベースを利用します。エンタープライズ向けの Aqua Platform は、集中型ポリシー管理、ランタイム保護、コンプライアンスレポート機能を追加して Trivy を拡張します。
使用する場面
- 環境でコンテナスキャン機能向けの Aqua Security の実装をデプロイまたは設定するとき
- コンプライアンス要件に沿ったセキュリティ制御を確立するとき
- この分野のセキュリティアーキテクチャを構築または改善するとき
- この実装が必要なセキュリティ評価を実施するとき
前提条件
- ローカルでイメージをスキャンするための Docker
- CI/CD プラットフォーム(GitHub Actions、GitLab CI、Jenkins など)
- コンテナレジストリへのアクセス(Docker Hub、ECR、GCR、ACR、Harbor)
- Trivy CLI(
trivy)または Kubernetes 用 Trivy Operator - エンタープライズ機能を利用するための Aqua Platform ライセンス(任意)
主なスキャン機能
イメージの脆弱性スキャン
Trivy はコンテナイメージをレイヤーごとにスキャンし、OS パッケージとアプリケーションの依存関係に含まれる CVE を特定します。ローカルイメージ、リモートレジストリのイメージ、tar アーカイブのスキャンに対応しています。
# Scan a remote image
trivy image python:3.11-slim
# Scan with severity filter
trivy image --severity HIGH,CRITICAL nginx:latest
# Scan and fail CI if critical CVEs found
trivy image --exit-code 1 --severity CRITICAL myapp:latest
# Generate SBOM in CycloneDX format
trivy image --format cyclonedx --output sbom.json myapp:latest
ファイルシステムとリポジトリのスキャン
# Scan project directory for vulnerabilities in dependencies
trivy fs --scanners vuln,secret,misconfig .
# Scan a specific lockfile
trivy fs --scanners vuln package-lock.json
# Scan git repository
trivy repo https://github.com/org/project
Trivy Operator による Kubernetes のスキャン
Trivy Operator は Kubernetes クラスター内で稼働し、ワークロードを継続的にスキャンします。
# Install Trivy Operator via Helm
helm repo add aqua https://aquasecurity.github.io/helm-charts/
helm repo update
helm install trivy-operator aqua/trivy-operator \
--namespace trivy-system \
--create-namespace \
--set trivy.severity="HIGH,CRITICAL" \
--set operator.scanJobTimeout="5m"
この Operator は、各ワークロードについて VulnerabilityReport と ConfigAuditReport のカスタムリソースを作成します。
IaC の設定ミスのスキャン
# Scan Terraform files
trivy config --severity HIGH,CRITICAL ./terraform/
# Scan Dockerfile for misconfigurations
trivy config Dockerfile
# Scan Kubernetes manifests
trivy config ./k8s-manifests/
CI/CD との統合
GitHub Actions
name: Container Security Scan
on:
push:
branches: [main]
pull_request:
jobs:
scan:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Build Docker image
run: docker build -t myapp:${{ github.sha }} .
- name: Run Trivy vulnerability scanner
uses: aquasecurity/trivy-action@master
with:
image-ref: 'myapp:${{ github.sha }}'
format: 'sarif'
output: 'trivy-results.sarif'
severity: 'CRITICAL,HIGH'
exit-code: '1'
- name: Upload Trivy scan results to GitHub Security tab
uses: github/codeql-action/upload-sarif@v3
if: always()
with:
sarif_file: 'trivy-results.sarif'
GitLab CI
container_scanning:
stage: security
image:
name: aquasec/trivy:latest
entrypoint: [""]
variables:
FULL_IMAGE_NAME: $CI_REGISTRY_IMAGE:$CI_COMMIT_SHORT_SHA
script:
- trivy image --exit-code 0 --format template --template "@/contrib/gitlab.tpl"
--output gl-container-scanning-report.json $FULL_IMAGE_NAME
- trivy image --exit-code 1 --severity CRITICAL $FULL_IMAGE_NAME
artifacts:
reports:
container_scanning: gl-container-scanning-report.json
Jenkins パイプライン
pipeline {
agent any
stages {
stage('Build') {
steps {
sh 'docker build -t myapp:${BUILD_NUMBER} .'
}
}
stage('Security Scan') {
steps {
sh '''
trivy image --exit-code 1 \
--severity HIGH,CRITICAL \
--format json \
--output trivy-report.json \
myapp:${BUILD_NUMBER}
'''
}
post {
always {
archiveArtifacts artifacts: 'trivy-report.json'
}
}
}
}
}
ポリシー設定
OPA/Rego による Trivy ポリシー
カスタムポリシーを適用するには、.trivy/policy.rego を作成します。
package trivy
deny[msg] {
input.Results[_].Vulnerabilities[_].Severity == "CRITICAL"
msg := "Critical vulnerabilities found in image"
}
deny[msg] {
input.Results[_].Vulnerabilities[vuln]
vuln.FixedVersion != ""
vuln.Severity == "HIGH"
msg := sprintf("Fixable HIGH vulnerability: %s", [vuln.VulnerabilityID])
}
無視ファイルの設定
許容するリスクを指定するには、.trivyignore を作成します。
# Accepted risk: vulnerability in test dependency only
CVE-2023-12345
# Accepted until expiry date
CVE-2024-67890 exp:2025-06-01
SBOM の生成と管理
# Generate CycloneDX SBOM
trivy image --format cyclonedx --output sbom-cyclonedx.json myapp:latest
# Generate SPDX SBOM
trivy image --format spdx-json --output sbom-spdx.json myapp:latest
# Scan an existing SBOM for new vulnerabilities
trivy sbom sbom-cyclonedx.json
モニタリングとレポート
| 指標 | 説明 | 目標 |
|---|---|---|
| 1 日あたりのスキャン済みイメージ数 | スキャンパイプラインを通過するイメージの合計数 | すべての本番イメージ |
| 重大な CVE の数 | すべてのイメージにおける未解決の重大な脆弱性 | 本番環境で 0 件 |
| パッチ適用までの平均時間 | CVE 公開からパッチ適用済みイメージまでの平均日数 | 7 日未満 |
| SBOM カバレッジ | SBOM が生成された本番イメージの割合 | 100% |
| スキャン所要時間 | イメージスキャン 1 回あたりの平均時間 | 2 分未満 |