

本文属于机器翻译版本。若本译文内容与英语原文存在差异，则一律以英文原文为准。

# 创建一份包含多个 Prowler 安全调查结果的合并报告 AWS 账户
<a name="create-a-consolidated-report-of-prowler-security-findings-from-multiple-aws-accounts"></a>

*Mike Virgilio、Jay Durga 和 Andrea Di Fabio，Amazon Web Services*

## Summary
<a name="create-a-consolidated-report-of-prowler-security-findings-from-multiple-aws-accounts-summary"></a>

[Prowler](https://github.com/prowler-cloud/prowler) (GitHub) 是一个开源命令行工具，可以帮助您评估、审计和监控您的 Amazon Web Services (AWS) 账户是否符合安全最佳实践。在这种模式下，您可以将 Prowler 部署到组织 AWS 账户 中由管理的集中管理中 AWS Organizations，然后使用 Prowler 对组织中的所有帐户进行安全评估。

虽然部署和使用 Prowler 进行评测的方法有很多，但该解决方案旨在实现快速部署、全面分析组织中的所有账户或已定义的目标客户，以及安全调查发现的可访问报告。按此解决方案，当 Prowler 完成对组织中所有账户的安全评测时，它会合并结果。它还会过滤掉任何预期错误消息，例如与限制 Prowler 无法扫描通过 AWS Control Tower配置的账户中的 Amazon Simple Storage Service (Amazon S3) 存储桶相关的错误。筛选后的合并结果将在此操作说明中包含的 Microsoft Excel 模板中报告。您可以使用此报告确定组织中安全控件的潜在改进。

该解决方案的设计考虑了以下内容：
+ 这些 AWS CloudFormation 模板减少了在这种模式下部署 AWS 资源所需的工作量。
+ 您可以在部署时调整 CloudFormation 模板和 **prowler\$1scan.sh** 脚本中的参数，以便为您的环境自定义模板。
+ 通过并行处理 AWS 账户、汇总结果、合并报告和建议的补救措施以及自动生成的可视化效果来优化 Prowler 的评估和报告速度。
+ 用户不需要监控扫描进度。评测完成后，Amazon Simple Notiﬁcation Service (Amazon SNS) 主题将通知用户，以便他们可检索报告。
+ 报告模板可帮助您仅阅读和评测整个组织相关结果。

## 先决条件和限制
<a name="create-a-consolidated-report-of-prowler-security-findings-from-multiple-aws-accounts-prereqs"></a>

**先决条件**
+  AWS 账户 用于托管安全服务和工具，作为中组织的成员帐户进行管理 AWS Organizations。在这种模式中，此账户被称为 *安全账户*。
+ 在安全账户中，必须具有具有出站互联网访问权限的私有子网。有关说明，请参阅 Amazon Virtual Private Cloud (Amazon VPC) 文档中的[私有子网和 NAT 中的 服务器 VPC](https://docs.aws.amazon.com/vpc/latest/userguide/vpc-example-private-subnets-nat.html)。您可以使用在公有子网中配置的 [NAT 网关](https://docs.aws.amazon.com/vpc/latest/userguide/vpc-nat-gateway.html)建立互联网接入。
+ 对 AWS Organizations 管理账户或拥有委托管理员权限的账户的访问权限 CloudFormation。有关说明，请参阅 CloudFormation 文档[中的注册委托管理员](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/stacksets-orgs-delegated-admin.html)。
+ 在 AWS Organizations 和之间启用可信访问 CloudFormation。有关说明，请参阅 CloudFormation 文档 AWS Organizations中的[使用启用可信访问](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/stacksets-orgs-enable-trusted-access.html)。

**限制**
+ 目标 AWS 账户 必须作为一个组织在中进行管理 AWS Organizations。如果您不使用 AWS Organizations，则可以更新适用于您的环境的 **IAM-ProwlerExecRole .yaml** CloudFormation 模板和 **prowler\$1scan.sh** 脚本。相反，您可以提供要在其中运行脚本的 AWS 账户 IDs 和区域的列表。
+ 该 CloudFormation 模板旨在将亚马逊弹性计算云 (Amazon EC2) 实例部署到具有出站互联网访问权限的私有子网中。 AWS Systems Manager 代理（SSM 代理）需要出站访问权限才能访问 AWS Systems Manager 服务端点，并且您需要出站访问权限才能克隆代码存储库和安装依赖项。[如果要使用公有子网，则必须修改 p **rowler-resources.yaml** 模板以将弹性 IP 地址与实例相关联。](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/elastic-ip-addresses-eip.html) EC2 

**产品版本**
+ Prowler 版本 4.0 或更高版本

## 架构
<a name="create-a-consolidated-report-of-prowler-security-findings-from-multiple-aws-accounts-architecture"></a>

![\[部署至集中式安全账户中的 Prowler 的架构图。\]](http://docs.aws.amazon.com/zh_cn/prescriptive-guidance/latest/patterns/images/pattern-img/81ba9037-9958-4e4a-95b7-d68896075a5b/images/4a3c281c-f108-4e35-9683-72783ceb3336.png)


此图显示以下流程：

1. 使用会话管理器（一种功能） AWS Systems Manager，用户对 EC2 实例进行身份验证并运行 **prowler\$1scan.sh** 脚本。此 Shell 脚本执行步骤 2-8。

1. 该 EC2 实例担任 `ProwlerEC2Role` IAM 角色，该角色授予访问 S3 存储桶和在组织中其他账户中担任 `ProwlerExecRole` IAM 角色的权限。

1. 该 EC2 实例在组织的管理账户中担任 `ProwlerExecRole` IAM 角色，并生成组织中的账户列表。

1. 该 EC2 实例在组织的成员账户（架构图中称为*工作负载账户*）中担任 `ProwlerExecRole` IAM 角色，并在每个账户中执行安全评估。调查结果以 CSV 和 HTML 文件的形式存储在 EC2 实例上。
**注意**  
 HTML 文件非 Prowler 评测的输出。由于 HTML 的性质，它们不在此模式中进行串联、处理或直接使用。但是，这些可能对个人账户报告审核很有用。

1. 该 EC2 实例处理所有 CSV 文件以删除已知的预期错误，并将剩余的发现结果合并到一个 CSV 文件中。

1. 该 EC2 实例将个人账户结果和汇总结果打包到一个 zip 文件中。

1.  EC2 实例将 zip 文件上传到 S3 存储桶。

1.  EventBridge 规则会检测文件上传，并使用 Amazon SNS 主题向用户发送电子邮件，通知他们评估已完成。

1. 用户从 S3 存储桶下载 zip 文件。用户将结果导入 Excel 模板，并查看结果。

## 工具
<a name="create-a-consolidated-report-of-prowler-security-findings-from-multiple-aws-accounts-tools"></a>

**AWS 服务**
+ [亚马逊弹性计算云 (Amazon EC2)](https://docs.aws.amazon.com/ec2/) 在中提供可扩展的计算容量 AWS 云。您可以根据需要启动任意数量的虚拟服务器，并快速纵向扩展或缩减这些服务器。
+ [Amazon EventBridge](https://docs.aws.amazon.com/eventbridge/latest/userguide/eb-what-is.html) 是一项无服务器事件总线服务，可帮助您将应用程序与来自各种来源的实时数据连接起来。例如， AWS Lambda 函数、使用 API 目的地的 HTTP 调用端点或其他 AWS 账户目的地的事件总线。
+ [AWS Identity and Access Management (IAM)](https://docs.aws.amazon.com/IAM/latest/UserGuide/introduction.html) 通过控制谁经过身份验证并有权使用 AWS 资源，从而帮助您安全地管理对资源的访问权限。
+ [AWS Organizations](https://docs.aws.amazon.com/organizations/latest/userguide/orgs_introduction.html)是一项账户管理服务，可帮助您将多个账户整合 AWS 账户 到一个由您创建和集中管理的组织中。
+ [Amazon Simple Notification Service（Amazon SNS）](https://docs.aws.amazon.com/sns/latest/dg/welcome.html)可帮助您协调和管理发布者与客户端（包括 Web 服务器和电子邮件地址）之间的消息交换。
+ [Amazon Simple Storage Service（Amazon S3）](https://docs.aws.amazon.com/AmazonS3/latest/userguide/Welcome.html)是一项基于云的对象存储服务，可帮助您存储、保护和检索任意数量的数据。
+ [AWS Systems Manager](https://docs.aws.amazon.com/systems-manager/latest/userguide/what-is-systems-manager.html) 可帮助您管理在 AWS 云中运行的应用程序和基础设施。它简化了应用程序和资源管理，缩短了检测和解决操作问题的时间，并帮助您大规模安全地管理 AWS 资源。此模式使用会话管理器，这是 Systems Manager 的一项功能。

**其他工具**
+ [Prowler](https://github.com/prowler-cloud/prowler/#requirements-and-installation) 是一款开源命令行工具，可帮助您评估、审计和监控您的账户是否符合 AWS 安全最佳实践以及其他安全框架和标准。

**代码存储库**

此模式的代码可[通过 Prowler 存储库在 GitHub 多账户安全评估](https://github.com/aws-samples/multi-account-security-assessment-via-prowler)中找到。代码存储库包含以下文件：
+ **prowler\$1scan.sh** — 此 bash 脚本用于并行启动多个 AWS 账户 Prowler 安全评估。按照 **Prowler-Resources.yaml** 中的定义 CloudFormationtemplate，此脚本会自动部署到实例上的文件夹。`usr/local/prowler` EC2 
+ **Prowler-resources.yaml** — 您可以使用此 CloudFormation 模板在组织的安全账户中创建堆栈。此模板部署了该账户所需所有资源，以支持此解决方案。此堆栈必须在 **IAM-ProwlerExecRole .yaml** 模板之前部署。我们不建议您将这些资源部署至托管关键生产工作负载的账户中。
**注意**  
如果删除并重新部署此堆栈，则必须重新构建 `ProwlerExecRole` 堆栈集，以便重新构建 IAM 角色之间的跨账户依赖关系。
+ **IAM-ProwlerExecRole .yaml** — 您可以使用此 CloudFormation 模板创建堆栈集，用于在组织中的所有账户（包括管理账户）中部署 `ProwlerExecRole` IAM 角色。
+ **prowler-report-template.xlsm** — 您可以使用此 Excel 模板来处理 Prowler 的调查结果。报告中的数据透视表提供搜索功能、图表与综合调查发现。

## 操作说明
<a name="create-a-consolidated-report-of-prowler-security-findings-from-multiple-aws-accounts-epics"></a>

### 准备部署
<a name="prepare-for-deployment"></a>


| Task | 说明 | 所需技能 | 
| --- | --- | --- | 
| 克隆代码存储库。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_cn/prescriptive-guidance/latest/patterns/create-a-consolidated-report-of-prowler-security-findings-from-multiple-aws-accounts.html) | AWS DevOps | 
| 审核模板。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_cn/prescriptive-guidance/latest/patterns/create-a-consolidated-report-of-prowler-security-findings-from-multiple-aws-accounts.html) | AWS DevOps | 

### 创建堆 CloudFormation 栈
<a name="create-the-cfnshort-stacks"></a>


| Task | 说明 | 所需技能 | 
| --- | --- | --- | 
| 在安全账户中预置资源。 | 使用 **prowler-resources.yaml** 模板，您可以创建一个 CloudFormation 堆栈，用于在安全账户中部署所有必需的资源。有关说明，请参阅 CloudFormation 文档中的[创建堆栈](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/cfn-console-create-stack.html)。部署此模板时应注意以下几点：[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_cn/prescriptive-guidance/latest/patterns/create-a-consolidated-report-of-prowler-security-findings-from-multiple-aws-accounts.html) | AWS DevOps | 
| 在成员账户中预置 IAM 角色。 | 在 AWS Organizations 管理账户或具有委托管理员权限的账户中 CloudFormation，使用 **IAM-ProwlerExecRole .yaml** 模板创建 CloudFormation 堆栈集。堆栈集在组织中的所有成员账户中部署 `ProwlerExecRole` IAM 角色。有关说明，请参阅 CloudFormation 文档中的[使用服务管理权限创建堆栈集](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/stacksets-getting-started-create.html#stacksets-orgs-associate-stackset-with-org)。部署此模板时应注意以下几点：[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_cn/prescriptive-guidance/latest/patterns/create-a-consolidated-report-of-prowler-security-findings-from-multiple-aws-accounts.html) | AWS DevOps | 
| 在管理账户中预置 IAM 角色。 | 使用 **IAM-ProwlerExecRole .yaml** 模板，您可以创建一个 CloudFormation 堆栈，用于在组织的管理账户中部署 `ProwlerExecRole` IAM 角色。您之前创建的堆栈集不在管理账户中部署 IAM 角色。有关说明，请参阅 CloudFormation 文档中的[创建堆栈](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/cfn-console-create-stack.html)。部署此模板时应注意以下几点：[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_cn/prescriptive-guidance/latest/patterns/create-a-consolidated-report-of-prowler-security-findings-from-multiple-aws-accounts.html) | AWS DevOps | 

### 执行 Prowler 安全评测
<a name="perform-the-prowler-security-assessment"></a>


| Task | 说明 | 所需技能 | 
| --- | --- | --- | 
| 运行扫描。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_cn/prescriptive-guidance/latest/patterns/create-a-consolidated-report-of-prowler-security-findings-from-multiple-aws-accounts.html) | AWS 管理员 | 
| 检索 Prowler 调查发现。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_cn/prescriptive-guidance/latest/patterns/create-a-consolidated-report-of-prowler-security-findings-from-multiple-aws-accounts.html) | 常规 AWS | 
| 停止实 EC2 例。 | 为防止在实例空闲时计费，请停止运行 Prowler 的 EC2 实例。有关说明，请参阅 Amazon EC2 文档中的[停止和启动您的实例](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/Stop_Start.html#starting-stopping-instances)。 | AWS DevOps | 

### 创建调查发现报告
<a name="create-a-report-of-the-findings"></a>


| Task | 说明 | 所需技能 | 
| --- | --- | --- | 
| 导入调查发现。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_cn/prescriptive-guidance/latest/patterns/create-a-consolidated-report-of-prowler-security-findings-from-multiple-aws-accounts.html) | 常规 AWS | 
| 完成报告。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_cn/prescriptive-guidance/latest/patterns/create-a-consolidated-report-of-prowler-security-findings-from-multiple-aws-accounts.html) | 常规 AWS | 

### （可选）更新 Prowler 或代码存储库中的资源
<a name="optional-update-prowler-or-the-resources-in-the-code-repository"></a>


| Task | 说明 | 所需技能 | 
| --- | --- | --- | 
| 更新 Prowler。 | 如果要将 Prowler 更新至最新版本，请执行以下操作：[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_cn/prescriptive-guidance/latest/patterns/create-a-consolidated-report-of-prowler-security-findings-from-multiple-aws-accounts.html) | 常规 AWS | 
| 更新 prowler\$1scan.sh 脚本。 | 如果要将 **prowler\$1scan.sh** 脚本更新至存储库中的最新版本，请执行以下操作：[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_cn/prescriptive-guidance/latest/patterns/create-a-consolidated-report-of-prowler-security-findings-from-multiple-aws-accounts.html)您可能会收到与任何不在 GitHub 存储库中的本地生成的文件相关的警告，例如查找报告。只要 **prowler\$1scan.sh** 显示本地隐藏的更改已合并，就可以忽略这些内容。 | 常规 AWS | 

### (可选)清除
<a name="optional-clean-up"></a>


| Task | 说明 | 所需技能 | 
| --- | --- | --- | 
| 删除所有已部署资源。 | 您可以将资源保留在账户中。如果您在 EC2 实例未使用时将其关闭，并保持 S3 存储桶为空，则可以降低维护资源以备将来扫描的成本。如果要取消预配所有资源，请执行以下操作：[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_cn/prescriptive-guidance/latest/patterns/create-a-consolidated-report-of-prowler-security-findings-from-multiple-aws-accounts.html) | AWS DevOps | 

## 问题排查
<a name="create-a-consolidated-report-of-prowler-security-findings-from-multiple-aws-accounts-troubleshooting"></a>


| 问题 | 解决方案 | 
| --- | --- | 
| 无法使用会话管理器连接到 EC2 实例。 | SSM 代理必须能够与 Systems Manager 端点通信。执行以下操作：[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_cn/prescriptive-guidance/latest/patterns/create-a-consolidated-report-of-prowler-security-findings-from-multiple-aws-accounts.html) | 
| 部署堆栈集时， CloudFormation 控制台会提示您这样做`Enable trusted access with AWS Organizations to use service-managed permissions`。 | 这表示未在 AWS Organizations 和之间启用可信访问 CloudFormation。部署服务托管堆栈集需要可信访问权限。选择该按钮以启用受信任的访问。有关更多信息，请参阅 CloudFormation 文档中的[启用可信访问](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/stacksets-orgs-enable-trusted-access.html)。 | 

## 相关资源
<a name="create-a-consolidated-report-of-prowler-security-findings-from-multiple-aws-accounts-resources"></a>

**AWS 文档**
+ [在 AWS（AWS 规范性指南）上实施安全控制](https://docs.aws.amazon.com/prescriptive-guidance/latest/aws-security-controls/introduction.html)

**其他资源**
+ [Prowler (](https://github.com/prowler-cloud/prowler)) GitHub

## 附加信息
<a name="create-a-consolidated-report-of-prowler-security-findings-from-multiple-aws-accounts-additional"></a>

**以编程方式删除错误**

如果结果包含 `Access Denied` 错误，则应将其从调查发现中删除。这些错误通常是由于外部影响权限导致 Prowler 无法评测特定资源造成的。例如，在查看通过配置的 S3 存储桶时，某些检查会失败。 AWS Control Tower您可通过编程方式提取这些结果，并将筛选后的结果另存为新文件。

以下命令删除包含单个文本字符串（一种模式）行，然后将结果输出至新文件中。
+ 适用于 Linux 或 macOS (Grep)

  ```
  grep -v -i "Access Denied getting bucket" myoutput.csv > myoutput_modified.csv
  ```
+ 适用于 Windows (PowerShell)

  ```
  Select-String -Path myoutput.csv -Pattern 'Access Denied getting bucket' -NotMatch > myoutput_modified.csv
  ```

以下命令删除与多个文本字符串匹配的行，然后将结果输出至新文件。
+ 对于 Linux 或 macOS（在字符串之间使用转义管道）

  ```
  grep -v -i 'Access Denied getting bucket\|Access Denied Trying to Get' myoutput.csv > myoutput_modified.csv
  ```
+ 适用于 Windows（在字符串之间使用逗号）

  ```
  Select-String -Path myoutput.csv -Pattern 'Access Denied getting bucket', 'Access Denied Trying to Get' -NotMatch > myoutput_modified.csv
  ```

**报告示例**

下图是 Prowler 合并调查发现报告中的**调查发现**工作表示例。

![\[Prowler 扫描结果报告中的“调查发现”选项卡示例\]](http://docs.aws.amazon.com/zh_cn/prescriptive-guidance/latest/patterns/images/pattern-img/81ba9037-9958-4e4a-95b7-d68896075a5b/images/70311fc4-b919-4848-b200-40b35ce81826.png)


下图是 Prowler 合并调查发现报告中的 **Pass Fail** 工作表的示例。（默认情况下，输出中不包括通过结果。）

![\[Prowler 扫描结果报告中的“通过失败” 选项卡示例\]](http://docs.aws.amazon.com/zh_cn/prescriptive-guidance/latest/patterns/images/pattern-img/81ba9037-9958-4e4a-95b7-d68896075a5b/images/4823e2be-4d5e-4676-9fa3-d47b065dc6d8.png)


下图是 Prowler 合并调查发现报告中**严重性**工作表的示例。

![\[Prowler 扫描结果报告中的“严重性” 选项卡示例\]](http://docs.aws.amazon.com/zh_cn/prescriptive-guidance/latest/patterns/images/pattern-img/81ba9037-9958-4e4a-95b7-d68896075a5b/images/b7cbbff1-bca3-4667-9a1e-cc92e2e4adcd.png)
