The interface is localized. Skill descriptions and documents are machine-translated by AI into your language; code, commands, paths and technical terms stay in the original, and the author's document governs.
Explore skills
Productivity · SKILL.md

implementing-aws-security-hub-compliance

implementing-aws-security-hub-compliance

实施 AWS Security Hub 跨 AWS 账户聚合安全发现结果,启用 CIS AWS Foundations 和 PCI DSS 等合规标准,通过 EventBridge 和 Lambda 配置自动修复,并为组织风险管理创建自定义安全洞察。

Independent GitHub snapshot · Automated classification · Original documentation governs

Skill documentation

GitHub

name: implementing-aws-security-hub-compliance description: > 实施 AWS Security Hub 跨 AWS 账户聚合安全发现结果,启用 CIS AWS Foundations 和 PCI DSS 等合规标准,通过 EventBridge 和 Lambda 配置自动修复,并为组织风险管理创建自定义安全洞察。 domain: cybersecurity subdomain: cloud-security tags: [cloud-security, aws, security-hub, compliance, cspm, cis-benchmark] version: "1.0" author: mahipal license: Apache-2.0

实施 AWS Security Hub 合规

适用场景

  • 在多个 AWS 账户之间建立集中式安全态势管理时
  • 合规要求需要针对 CIS、PCI DSS 或 NIST 800-53 标准进行持续监控时
  • 聚合来自 GuardDuty、Inspector、Macie、Firewall Manager 和第三方工具的发现结果时
  • 构建由安全发现结果触发的自动修复工作流时
  • 管理层需要跨组织安全合规仪表盘时

不适用于:实时威胁检测(使用 GuardDuty)、漏洞扫描(使用 Inspector)或数据分类(使用 Macie)。Security Hub 聚合来自这些服务的发现结果,但不能取代它们。

前置条件

  • 具有 Security Hub 委派管理员的 AWS Organizations
  • 具备 securityhub:*、config:*、events:* 和 lambda:* 的 IAM 权限
  • 在所有目标账户和区域启用 AWS Config(Security Hub 必需)
  • 用于多账户部署的 CloudFormation StackSets 或 Terraform
  • 已配置 SNS 主题用于向安全团队路由告警

工作流程

步骤 1:启用 Security Hub 并配置合规标准

在管理账户中启用 Security Hub,并选择要评估的合规标准。

# 在当前账户/区域启用 Security Hub
aws securityhub enable-security-hub \
  --enable-default-standards \
  --control-finding-generator SECURITY_CONTROL

# 启用特定合规标准
aws securityhub batch-enable-standards --standards-subscription-requests \
  '[
    {"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/cis-aws-foundations-benchmark/v/1.4.0"},
    {"StandardsArn": "arn:aws:securityhub:us-east-1::standards/pci-dss/v/3.2.1"},
    {"StandardsArn": "arn:aws:securityhub:us-east-1::standards/nist-800-53/v/5.0.0"}
  ]'

# 验证已启用的标准
aws securityhub get-enabled-standards \
  --query 'StandardsSubscriptions[*].[StandardsArn,StandardsStatus]' --output table

步骤 2:配置多账户聚合

设置委派管理员,并聚合来自所有组织账户的发现结果。

# 指定委派管理员(从管理账户执行)
aws securityhub enable-organization-admin-account \
  --admin-account-id 111122223333

# 从委派管理员账户启用自动注册
aws securityhub update-organization-configuration \
  --auto-enable \
  --auto-enable-standards DEFAULT

# 创建跨区域发现结果聚合器
aws securityhub create-finding-aggregator \
  --region-linking-mode ALL_REGIONS

# 列出成员账户
aws securityhub list-members \
  --query 'Members[*].[AccountId,MemberStatus]' --output table

步骤 3:审查合规评分和失败控制项

查询 Security Hub 以了解已启用标准的合规态势,并识别失败的控制项。

# 获取 CIS 基准的总体合规评分
aws securityhub get-standards-control-associations \
  --security-control-id "IAM.1" \
  --query 'StandardsControlAssociationSummaries[*].[StandardsArn,AssociationStatus]' \
  --output table

# 列出所有失败的控制项
aws securityhub get-findings \
  --filters '{
    "ComplianceStatus": [{"Value": "FAILED", "Comparison": "EQUALS"}],
    "RecordState": [{"Value": "ACTIVE", "Comparison": "EQUALS"}],
    "WorkflowStatus": [{"Value": "NEW", "Comparison": "EQUALS"}]
  }' \
  --sort-criteria '{"Field": "SeverityNormalized", "SortOrder": "desc"}' \
  --max-items 50 \
  --query 'Findings[*].[Title,Severity.Label,Compliance.Status,Resources[0].Id]' \
  --output table

# 按严重程度获取发现结果计数
aws securityhub get-insight-results \
  --insight-arn "arn:aws:securityhub:us-east-1:111122223333:insight/111122223333/default/2"

步骤 4:创建自定义安全洞察

构建自定义洞察以跟踪组织特定的安全优先事项。

# 创建针对公开可访问资源的洞察
aws securityhub create-insight \
  --name "公开可访问的资源" \
  --filters '{
    "ResourceType": [
      {"Value": "AwsS3Bucket", "Comparison": "EQUALS"},
      {"Value": "AwsEc2SecurityGroup", "Comparison": "EQUALS"},
      {"Value": "AwsRdsDbInstance", "Comparison": "EQUALS"}
    ],
    "ComplianceStatus": [{"Value": "FAILED", "Comparison": "EQUALS"}],
    "SeverityLabel": [{"Value": "CRITICAL", "Comparison": "EQUALS"}, {"Value": "HIGH", "Comparison": "EQUALS"}]
  }' \
  --group-by-attribute "ResourceType"

# 创建针对未加密资源的洞察
aws securityhub create-insight \
  --name "跨账户未加密资源" \
  --filters '{
    "Title": [{"Value": "encryption", "Comparison": "CONTAINS"}],
    "ComplianceStatus": [{"Value": "FAILED", "Comparison": "EQUALS"}]
  }' \
  --group-by-attribute "AwsAccountId"

步骤 5:通过 EventBridge 配置自动修复

设置 EventBridge 规则,为特定发现结果类型触发基于 Lambda 的自动修复。

# 为 Security Hub 发现结果创建 EventBridge 规则
aws events put-rule \
  --name "security-hub-critical-findings" \
  --event-pattern '{
    "source": ["aws.securityhub"],
    "detail-type": ["Security Hub Findings - Imported"],
    "detail": {
      "findings": {
        "Severity": {"Label": ["CRITICAL"]},
        "Compliance": {"Status": ["FAILED"]},
        "Workflow": {"Status": ["NEW"]}
      }
    }
  }'

# S3 公开访问自动修复示例 Lambda(Python)
cat > /tmp/remediate_s3.py << 'PYEOF'
import boto3
import json

def lambda_handler(event, context):
    s3 = boto3.client('s3')
    securityhub = boto3.client('securityhub')

    for finding in event['detail']['findings']:
        if 'S3' in finding.get('Title', '') and 'public' in finding.get('Title', '').lower():
            bucket_arn = finding['Resources'][0]['Id']
            bucket_name = bucket_arn.split(':::')[-1]

            s3.put_public_access_block(
                Bucket=bucket_name,
                PublicAccessBlockConfiguration={
                    'BlockPublicAcls': True,
                    'IgnorePublicAcls': True,
                    'BlockPublicPolicy': True,
                    'RestrictPublicBuckets': True
                }
            )

            securityhub.batch_update_findings(
                FindingIdentifiers=[{
                    'Id': finding['Id'],
                    'ProductArn': finding['ProductArn']
                }],
                Workflow={'Status': 'RESOLVED'},
                Note={
                    'Text': '自动修复:已启用阻止公开访问',
                    'UpdatedBy': 'security-hub-auto-remediation'
                }
            )
    return {'statusCode': 200}
PYEOF

步骤 6:导出发现结果并生成合规报告

导出 Security Hub 发现结果,用于报告和与外部 SIEM 或 GRC 平台集成。

# 通过自定义脚本将所有发现结果导出到 S3
aws securityhub get-findings \
  --filters '{
    "RecordState": [{"Value": "ACTIVE", "Comparison": "EQUALS"}]
  }' \
  --max-items 1000 \
  --output json > security-hub-findings-export.json

# 将严重发现结果发送到 SNS
aws sns publish \
  --topic-arn arn:aws:sns:us-east-1:111122223333:security-alerts \
  --subject "Security Hub 每日摘要" \
  --message file://daily-summary.json

# 通过 EventBridge 集成第三方 SIEM
aws events put-targets \
  --rule security-hub-critical-findings \
  --targets '[{
    "Id": "splunk-hec",
    "Arn": "arn:aws:events:us-east-1:111122223333:api-destination/splunk-hec",
    "HttpParameters": {
      "HeaderParameters": {"Authorization": "Splunk HEC_TOKEN"}
    }
  }]'

核心概念

术语定义
Security HubAWS 服务,聚合来自 AWS 服务和第三方工具的安全发现结果,评估对标准的合规性,并提供统一的安全仪表盘
安全标准(Security Standard)Security Hub 针对您的 AWS 配置进行评估的预定义安全控制集(CIS、PCI DSS、NIST 800-53)
安全控制(Security Control)标准中的单个检查项,评估特定 AWS 资源配置,例如 S3 存储桶是否阻止公开访问
发现结果(Finding)Security Hub 或集成服务检测到的安全问题,采用 AWS Security Finding Format(ASFF)格式
洞察(Insight)按特定属性分组的自定义或托管发现结果集合,为安全分析提供聚合视图
ASFFAWS Security Finding Format,所有 Security Hub 集成使用的标准化 JSON 模式,确保发现结果表示的一致性

工具与系统

  • AWS Security Hub:跨 AWS 账户安全发现结果聚合和合规评估的中央平台
  • AWS Config:Security Hub 评估资源合规性所必需的配置记录服务
  • Amazon EventBridge:将 Security Hub 发现结果路由到 Lambda、SNS 或外部修复系统的事件总线
  • AWS Lambda:由 Security Hub 发现结果触发的自动修复函数的无服务器计算平台
  • Prowler:可通过 ASFF 集成将发现结果发送到 Security Hub 的开源工具

常见场景

场景:在 50 账户组织中推广 Security Hub

场景背景:安全团队需要在 AWS Organization 的所有账户中启用具有 CIS 和 FSBP 标准的 Security Hub,实现集中化发现结果聚合和自动告警。

方法:

  1. 在管理账户中启用 Security Hub,并将安全账户指定为委派管理员
  2. 通过 update-organization-configuration 为所有现有和新成员账户配置自动启用
  3. 创建跨区域发现结果聚合器,将所有区域的发现结果整合到管理员账户
  4. 在所有账户中启用 CIS AWS Foundations 1.4 和 AWS FSBP 标准
  5. 创建 EventBridge 规则,将严重(CRITICAL)发现结果路由到 PagerDuty,将所有发现结果发送到 Splunk
  6. 为组织最高风险构建自定义洞察:公开资源、缺失加密、未使用凭据
  7. 使用 Lambda 和 SES 为相关方安排每周合规报告

常见陷阱:Security Hub 要求在每个账户和区域启用 AWS Config。未能启用 Config 将导致控制项显示为"无数据"而非 PASSED 或 FAILED。Config 已禁用的成员账户将静默产生不完整的合规评分。

输出格式

AWS Security Hub 合规报告
=====================================
组织: acme-corp(50 个账户)
区域: us-east-1(来自所有区域的聚合)
报告日期: 2026-02-23
已启用标准: CIS 1.4, FSBP v1.0, PCI DSS 3.2.1

合规评分:
  CIS AWS Foundations 1.4:     78%(182 个控制项中 142 个通过)
  AWS FSBP v1.0.0:             85%(233 个控制项中 198 个通过)
  PCI DSS 3.2.1:               72%(124 个控制项中 89 个通过)

严重发现结果: 23
高级发现结果: 87
中级发现结果: 245
低级发现结果: 412

失败控制项 TOP 排行:
  [IAM.6]  Root 账户未启用 MFA           12 个账户
  [S3.2]   S3 未启用阻止公开访问          8 个账户
  [EC2.19] 安全组允许无限制访问           15 个账户
  [RDS.3]  RDS 未启用静态加密             6 个账户

自动修复操作(过去 30 天):
  已启用 S3 阻止公开访问:    14 次
  已限制安全组规则:           8 次
  已重新启用 CloudTrail 日志:  3 次
  自动修复发现结果总计:       25 次
Saved skills