| name | implementing-cloud-security-posture-management |
| description | 实施云安全态势管理(CSPM),使用 Prowler、ScoutSuite、AWS Security Hub、Azure Defender 和 GCP Security Command Center 对多云环境中的错误配置、合规违规和安全风险进行持续监控。
|
| domain | cybersecurity |
| subdomain | cloud-security |
| tags | ["cloud-security","cspm","multi-cloud","compliance","prowler","scoutsuite"] |
| version | 1.0 |
| author | mahipal |
| license | Apache-2.0 |
实施云安全态势管理
适用场景
- 在 AWS、Azure 和 GCP 环境中建立持续安全监控时
- 合规要求需要针对 CIS、SOC 2 或 PCI DSS 进行自动化态势评估时
- 安全团队需要跨多个账户和订阅了解云错误配置时
- 构建能检测和修复偏离安全基线的安全运营工作流时
- 将工作负载迁移到云端并需要强制执行安全护栏时
不适用于:运行时工作负载保护(使用 Falco 或 Aqua 等 CWPP 工具)、应用安全测试(使用 DAST/SAST 工具),或网络入侵检测(使用 GuardDuty 或 Network Watcher 等云原生 IDS)。
前置条件
- 跨所有目标环境具有只读安全审计权限的多云凭据
- 已安装 Prowler v3+(
pip install prowler)
- 已安装 ScoutSuite(
pip install scoutsuite)
- 在各自环境中启用 AWS Config、Azure Policy 和 GCP Organization Policy
- 用于发现结果聚合的集中日志目标(S3 存储桶、Log Analytics 工作区或 Cloud Storage)
- 已配置严重发现结果告警的通知渠道(Slack、PagerDuty、邮件)
工作流程
步骤 1:部署云原生 CSPM 服务
在每个云提供商中启用内置 CSPM 功能,用于基线态势评估。
aws securityhub enable-security-hub --enable-default-standards
aws securityhub batch-enable-standards --standards-subscription-requests \
'[{"StandardsArn":"arn:aws:securityhub:::standards/cis-aws-foundations-benchmark/v/1.4.0"}]'
az security pricing create --name CloudPosture --tier standard
az security auto-provisioning-setting update --name default --auto-provision on
gcloud services enable securitycenter.googleapis.com
gcloud scc settings update --organization=ORG_ID \
--enable-asset-discovery
步骤 2:运行 Prowler 进行多云评估
执行 Prowler,对所有三个云提供商进行全面安全检查。
prowler aws \
--profile production \
-M json-ocsf csv html \
-o ./prowler-results/aws/ \
--compliance cis_1.4_aws cis_1.5_aws
prowler azure \
--subscription-ids SUB_ID_1 SUB_ID_2 \
-M json-ocsf csv html \
-o ./prowler-results/azure/ \
--compliance cis_2.0_azure
prowler gcp \
--project-ids project-1 project-2 \
-M json-ocsf csv html \
-o ./prowler-results/gcp/ \
--compliance cis_2.0_gcp
prowler aws --list-compliance
步骤 3:运行 ScoutSuite 进行跨云比较
使用 ScoutSuite 进行统一的多云安全评估,并生成可视化报告。
python3 -m ScoutSuite aws --profile production \
--report-dir ./scoutsuite/aws/
python3 -m ScoutSuite azure --cli \
--all-subscriptions \
--report-dir ./scoutsuite/azure/
python3 -m ScoutSuite gcp --user-account \
--all-projects \
--report-dir ./scoutsuite/gcp/
步骤 4:构建自动化合规监控管道
创建每日运行 CSPM 检查并将发现结果路由到相应渠道的定期管道。
cat > buildspec.yml << 'EOF'
version: 0.2
phases:
install:
commands:
- pip install prowler
build:
commands:
- prowler aws -M json-ocsf -o s3://security-findings-bucket/prowler/$(date +%Y%m%d)/
- prowler aws --compliance cis_1.5_aws -M csv -o s3://security-findings-bucket/prowler/compliance/
post_build:
commands:
- |
CRITICAL=$(cat output/*.json | grep -c '"CRITICAL"')
if [ "$CRITICAL" -gt 0 ]; then
aws sns publish --topic-arn arn:aws:sns:us-east-1:ACCOUNT:security-alerts \
--subject "Prowler: 发现 $CRITICAL 个严重问题" \
--message "请查看 s3://security-findings-bucket/prowler/$(date +%Y%m%d)/"
fi
EOF
aws events put-rule \
--name daily-prowler-scan \
--schedule-expression "cron(0 6 * * ? *)" \
--state ENABLED
步骤 5:配置发现结果聚合和去重
将来自多个 CSPM 工具和云提供商的发现结果聚合到统一视图。
import json
import hashlib
from datetime import datetime
def normalize_finding(finding, source):
"""将来自不同 CSPM 工具的发现结果规范化为通用格式。"""
normalized = {
'id': hashlib.sha256(f"{finding.get('ResourceId','')}{finding.get('CheckId','')}".encode()).hexdigest()[:16],
'source': source,
'cloud': finding.get('Provider', 'unknown'),
'account': finding.get('AccountId', finding.get('SubscriptionId', '')),
'region': finding.get('Region', ''),
'resource_type': finding.get('ResourceType', ''),
'resource_id': finding.get('ResourceId', ''),
'severity': finding.get('Severity', 'INFO').upper(),
'status': finding.get('Status', 'FAIL'),
'title': finding.get('CheckTitle', finding.get('Title', '')),
'description': finding.get('StatusExtended', ''),
'compliance': finding.get(, {}),
: finding.get(, {}).get(, {}).get(, ),
: datetime.utcnow().isoformat()
}
normalized
():
findings = {}
file_path, source [(prowler_file, ), (scoutsuite_file, )]:
(file_path) f:
line f:
raw = json.loads(line)
normalized = normalize_finding(raw, source)
normalized[] == :
findings[normalized[]] = normalized
(findings.values(), key= x: {:,:,:,:}.get(x[],))
步骤 6:实施配置漂移检测和自动修复
为违反安全基线的配置漂移设置自动响应。
aws configservice put-remediation-configurations --remediation-configurations '[{
"ConfigRuleName": "s3-bucket-public-read-prohibited",
"TargetType": "SSM_DOCUMENT",
"TargetId": "AWS-DisableS3BucketPublicReadWrite",
"Parameters": {
"S3BucketName": {"ResourceValue": {"Value": "RESOURCE_ID"}}
},
"Automatic": true,
"MaximumAutomaticAttempts": 3,
"RetryAttemptSeconds": 60
}]'
az policy assignment create \
--name "enforce-storage-encryption" \
--policy "/providers/Microsoft.Authorization/policyDefinitions/404c3081-a854-4457-ae30-26a93ef643f9" \
--scope "/subscriptions/SUB_ID" \
--enforcement-mode Default
gcloud resource-manager org-policies set-policy policy.yaml --organization=ORG_ID
核心概念
| 术语 | 定义 |
|---|
| CSPM(云安全态势管理) | 持续监控云基础设施错误配置和合规违规的实践 |
| 配置漂移(Configuration Drift) | 云资源配置随时间偏离已批准安全基线的意外变更 |
| 安全基线(Security Baseline) | 记录了所有云资源必须满足的最低安全配置要求的文档 |
| 合规框架(Compliance Framework) | 用于评估云配置的结构化安全控制和要求集(CIS、SOC 2、PCI DSS、NIST) |
| 发现结果严重程度(Finding Severity) | 基于可利用性和潜在影响的错误配置风险分类(严重、高、中、低、信息) |
| 自动修复(Auto-Remediation) | 无需人工干预即可将不合规资源恢复到所需配置的自动纠正操作 |
工具与系统
- Prowler:开源多云安全评估工具,包含 300 余项对齐 CIS、PCI DSS、HIPAA 和 NIST 的检查
- ScoutSuite:多云安全审计工具,通过 API 收集的配置数据生成风险评分 HTML 报告
- AWS Security Hub:具有聚合发现结果和合规标准评估的 AWS 原生 CSPM
- Microsoft Defender for Cloud:具有安全评分、合规性和工作负载保护的 Azure 原生 CSPM
- GCP Security Command Center:具有资产清单、漏洞扫描和合规监控的 GCP 原生安全平台
常见场景
场景:为多云企业建立 CSPM
场景背景:一家企业在 AWS(主要)、Azure(身份和 Microsoft 服务)和 GCP(数据分析)上运行生产工作负载。安全团队需要统一的态势可见性。
方法:
- 在每个提供商中启用云原生 CSPM:Security Hub、Defender for Cloud、SCC
- 通过 CI/CD 管道在每个环境中将 Prowler 扫描部署为每日定期任务
- 使用聚合脚本将发现结果规范化并聚合到中央数据湖
- 在 Grafana 或 Kibana 中构建按云、账户和严重程度显示态势评分的仪表盘
- 为已知安全修复(公开访问阻断、加密启用)配置自动修复
- 将严重(CRITICAL)发现结果路由到 PagerDuty 进行即时响应,将高(HIGH)发现结果路由到 Jira 工单
- 为管理层生成显示趋势数据的每周合规报告
常见陷阱:使用权限过宽运行 CSPM 工具会创建高价值目标。使用具有只读权限的专用服务账户并定期轮换凭据。不同 CSPM 工具可能以不同方式报告同一错误配置,因此去重逻辑必须考虑不同工具之间不同的资源 ID 格式和发现结果标题。
输出格式
云安全态势管理仪表盘
==============================================
组织: Acme Corp
评估日期: 2026-02-23
环境: AWS(12 个账户)、Azure(8 个订阅)、GCP(5 个项目)
态势评分:
AWS: 82/100(比上周+3)
Azure: 76/100(比上周-1)
GCP: 79/100(比上周+5)
总体: 79/100
按严重程度划分的发现结果:
严重: 18(AWS: 7, Azure: 8, GCP: 3)
高: 67(AWS: 28, Azure: 24, GCP: 15)
中: 234(AWS: 98, Azure: 87, GCP: 49)
低: 412(AWS: 178, Azure: 134, GCP: 100)
失败类别 TOP 排行:
1. IAM 权限过宽策略 (43 个发现结果)
2. 静态加密未启用 (38 个发现结果)
3. 公开网络暴露 (29 个发现结果)
4. 日志和监控缺口 (24 个发现结果)
5. 未使用的凭据和密钥 (19 个发现结果)
自动修复(过去 7 天):
已自动修复的发现结果: 34
待手动修复: 51
已批准豁免: 8