

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

# 自动加密现有和新 Amazon EBS 卷
<a name="automatically-encrypt-existing-and-new-amazon-ebs-volumes"></a>

*Tony DeMarco 和 Josh Joy，Amazon Web Services*

## Summary
<a name="automatically-encrypt-existing-and-new-amazon-ebs-volumes-summary"></a>

Amazon Elastic Block Store (Amazon EBS) 卷加密对企业的数据保护策略非常重要。这是建立良好架构环境的重要一步。虽然没有直接的方法可以加密现有的未加密 EBS 卷或快照，但您可以通过创建新卷或快照来加密它们。有关更多信息，请参阅 Amazon EC2 文档中的[加密 EBS 资源](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/EBSEncryption.html#encryption-parameters)。此模式为加密新增和现有 EBS 卷提供了预防性控制和侦测性控制。在此模式中，您可以配置账户设置、创建自动修复流程以及实施访问控制。

## 先决条件和限制
<a name="automatically-encrypt-existing-and-new-amazon-ebs-volumes-prereqs"></a>

**先决条件**
+ 一个活跃的 Amazon Web Services（AWS）账户
+ [AWS 命令行界面（AWS CLI）](https://docs.aws.amazon.com/cli/latest/userguide/getting-started-install.html)，已在 macOS、Linux 或 Windows 上安装并配置。
+ [jq](https://stedolan.github.io/jq/download/)，已在 macOS、Linux 或 Windows 上安装并配置
+ AWS Identity and Access Management (IAM) 权限已配置为拥有对 AWS CloudFormation、亚马逊弹性计算云 (亚马逊 EC2)、AWS Systems Manager、AWS Config 和 AWS 密钥管理服务 (AWS KMS) 的读写权限
+ 已配置已启用所有功能的 AWS Organizations，这是服务控制策略的要求
+ AWS Config 已在目标账户中启用

**限制**
+ 在目标 AWS 账户中，不得存在名为 **encrypted-volumes** 的 AWS Config 规则。此解决方案部署具有此名称的规则。使用具有此名称的预先存在的规则可能会导致部署失败，并产生与多次处理同一规则相关的不必要费用。
+ 此解决方案采用同一 AWS KMS 密钥对所有 EBS 卷加密。
+ 如果为账户启用了 EBS 卷加密，则此设置为区域特定。如果为某个 AWS 区域启用了它，则无法为该区域中单独的卷或快照禁用。有关更多信息，请参阅 Amazon EC2 文档中的[默认加密](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/EBSEncryption.html#encryption-by-default)。
+ 修复现有未加密的 EBS 卷时，请确保该 EC2 实例未在使用中。此自动化将关闭实例，以便分离未加密卷并附加加密卷。修复过程中会出现停机。如果这是您组织的关键基础架构，请确保[手动](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/scenarios-enis.html#create-a-low-budget-high-availability-solution)或[自动](https://docs.aws.amazon.com/autoscaling/ec2/userguide/what-is-amazon-ec2-auto-scaling.html)的高可用性配置已到位，以免影响该实例上运行的任何应用程序的可用性。建议仅在标准维护时段修复关键资源。

## 架构
<a name="automatically-encrypt-existing-and-new-amazon-ebs-volumes-architecture"></a>

**自动化工作流程**

![显示自动化进程和服务的高级架构图](http://docs.aws.amazon.com/zh_cn/prescriptive-guidance/latest/patterns/images/pattern-img/484fd5fe-e10a-41f6-aafe-260ea824883b/images/483f551c-ca1d-4c1e-b3c7-989df7d3b059.png)


1. AWS Config 检测到未加密 EBS 卷。

1. 管理员通过 AWS Config 向 Systems Manager 发送补救命令。

1. Systems Manager 自动生成未加密 EBS 卷的快照。

1. Systems Manager 自动使用 AWS KMS 创建快照的加密副本。

1. Systems Manager 自动化执行以下操作：

   1. 如果受影响的 EC2 实例正在运行，则将其停止

   1. 将卷的新加密副本附加到实 EC2 例

   1. 将 EC2 实例恢复到其原始状态

## 工具
<a name="automatically-encrypt-existing-and-new-amazon-ebs-volumes-tools"></a>

**AWS 服务**
+ [AWS CLI](https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-welcome.html) — AWS 命令行接口 (AWS CLI) Line Interface 提供对 AWS 服务的公共应用程序编程接口 APIs () 的直接访问。您可以使用 AWS CLI 探索服务的功能，并开发 Shell 脚本来管理资源。除了低级 API 等效命令，多项 Amazon Web Services 亦为 AWS CLI 提供了自定义项。自定义项可能包括更高级别的命令，可简化具有复杂 API 的服务的使用。
+ [AWS CloudFormation](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/Welcome.html) — AWS CloudFormation 是一项可帮助您建模和设置 AWS 资源的服务。您可以创建一个描述所需所有 AWS 资源（例如 Amazon EC2 实例）的模板，并 CloudFormation 为您预置和配置这些资源。
+ [AWS Config](https://docs.aws.amazon.com/config/latest/developerguide/WhatIsConfig.html) – AWS Config 可提供 AWS 账户中 AWS 资源配置的详细视图。这些信息包括资源之间的关联方式以及资源以前的配置方式，让您了解资源的配置和关系如何随着的时间的推移而更改。
+ [亚马逊 EC2](https://docs.aws.amazon.com/ec2/?id=docs_gateway) — Amazon Elastic Compute Cloud (Amazon EC2) 是一项网络服务，可提供可调整的计算容量，供您构建和托管软件系统。
+ [AWS KMS](https://docs.aws.amazon.com/kms/latest/developerguide/overview.html) – AWS Key Management Service (AWS KMS) 是一项扩展到云的加密和密钥管理服务。AWS KMS 密钥和功能可用于其他 Amazon Web Services，您可以使用它们保护 AWS 环境中的数据。
+ [AWS Organizations](https://docs.aws.amazon.com/organizations/latest/userguide/orgs_introduction.html) – AWS Organizations 是一项账户管理服务，可让您将多个 AWS 账户整合到您创建并集中管理的组织中。
+ [AWS Systems Manager Aut](https://docs.aws.amazon.com/systems-manager/latest/userguide/systems-manager-automation.html) omation — Systems Manager Automation 简化了亚马逊 EC2 实例和其他 AWS 资源的常见维护和部署任务。

**其他服务**
+ [jq](https://stedolan.github.io/jq/download/) – jq 是一个轻量级且灵活的命令行 JSON 处理器。您使用此工具从 AWS CLI 输出中提取关键信息。

**代码**
+ 此模式的代码可在[使用客户 KMS 密钥 GitHub 自动修复未加密的 EBS 卷存储库](https://github.com/aws-samples/aws-system-manager-automation-unencrypted-to-encrypted-resources/tree/main/ebs)中找到。

## 操作说明
<a name="automatically-encrypt-existing-and-new-amazon-ebs-volumes-epics"></a>

### 自动修复未加密卷
<a name="automate-remediation-of-unencrypted-volumes"></a>


| Task | 说明 | 所需技能 | 
| --- | --- | --- | 
| 下载脚本和 CloudFormation 模板。 | 从[使用客户 KMS 密钥存储库 GitHub 自动修复未加密的 EBS 卷](https://github.com/aws-samples/aws-system-manager-automation-unencrypted-to-encrypted-resources/tree/main/ebs)中下载 shell 脚本、JSON 文件和 CloudFormation 模板。 | AWS 管理员、常规 AWS | 
| 确定 AWS KMS 密钥管理员。 | [See the AWS documentation website for more details](http://docs.aws.amazon.com/zh_cn/prescriptive-guidance/latest/patterns/automatically-encrypt-existing-and-new-amazon-ebs-volumes.html) | AWS 管理员、常规 AWS | 
| 部署 Stack1 模板 CloudFormation 。 | [See the AWS documentation website for more details](http://docs.aws.amazon.com/zh_cn/prescriptive-guidance/latest/patterns/automatically-encrypt-existing-and-new-amazon-ebs-volumes.html)有关部署 CloudFormation 模板的更多信息，请参阅 CloudFormation 文档中的[使用 AWS CloudFormation 模板](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/template-guide.html)。 | AWS 管理员、常规 AWS | 
| 部署 Stack2 模板 CloudFormation 。 | 在 CloudFormation中，部署`Stack2.yaml`模板。请注意以下部署详细信息：[See the AWS documentation website for more details](http://docs.aws.amazon.com/zh_cn/prescriptive-guidance/latest/patterns/automatically-encrypt-existing-and-new-amazon-ebs-volumes.html) | AWS 管理员、常规 AWS | 
| 创建测试用未加密卷。 | 使用未加密 EBS 卷创建 EC2 实例。有关说明，请参阅[亚马逊 EC2 文档中的创建 Amazon EBS 卷](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ebs-creating-volume.html)。实例类型并不重要，无需访问该实例。您可以创建 t2.micro 实例，以保留在免费套餐中，且无需创建密钥对。 | AWS 管理员、常规 AWS | 
| 测试 AWS Config 规则。 | [See the AWS documentation website for more details](http://docs.aws.amazon.com/zh_cn/prescriptive-guidance/latest/patterns/automatically-encrypt-existing-and-new-amazon-ebs-volumes.html)您可以在 Systems Manager 中查看如下修复进度与状态：[See the AWS documentation website for more details](http://docs.aws.amazon.com/zh_cn/prescriptive-guidance/latest/patterns/automatically-encrypt-existing-and-new-amazon-ebs-volumes.html) | AWS 管理员、常规 AWS | 
| 配置其他账户或者 AWS 区域。 | 根据您的用例需要，对任何其他账户或 AWS 区域重复此操作 | AWS 管理员、常规 AWS | 

### 启用 EBS 卷的账户级加密
<a name="enable-account-level-encryption-of-ebs-volumes"></a>


| Task | 说明 | 所需技能 | 
| --- | --- | --- | 
| 运行启用脚本。 | [See the AWS documentation website for more details](http://docs.aws.amazon.com/zh_cn/prescriptive-guidance/latest/patterns/automatically-encrypt-existing-and-new-amazon-ebs-volumes.html) | AWS 管理员、常规 AWS、bash | 
| 确认设置已更新。 | [See the AWS documentation website for more details](http://docs.aws.amazon.com/zh_cn/prescriptive-guidance/latest/patterns/automatically-encrypt-existing-and-new-amazon-ebs-volumes.html) | AWS 管理员、常规 AWS | 
| 配置其他账户或者 AWS 区域。 | 根据您的用例需要，对任何其他账户或 AWS 区域重复此操作 | AWS 管理员、常规 AWS | 

### 避免创建未加密实例
<a name="prevent-creation-of-unencrypted-instances"></a>


| Task | 说明 | 所需技能 | 
| --- | --- | --- | 
| 创建服务控制策略。 | [See the AWS documentation website for more details](http://docs.aws.amazon.com/zh_cn/prescriptive-guidance/latest/patterns/automatically-encrypt-existing-and-new-amazon-ebs-volumes.html) | AWS 管理员、常规 AWS | 

## 相关资源
<a name="automatically-encrypt-existing-and-new-amazon-ebs-volumes-resources"></a>

**Amazon Web Services 文档**
+ [AWS CLI](https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-welcome.html)
+ [AWS Config](https://docs.aws.amazon.com/config/latest/developerguide/WhatIsConfig.html)
+ [AWS CloudFormation](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/Welcome.html)
+ [Amazon EC2](https://docs.aws.amazon.com/ec2/?id=docs_gateway)
+ [AWS KMS](https://docs.aws.amazon.com/kms/latest/developerguide/overview.html)
+ [AWS Organizations](https://docs.aws.amazon.com/organizations/latest/userguide/orgs_introduction.html)
+ [AWS Systems Manager Automation](https://docs.aws.amazon.com/systems-manager/latest/userguide/systems-manager-automation.html)

**其他资源**
+ [jq 手册](https://stedolan.github.io/jq/manual/)（jq 网站）
+ [jq 下载](https://github.com/stedolan/jq) () GitHub