Classmethod Gcp Scc Iac Validation Github Actions
Security Command Center の IaC 検証を GitHub Actions で実行してみた
- URL: https://dev.classmethod.jp/articles/gcp-scc-iac-validation-github-actions/
- 日付: 2026-06-09
- Tier: Tier 3
- 要旨: Google Cloud Security Command Center(SCC)の IaC 検証機能を GitHub Actions に組み込む手順を解説。PR ごとに Terraform plan を自動検証し、セキュリティポスチャー違反があれば job を失敗させて PR をブロック。Workload Identity 連携で鍵レス認証を実現。
詳細
前提条件
- SCC が Premium または Enterprise で組織レベル有効化済み(プロジェクトレベルでは使用不可)
- セキュリティポスチャー(IaC 違反ルールの束)を組織で作成・対象プロジェクトにデプロイ済み
- 有効化 API:
securityposture.googleapis.com,securitycentermanagement.googleapis.com
CI で使用する GitHub Action
google-github-actions/analyze-code-security-scc: Terraform plan の JSON を受け取り SCC IaC 検証レポートを生成
IaC 検証 SA(サービスアカウント)の設定
- 必要なロール:
roles/securityposture.reportCreator(実権限:securityposture.reports.create/get/list,operations.get) - 付与先は組織レベルのみ(プロジェクトレベルで付けると
Role ... is not supported for this resourceエラー) - Workload Identity 連携(WIF)で GitHub OIDC を信頼 → サービスアカウントキー JSON 不要
実装上のハマりポイント
bootstrap/(SA・WIF 定義)とterraform/(検証対象の main.tf)のステートファイルを分離すること。混ぜると bootstrap リソースまで検証対象に含まれる- 組織 IAM の
setIamPolicy権限(Organization Administrator 相当)がないとgoogle_organization_iam_memberの apply が失敗
ワークフロー構成
- PR 時: Terraform plan → SCC 検証 → 違反あれば job 失敗(PR ブロック)
- 検証結果の SARIF を artifact として保存しダウンロード・確認可能