auditing-gcp-iam-permissions について
GCP 組織やプロジェクトの IAM 構成を確認するセキュリティ監査スキルです。ポリシーの棚卸し、サービスアカウントの点検、権限分析、修正を GCP ツールで進めます。
主な機能
- 01組織全体の IAM バインディングの棚卸し
- 02サービスアカウントとキーの確認
- 03IAM Recommender による過剰権限の検出
- 04Policy Analyzer による実効アクセス分析
- 05ドメイン全体の委任と偽装リスクの特定
- 06監査・修正レポートの作成
活用シーン
- 01GCP セキュリティ監査で IAM アクセスを評価
- 02過剰な権限を持つサービスアカウントを特定
- 03広範な基本ロールを細分化されたロールに置換
インストール
コマンドをコピーしてターミナルで実行します。
npx skills add https:/ / github.com/ mukul975/ anthropic-cybersecurity-skills --skill auditing-gcp-iam-permissionsインストール後、Claude Code で/auditing-gcp-iam-permissionsを入力して読み込まれたか確認します。
同梱ファイル
SKILL.md と一緒にインストールされる参考資料やスクリプト。
LICENSEreferences/api-reference.mdscripts/agent.py詳細
GCP IAM 権限の監査
使用する場面
- GCP の組織またはプロジェクトの IAM 設定に対するセキュリティ評価を実施する場合
- 過剰な権限または未使用のアクセス権を持つサービスアカウントを特定する場合
- コンプライアンス要件により、アクセス制御とロール割り当てのレビューが必要な場合
- IAM の設定ミスによる潜在的なラテラルムーブメントを調査する場合
- 権限を絞り込んで、認証情報が侵害された場合の影響範囲を縮小する場合
使用しないでください。VPC ファイアウォールルールの監査には使用しないでください(ネットワークセキュリティツールを使用してください)。GKE RBAC の監査には使用しないでください(Kubernetes 専用の RBAC ツールを使用してください)。IAM アクションのリアルタイム脅威検出には使用しないでください(SCC Event Threat Detection を使用してください)。
前提条件
roles/iam.securityReviewerとroles/cloudAsset.viewerが付与された GCP 組織またはプロジェクト- 適切な権限で認証された gcloud CLI
- Cloud Asset API が有効であること(
gcloud services enable cloudasset.googleapis.com) - IAM Recommender API が有効であること(
gcloud services enable recommender.googleapis.com) - Policy Analyzer API が有効であること(
gcloud services enable policyanalyzer.googleapis.com)
ワークフロー
ステップ 1:組織全体の IAM バインディングを列挙する
組織、フォルダ、プロジェクトの各レベルにあるすべての IAM バインディングを一覧表示し、アクセス状況の全体像を把握します。
# Organization-level IAM bindings
gcloud organizations get-iam-policy ORG_ID \
--format=json > org-iam-policy.json
# Search all IAM policies across the organization
gcloud asset search-all-iam-policies \
--scope=organizations/ORG_ID \
--format="table(resource, policy.bindings.role, policy.bindings.members)" \
--limit=500
# Find all users and service accounts with Owner role
gcloud asset search-all-iam-policies \
--scope=organizations/ORG_ID \
--query="policy:roles/owner" \
--format="table(resource, policy.bindings.members)"
# Find all bindings using primitive roles (Owner, Editor, Viewer)
gcloud asset search-all-iam-policies \
--scope=organizations/ORG_ID \
--query="policy:roles/owner OR policy:roles/editor" \
--format=json | python3 -c "
import json, sys
data = json.load(sys.stdin)
for result in data:
resource = result.get('resource', '')
for binding in result.get('policy', {}).get('bindings', []):
role = binding.get('role', '')
if role in ['roles/owner', 'roles/editor']:
for member in binding.get('members', []):
print(f'{resource} | {role} | {member}')
"
ステップ 2:サービスアカウントとその鍵を監査する
過剰な権限やユーザー管理の鍵を持つサービスアカウント、および未使用のアカウントを特定します。
# List all service accounts in a project
gcloud iam service-accounts list \
--project=PROJECT_ID \
--format="table(email, displayName, disabled)"
# Check for user-managed keys (should be minimized)
for sa in $(gcloud iam service-accounts list --project=PROJECT_ID --format="value(email)"); do
keys=$(gcloud iam service-accounts keys list \
--iam-account="$sa" \
--managed-by=user \
--format="table(name.basename(),validAfterTime,validBeforeTime)")
if [ -n "$keys" ]; then
echo "=== $sa ==="
echo "$keys"
fi
done
# Find service accounts with admin roles across all projects
gcloud asset search-all-iam-policies \
--scope=organizations/ORG_ID \
--query="policy.bindings.members:serviceAccount AND (policy:roles/owner OR policy:roles/editor OR policy:admin)" \
--format="table(resource, policy.bindings.role, policy.bindings.members)"
# Check service account IAM policies (who can impersonate)
for sa in $(gcloud iam service-accounts list --project=PROJECT_ID --format="value(email)"); do
echo "=== $sa ==="
gcloud iam service-accounts get-iam-policy "$sa" --format=json 2>/dev/null
done
ステップ 3:IAM Recommender を使って過剰な権限を特定する
GCP の IAM Recommender を活用して、実際の使用状況を超えるアクセス権を付与するロールを特定します。
# List IAM role recommendations for a project
gcloud recommender recommendations list \
--project=PROJECT_ID \
--recommender=google.iam.policy.Recommender \
--location=global \
--format="table(name, description, priority, stateInfo.state)"
# Get detailed recommendation
gcloud recommender recommendations describe RECOMMENDATION_ID \
--project=PROJECT_ID \
--recommender=google.iam.policy.Recommender \
--location=global \
--format=json
# List insights about IAM usage
gcloud recommender insights list \
--project=PROJECT_ID \
--insight-type=google.iam.policy.Insight \
--location=global \
--format="table(name, description, severity, category)"
# Apply a recommendation (after review)
gcloud recommender recommendations mark-claimed RECOMMENDATION_ID \
--project=PROJECT_ID \
--recommender=google.iam.policy.Recommender \
--location=global \
--etag=ETAG
ステップ 4:Policy Analyzer で有効な権限を分析する
Policy Analyzer を使用して、特定のプリンシパルまたはリソースの有効なアクセス権を判定します。
# Check who has access to a specific resource
gcloud asset analyze-iam-policy \
--organization=ORG_ID \
--full-resource-name="//storage.googleapis.com/projects/_/buckets/sensitive-data-bucket" \
--format="table(identityList.identities, accessControlLists.accesses.role)"
# Check what resources a specific user can access
gcloud asset analyze-iam-policy \
--organization=ORG_ID \
--identity="user:[email protected]" \
--format="table(accessControlLists.resources.fullResourceName, accessControlLists.accesses.role)"
# Check who can perform a specific action
gcloud asset analyze-iam-policy \
--organization=ORG_ID \
--full-resource-name="//cloudresourcemanager.googleapis.com/projects/PROJECT_ID" \
--permissions="iam.serviceAccounts.actAs,iam.serviceAccountKeys.create" \
--format="table(identityList.identities, accessControlLists.accesses.permission)"
# Find all principals with allUsers or allAuthenticatedUsers access
gcloud asset search-all-iam-policies \
--scope=organizations/ORG_ID \
--query="policy:allUsers OR policy:allAuthenticatedUsers" \
--format="table(resource, policy.bindings.role, policy.bindings.members)"
ステップ 5:ドメイン全体の委任と権限借用のリスクを確認する
ドメイン全体の委任や権限借用の機能を持つサービスアカウントを特定します。
# Check for service accounts with domain-wide delegation
# (Requires Admin SDK access to list delegated accounts)
gcloud iam service-accounts list --project=PROJECT_ID --format=json | python3 -c "
import json, sys
accounts = json.load(sys.stdin)
for sa in accounts:
email = sa.get('email', '')
# Check if the SA has domain-wide delegation enabled
# This requires Admin SDK API access
print(f'SA: {email} - Check admin.google.com for delegation status')
"
# Find service accounts that other identities can impersonate
for sa in $(gcloud iam service-accounts list --project=PROJECT_ID --format="value(email)"); do
policy=$(gcloud iam service-accounts get-iam-policy "$sa" --format=json 2>/dev/null)
if echo "$policy" | python3 -c "
import json, sys
p = json.load(sys.stdin)
for b in p.get('bindings', []):
if b['role'] in ['roles/iam.serviceAccountTokenCreator', 'roles/iam.serviceAccountUser']:
print(f' {b[\"role\"]}: {b[\"members\"]}')
" 2>/dev/null; then
echo "=== Impersonation risk: $sa ==="
fi
done
ステップ 6:監査レポートを作成し、修正措置を適用する
検出結果をまとめ、推奨される権限の縮小を実施します。
# Remove primitive role and replace with predefined role
gcloud projects remove-iam-policy-binding PROJECT_ID \
--member="user:[email protected]" \
--role="roles/editor"
gcloud projects add-iam-policy-binding PROJECT_ID \
--member="user:[email protected]" \
--role="roles/compute.viewer"
gcloud projects add-iam-policy-binding PROJECT_ID \
--member="user:[email protected]" \
--role="roles/storage.objectViewer"
# Delete unused service account keys
gcloud iam service-accounts keys delete KEY_ID \
--iam-account=SA_EMAIL
# Disable unused service accounts
gcloud iam service-accounts disable SA_EMAIL --project=PROJECT_ID
主な概念
| 用語 | 定義 |
|---|---|
| プリミティブロール | すべてのサービスにわたる広範な権限を付与する旧式の GCP ロール(Owner、Editor、Viewer)。本番環境での使用は推奨されません |
| 事前定義ロール | GCP が管理する、特定のサービスとアクションを対象としたロール。プリミティブロールよりも細かくアクセスを制御できます |
| IAM Recommender | 実際の権限使用状況を分析し、最小権限を実現するためのロール縮小を提案する、GCP の機械学習ベースのサービス |
| Policy Analyzer | 組織階層全体の有効な IAM アクセスを分析し、「誰が何にアクセスできるか」というクエリに回答するツール |
| サービスアカウントキー | サービスアカウントの認証に使うユーザー管理の認証情報。エクスポート可能で自動的に有効期限が切れないため、セキュリティ上のリスクとなります |
| ドメイン全体の委任 | サービスアカウントに Google Workspace ドメイン内の任意のユーザーを偽装する機能を付与すること。重大な権限昇格のリスクとなります |
ツールとシステム
- gcloud CLI:GCP の IAM ポリシー、サービスアカウント、ロールバインディングを照会・管理する主要ツール
- IAM Recommender:実際の使用状況に基づいて過剰な権限の縮小を提案する、機械学習ベースの推奨エンジン
- Policy Analyzer:誰が何にアクセスできるかを把握するための、組織全体の有効なアクセス分析ツール
- Cloud Asset Inventory:IAM ポリシーとリソースのメタデータをプロジェクト横断で検索するツール
- ScoutSuite:ロールの割り当てとサービスアカウントに関する GCP IAM 固有のチェック機能を備えた、マルチクラウド監査ツール
よくあるシナリオ
シナリオ:GCP 組織全体での基本ロールの使用削減
背景:監査の結果、組織全体の IAM バインディングの 60%で基本ロール(Owner/Editor)が使用されていることが判明しました。セキュリティチームは、開発者のワークフローを妨げることなく、事前定義ロールへ移行する必要があります。
アプローチ:
gcloud asset search-all-iam-policiesを実行して、基本ロールのバインディングをすべて洗い出します- IAM Recommender を使用して、置き換えに適した事前定義ロールの機械学習ベースの提案を取得します
- 各バインディングについて、Policy Analyzer を使用して、プリンシパルが実際にアクセスしている対象を把握します
- 基本ロールから必要な特定の事前定義ロールへの対応表を作成します
- テスト期間中、基本ロールと並行して事前定義ロールを適用します
- Cloud Audit Logs を使用して、アクセス拒否エラーを監視します
- 2 週間にわたってアクセスの問題がないことを確認した後、基本ロールを削除します
注意点:基本ロールにはすべての GCP サービスにわたる権限が含まれているため、置き換えには複数の事前定義ロールが必要です。観察期間中にすべてのユースケースが記録されていない場合、Recommender が制限の厳しすぎるロールを提案することがあります。必要な権限の組み合わせに一致する事前定義ロールがない場合は、カスタムロールで補うことができます。
出力形式
GCP IAM Permissions Audit Report
===================================
Organization: acme-org (ORG_ID: 123456789)
Projects Audited: 25
Audit Date: 2026-02-23
IAM BINDING SUMMARY:
Total bindings: 342
Using primitive roles: 205 (60%)
Using predefined roles: 112 (33%)
Using custom roles: 25 (7%)
CRITICAL FINDINGS:
[IAM-001] Service Account with Owner Role
SA: [email protected]
Role: roles/owner on project prod-project
User-Managed Keys: 3 (oldest: 14 months)
Remediation: Replace with specific predefined roles, delete old keys
[IAM-002] allAuthenticatedUsers Binding
Resource: gs://public-data-bucket
Role: roles/storage.objectViewer
Risk: Any Google account holder can read bucket contents
Remediation: Restrict to specific user groups or service accounts
SERVICE ACCOUNT HEALTH:
Total service accounts: 67
With user-managed keys: 23
Keys older than 90 days: 18
Unused accounts (90+ days): 12
With domain-wide delegation: 2
RECOMMENDER SUGGESTIONS:
Total recommendations: 45
Priority HIGH: 12
Estimated permissions reduced: 2,847 individual permissions