mcpField
P
performing-gcp-security-assessment-with-forseti

performing-gcp-security-assessment-with-forseti

github.com/mukul975安全35.2k39 次安装8 周前更新
代码仓库

关于 performing-gcp-security-assessment-with-forseti

面向 GCP 安全团队的评估流程技能,帮助检查组织和项目的 IAM、网络规则、存储权限及安全发现。内容结合 gcloud、ScoutSuite、Security Command Center 等工具;Forseti 已被标注为旧版工具。

主要功能

  1. 01审查组织及项目的 IAM 绑定
  2. 02检查防火墙规则和网络暴露
  3. 03检查存储桶公开访问
  4. 04使用 ScoutSuite 执行自动评估
  5. 05查询 Security Command Center 发现

适用场景

  1. 01定期评估 GCP 组织安全状况
  2. 02为新接入项目建立安全基线
  3. 03审核多个项目的 IAM 与存储权限
  4. 04持续监控 GCP 基础设施配置

安装

复制下面的命令,在终端中运行。

$npx skills add https://github.com/mukul975/anthropic-cybersecurity-skills --skill performing-gcp-security-assessment-with-forseti

安装后在 Claude Code 中输入/performing-gcp-security-assessment-with-forseti确认已加载。

包含的文件

除 SKILL.md 外,安装时一起下载的参考资料和脚本。

LICENSE
references/
api-reference.md
scripts/
agent.py

详细介绍

使用 Forseti 执行 GCP 安全评估

何时使用

  • 在对 GCP 组织和项目进行定期安全评估时
  • 在接入新的 GCP 项目并建立安全基线时
  • 当合规要求强制进行 CIS GCP Foundations Benchmark 评估时
  • 在跨多个 GCP 项目审计 IAM 绑定、防火墙规则和存储 ACL 时
  • 在为 GCP 基础设施构建持续安全监控时

请勿使用其替代 GCP Security Command Center Premium 进行实时威胁检测,也请勿用于应用层漏洞扫描(请使用 Web Security Scanner)或 GKE 专属安全防护(请使用 GKE Security Posture)。

前提条件

  • 拥有 Organization Admin 或 Security Admin IAM 角色的 GCP 组织
  • 已通过身份验证且具备足够权限的 gcloud CLI(roles/securitycenter.admin、roles/iam.securityReviewer)
  • 已在组织层级启用 Security Command Center (SCC)
  • 已安装 ScoutSuite 以进行多云对比(pip install scoutsuite)
  • Python 3.8+,用于使用 google-cloud-asset 和 google-cloud-securitycenter 库编写自定义审计脚本

工作流

步骤 1:启用 Security Command Center 和资产清单

启用 SCC 并设置 Cloud Asset Inventory,以实现全面的资源可见性。

# Enable Security Command Center API
gcloud services enable securitycenter.googleapis.com \
  --project=PROJECT_ID

# Enable Cloud Asset API
gcloud services enable cloudasset.googleapis.com \
  --project=PROJECT_ID

# List all assets in the organization
gcloud asset search-all-resources \
  --scope=organizations/ORG_ID \
  --asset-types="compute.googleapis.com/Instance,storage.googleapis.com/Bucket,iam.googleapis.com/ServiceAccount" \
  --format="table(name, assetType, location, project)"

# Export asset inventory to BigQuery for analysis
gcloud asset export \
  --organization=ORG_ID \
  --output-bigquery-force \
  --output-bigquery-dataset=projects/PROJECT_ID/datasets/asset_inventory \
  --output-bigquery-table=resources \
  --content-type=resource
步骤 2:审计 IAM 策略与绑定

审查整个组织的 IAM 策略,查找权限过宽的绑定、基本角色以及服务账号滥用情况。

# List all IAM policy bindings at org level
gcloud organizations get-iam-policy ORG_ID \
  --format=json > org-iam-policy.json

# Find all users with Owner or Editor roles across projects
gcloud asset search-all-iam-policies \
  --scope=organizations/ORG_ID \
  --query="policy:roles/owner OR policy:roles/editor" \
  --format="table(resource, policy.bindings.role, policy.bindings.members)"

# Identify service accounts with admin roles
gcloud asset search-all-iam-policies \
  --scope=organizations/ORG_ID \
  --query="policy.bindings.members:serviceAccount AND policy:roles/owner" \
  --format=json

# Check for allUsers or allAuthenticatedUsers bindings (public 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)"

# List service account keys older than 90 days
gcloud iam service-accounts keys list \
  --iam-account=SA_EMAIL \
  --managed-by=user \
  --format="table(name,validAfterTime,validBeforeTime)"
步骤 3:评估防火墙规则与网络配置

审计 VPC 防火墙规则,查找权限过宽的入站规则、缺失的日志记录以及网络暴露情况。

# List all firewall rules allowing ingress from 0.0.0.0/0
gcloud compute firewall-rules list \
  --filter="direction=INGRESS AND sourceRanges=0.0.0.0/0" \
  --format="table(name, network, allowed, sourceRanges, targetTags)"

# Find firewall rules allowing all protocols/ports
gcloud compute firewall-rules list \
  --filter="direction=INGRESS AND allowed[].IPProtocol=all" \
  --format="table(name, network, sourceRanges, targetTags)"

# Check for SSH (22) and RDP (3389) open to internet
gcloud compute firewall-rules list \
  --filter="direction=INGRESS AND sourceRanges=0.0.0.0/0 AND (allowed[].ports=22 OR allowed[].ports=3389)" \
  --format="table(name, network, allowed, sourceRanges)"

# Audit VPC flow log configuration
gcloud compute networks subnets list \
  --format="table(name, region, enableFlowLogs, logConfig.aggregationInterval)"
步骤 4:审计 Cloud Storage 存储桶权限

检查可公开访问的存储桶以及缺失的加密配置。

# List all buckets in a project
gsutil ls -p PROJECT_ID

# Check bucket IAM for public access
for bucket in $(gsutil ls -p PROJECT_ID); do
  echo "=== $bucket ==="
  gsutil iam get "$bucket" | grep -E "allUsers|allAuthenticatedUsers" && \
    echo "  WARNING: PUBLIC ACCESS DETECTED" || \
    echo "  OK: No public access"
done

# Check bucket encryption configuration
for bucket in $(gsutil ls -p PROJECT_ID); do
  echo "=== $bucket ==="
  gsutil kms encryption "$bucket" 2>/dev/null || echo "  Using Google-managed encryption"
done

# Check uniform bucket-level access enforcement
for bucket in $(gsutil ls -p PROJECT_ID); do
  gsutil uniformbucketlevelaccess get "$bucket"
done
步骤 5:运行 ScoutSuite 进行全面评估

执行 ScoutSuite,对 GCP 环境进行自动化多项检查的安全评估。

# Run ScoutSuite against GCP
python3 -m ScoutSuite gcp \
  --user-account \
  --all-projects \
  --report-dir ./scoutsuite-gcp-report

# Run with service account credentials
python3 -m ScoutSuite gcp \
  --service-account /path/to/service-account-key.json \
  --all-projects \
  --report-dir ./scoutsuite-gcp-report

# Open the HTML report
open ./scoutsuite-gcp-report/gcp-report.html
步骤 6:查询 Security Command Center 发现项

检索并分析 SCC 发现项,以识别漏洞、错误配置和威胁。

# List active SCC findings
gcloud scc findings list ORG_ID \
  --filter="state=\"ACTIVE\" AND severity=\"CRITICAL\"" \
  --format="table(finding.category, finding.severity, finding.resourceName, finding.eventTime)"

# List findings by category
gcloud scc findings list ORG_ID \
  --filter="state=\"ACTIVE\" AND category=\"PUBLIC_BUCKET_ACL\"" \
  --format=json

# Get finding statistics grouped by category
gcloud scc findings group ORG_ID \
  --group-by="category" \
  --filter="state=\"ACTIVE\""

# List compliance violations from SCC
gcloud scc findings list ORG_ID \
  --filter="state=\"ACTIVE\" AND sourceProperties.compliance_standard=\"CIS\"" \
  --format="table(finding.category, finding.severity, finding.resourceName)"

关键概念

术语定义
Security Command CenterGCP 原生的安全与风险管理平台,提供资产清单、漏洞检测和威胁监控
Forseti Security开源 GCP 安全工具包(现已弃用,由 SCC 取代),提供清单、扫描、强制执行和通知功能
Cloud Asset InventoryGCP 服务,提供云资源的完整清单,包括元数据、IAM 策略和组织策略配置
CIS GCP Foundations BenchmarkCenter for Internet Security 针对 Google Cloud Platform 配置的安全最佳实践指南
Uniform Bucket-Level AccessGCP 存储设置,禁用旧版 ACL 并强制仅通过 IAM 策略进行访问,以实现一致的访问控制
Organization PolicyGCP 基于约束的治理机制,限制整个组织层级中的资源配置

工具与系统

  • Security Command Center:GCP 原生 CSPM,提供资产清单、漏洞发现项和合规评分
  • ScoutSuite:多云安全审计工具,具备针对 IAM、计算、存储和网络的全面 GCP 检查
  • gcloud CLI:用于查询 GCP 资源配置和安全设置的主要命令行界面
  • Cloud Asset Inventory:用于跨 GCP 项目搜索和导出资源元数据及 IAM 策略的 API
  • Forseti Security:旧版开源 GCP 安全工具包,已被 SCC 取代,但在合规框架中仍被引用

常见场景

场景:评估新收购的 GCP 组织

背景:公司完成收购后,安全团队需要评估被收购公司 GCP 组织的安全状况,该组织拥有 30+ 个项目。

方法:

  1. 启用 Cloud Asset API,并将完整的资源清单导出到 BigQuery 进行分析
  2. 运行 gcloud asset search-all-iam-policies,找出所有 Owner/Editor 绑定以及公开访问授权
  3. 审计所有项目中的防火墙规则,检查是否存在来自 0.0.0.0/0 的过于宽松的入站流量
  4. 使用 gsutil iam get 检查所有存储桶是否存在公开访问
  5. 运行 ScoutSuite 进行全面自动化评估,并生成 HTML 报告
  6. 启用 SCC,并审查所有 CRITICAL 和 HIGH 级别的发现项
  7. 为整合团队生成按风险优先级排序的修复路线图

陷阱:GCP IAM 绑定会从组织继承到文件夹,再继承到项目。组织级别的宽松绑定会影响所有下游项目。务必审计层级结构中每一层的 IAM,而不仅仅是项目层。

输出格式

GCP Security Assessment Report
=================================
Organization: acme-acquired-org (ORG_ID: 123456789)
Projects Assessed: 34
Assessment Date: 2026-02-23
Standards: CIS GCP Foundations 2.0

IAM FINDINGS:
  Users with Owner role at org level:       3
  Service accounts with Editor role:        12
  Resources with allUsers binding:           5
  Service account keys > 90 days:           18

NETWORK FINDINGS:
  Firewall rules allowing 0.0.0.0/0:       14
  SSH open to internet:                      7
  RDP open to internet:                      2
  Subnets without VPC flow logs:            22

STORAGE FINDINGS:
  Publicly accessible buckets:               5
  Buckets without CMEK encryption:          28
  Buckets without uniform access:           15

CRITICAL FINDINGS: 12
HIGH FINDINGS: 34
MEDIUM FINDINGS: 78
LOW FINDINGS: 145

TOP REMEDIATION PRIORITIES:
  1. Remove allUsers bindings from 5 storage buckets (CRITICAL)
  2. Restrict 0.0.0.0/0 firewall rules to specific CIDRs (HIGH)
  3. Rotate 18 service account keys older than 90 days (HIGH)
  4. Enable VPC flow logs on 22 subnets (MEDIUM)

评论

支持 Markdown