--- name: implementing-aws-security-hub description: > 部署 AWS Security Hub 作为集中式云安全态势管理平台,聚合来自 GuardDuty、Inspector、Macie 和第三方工具的发现结果,启用 CIS AWS Foundations Benchmark 等安全标准,配置自动修复,并构建跨多账户 AWS 组织的合规跟踪执行仪表盘。 domain: cybersecurity subdomain: cloud-security tags: [aws-security-hub, cspm, compliance-automation, security-standards, finding-aggregation] version: 1.0.0 author: mahipal license: Apache-2.0 --- # 实施 AWS Security Hub ## 适用场景 - 在多个 AWS 账户之间建立集中式安全发现结果仪表盘时 - 针对 CIS、PCI-DSS、NIST 或 AWS 基础安全最佳实践启用自动化合规检查时 - 集成来自 GuardDuty、Inspector、Macie 和第三方安全工具的发现结果时 - 为频繁出现的安全错误配置构建自动修复工作流时 - 为需要持续态势监控的审计人员准备合规证据时 **不适用于**:实时威胁检测(参见 detecting-cloud-threats-with-guardduty)、Azure 合规监控(参见 securing-azure-with-microsoft-defender),或对容器镜像进行深度漏洞扫描(参见 securing-container-registry)。 ## 前置条件 - 具有指定安全管理员账户的 AWS Organization - 在所有目标账户和区域启用 AWS Config - 已激活 GuardDuty、Inspector 和 Macie 以集成发现结果 - 管理员账户具备 `securityhub:*` 和 `config:*` IAM 权限 ## 工作流程 ### 步骤 1:启用 Security Hub 并配置安全标准 在委派管理员账户中激活 Security Hub 并启用安全标准。AWS Security Hub CSPM(云安全态势管理)支持 CIS AWS Foundations Benchmark v5.0、AWS 基础安全最佳实践(FSBP)、PCI DSS v3.2.1 和 NIST SP 800-53。 ```bash # 启用 Security Hub 并加载默认标准 aws securityhub enable-security-hub \ --enable-default-standards \ --tags '{"Environment":"production","ManagedBy":"security-team"}' # 启用 CIS AWS Foundations Benchmark v5.0 aws securityhub batch-enable-standards \ --standards-subscription-requests '[ {"StandardsArn": "arn:aws:securityhub:::ruleset/cis-aws-foundations-benchmark/v/5.0.0"}, {"StandardsArn": "arn:aws:securityhub:us-east-1::standards/aws-foundational-security-best-practices/v/1.0.0"}, {"StandardsArn": "arn:aws:securityhub:us-east-1::standards/pci-dss/v/3.2.1"} ]' # 验证已启用的标准 aws securityhub get-enabled-standards \ --query 'StandardsSubscriptions[*].[StandardsArn,StandardsStatus]' --output table ``` ### 步骤 2:配置多账户聚合 指定 Security Hub 管理员并自动注册所有组织成员账户。配置跨区域聚合,将发现结果整合到单一区域。 ```bash # 指定委派管理员 aws securityhub enable-organization-admin-account \ --admin-account-id 111122223333 # 为所有组织成员自动启用 aws securityhub update-organization-configuration \ --auto-enable \ --organization-configuration '{"ConfigurationType": "CENTRAL"}' # 启用跨区域聚合 aws securityhub create-finding-aggregator \ --region-linking-mode ALL_REGIONS ``` ### 步骤 3:集成安全服务和第三方工具 配置产品集成,接收来自 AWS 服务和合作伙伴安全工具的发现结果。将第三方发现结果映射到 AWS Security Finding Format(ASFF)。 ```bash # 列出可用的产品集成 aws securityhub describe-products \ --query 'Products[*].[ProductName,CompanyName,ProductSubscriptionResourcePolicy]' --output table # 启用特定集成 aws securityhub enable-import-findings-for-product \ --product-arn "arn:aws:securityhub:us-east-1::product/aws/guardduty" aws securityhub enable-import-findings-for-product \ --product-arn "arn:aws:securityhub:us-east-1::product/aws/inspector" # 使用 ASFF 格式导入自定义发现结果 aws securityhub batch-import-findings --findings '[{ "SchemaVersion": "2018-10-08", "Id": "custom-finding-001", "ProductArn": "arn:aws:securityhub:us-east-1:123456789012:product/123456789012/default", "GeneratorId": "custom-scanner", "AwsAccountId": "123456789012", "Types": ["Software and Configuration Checks/Vulnerabilities/CVE"], "Title": "生产 ALB 后端存在未修补的 OpenSSL 漏洞", "Description": "后端实例检测到 CVE-2024-12345", "Severity": {"Label": "HIGH"}, "Resources": [{"Type": "AwsEc2Instance", "Id": "arn:aws:ec2:us-east-1:123456789012:instance/i-0abc123"}] }]' ``` ### 步骤 4:构建自动修复 创建与 EventBridge 规则和 Lambda 函数关联的 Security Hub 自定义操作,实现对常见发现结果的一键式或全自动修复。 ```bash # 创建修复自定义操作 aws securityhub create-action-target \ --name "IsolateInstance" \ --description "通过替换安全组隔离 EC2 实例" \ --id "IsolateInstance" # 针对特定控制项自动修复的 EventBridge 规则 aws events put-rule \ --name SecurityHubAutoRemediate \ --event-pattern '{ "source": ["aws.securityhub"], "detail-type": ["Security Hub Findings - Imported"], "detail": { "findings": { "Compliance": {"Status": ["FAILED"]}, "Severity": {"Label": ["CRITICAL", "HIGH"]}, "GeneratorId": ["aws-foundational-security-best-practices/v/1.0.0/S3.1"] } } }' ``` ### 步骤 5:监控合规评分并生成报告 跟踪各标准的安全评分,监控合规漂移趋势,并生成用于审计证据的报告。 ```bash # 获取某个标准的安全评分 aws securityhub get-security-control-definition \ --security-control-id "S3.1" # 列出所有失败控制项及其数量 aws securityhub get-findings \ --filters '{ "ComplianceStatus": [{"Value": "FAILED", "Comparison": "EQUALS"}], "RecordState": [{"Value": "ACTIVE", "Comparison": "EQUALS"}] }' \ --sort-criteria '{"Field": "SeverityLabel", "SortOrder": "desc"}' \ --max-items 50 ``` ## 核心概念 | 术语 | 定义 | |------|------| | 安全标准(Security Standard) | 映射到 CIS、PCI-DSS、NIST 800-53 和 AWS 最佳实践等合规框架的预打包控制集 | | 安全控制(Security Control) | 针对特定安全要求评估 AWS 资源配置的单个自动化检查项 | | ASFF | AWS Security Finding Format,用于规范化所有集成安全产品发现结果的标准化 JSON 模式 | | 合规评分(Compliance Score) | 给定安全标准中处于通过状态的控制项百分比,按账户计算并在组织层面聚合 | | 发现结果聚合器(Finding Aggregator) | 将所有已启用区域的发现结果整合到单一管理员区域的跨区域机制 | | 自定义操作(Custom Action) | 可从 Security Hub 控制台触发的用户定义操作,用于调用 EventBridge 规则进行手动或自动响应 | ## 工具与系统 - **AWS Security Hub CSPM**:用于自动化安全态势检查和发现结果聚合的核心平台 - **AWS Config**:Security Hub 依赖的用于资源评估的底层配置记录器 - **Amazon EventBridge**:将 Security Hub 发现结果连接到自动修复工作流的事件路由服务 - **AWS Systems Manager**:Security Hub 可调用的自动化文档,用于修复常见错误配置 - **AWS Audit Manager**:使用 Security Hub 发现结果作为证据生成审计就绪报告 ## 常见场景 ### 场景:50 个账户中的 CIS 控制项失败 **场景背景**:一家企业启用 CIS AWS Foundations Benchmark v5.0 后,在 50 个账户中发现 340 个失败的控制项,主要集中在 IAM 密码策略、CloudTrail 配置和 VPC 流日志启用方面。 **方法**: 1. 按控制项 ID 导出所有 FAILED 发现结果,识别最普遍的问题 2. 优先处理影响最多账户的严重和高严重性控制项 3. 为出现频率最高的前 10 个失败项创建 Systems Manager Automation 文档 4. 通过 EventBridge 为 S3.1(阻止公开访问)和 CloudTrail.1(启用多区域跟踪)等控制项部署自动修复 5. 安排每周合规评分审查,并在 90 天修复窗口内跟踪改进情况 **常见陷阱**:一次性为所有控制项启用自动修复可能会破坏合法需要公开 S3 访问或特定网络配置的生产工作负载。务必先在预发布账户中测试修复操作。 ## 输出格式 ``` AWS Security Hub 合规报告 ==================================== 组织: acme-corp 管理员账户: 111122223333 报告日期: 2025-02-23 已启用标准: CIS v5.0, AWS FSBP v1.0, PCI DSS v3.2.1 合规评分: CIS AWS Foundations Benchmark v5.0: 78% AWS 基础安全最佳实践: 85% PCI DSS v3.2.1: 72% 失败控制项 TOP 排行(按账户数量): [S3.1] 已启用阻止公开访问设置 - 50 个账户中 23 个失败 [CT.1] 已启用 CloudTrail 多区域 - 50 个账户中 12 个失败 [IAM.4] Root 账户无访问密钥 - 50 个账户中 3 个失败 [EC2.19] 安全组限制未受限端口 - 50 个账户中 31 个失败 [RDS.3] 已启用 RDS 静态加密 - 50 个账户中 18 个失败 发现结果摘要: 活跃发现结果总计: 1,247 严重: 34 | 高: 189 | 中: 567 | 低: 457 本月自动修复: 89 已抑制: 23 ```