CSPM 雲端安全態勢管理
Vibe Prompt
「幫我設定 AWS Config Rules 自動檢查:S3 是否開放公開存取、EBS 是否加密、RDS 是否公開。」
AWS Config Rules
import * as config from 'aws-cdk-lib/aws-config';
// S3 檢查
new config.ManagedRule(this, 'S3PublicRead', {
identifier: config.ManagedRuleIdentifiers.S3_BUCKET_PUBLIC_READ_PROHIBITED,
});
new config.ManagedRule(this, 'S3PublicWrite', {
identifier: config.ManagedRuleIdentifiers.S3_BUCKET_PUBLIC_WRITE_PROHIBITED,
});
// EBS 加密檢查
new config.ManagedRule(this, 'EbsEncryption', {
identifier: config.ManagedRuleIdentifiers.ENCRYPTED_VOLUMES,
});
// RDS 公開存取檢查
new config.ManagedRule(this, 'RdsPublic', {
identifier: config.ManagedRuleIdentifiers.RDS_INSTANCE_PUBLIC_ACCESS_CHECK,
});
// IAM 檢查
new config.ManagedRule(this, 'IamUserNoPolicy', {
identifier: config.ManagedRuleIdentifiers.IAM_USER_NO_POLICIES_CHECK,
});
常見檢查項目
| 資源 | 檢查 | |------|------| | S3 | 是否公開、是否加密、是否版本控制 | | RDS | 是否公開、是否加密、備份是否啟用 | | EC2 | 是否使用 IMDSv2、SG 是否過於寬鬆 | | IAM | 是否有未使用的權限、是否啟用 MFA | | Lambda | 是否允許公開存取、執行角色是否最小權限 |
AWS Security Hub 整合
Security Hub
├── AWS Config Rules (合規檢查)
├── GuardDuty (威脅偵測)
├── Inspector (漏洞掃描)
├── Macie (敏感資料發現)
└── 第三方整合 (Prowler, ScoutSuite, Pacu)
自動修復
// 自動修復:S3 公開存取 → 自動阻擋
new config.RemediationConfiguration(this, 'RemediateS3Public', {
targetType: config.RemediationTargetType.SSM_DOCUMENT,
targetId: 'AWS-DisableS3BucketPublicReadWrite',
parameters: [
{ name: 'BucketName', resourceValue: 'RESOURCE_ID' },
],
automatic: true,
executionControls: {
ssmControls: { maxExecutionRate: 10, errorPercentage: 10 },
},
});
工具
| 工具 | 描述 | |------|------| | AWS Security Hub | 內建 CSPM | | Prowler | 開源 AWS/ Azure/ GCP 安全評估 | | ScoutSuite | 開源多雲端安全稽核 | | Checkov | IaC 安全掃描 |