

本文為英文版的機器翻譯版本，如內容有任何歧義或不一致之處，概以英文版為準。

# 自動加密現有和新的 Amazon EBS 磁碟區
<a name="automatically-encrypt-existing-and-new-amazon-ebs-volumes"></a>

*Tony DeMarco 和 Josh Joy，Amazon Web Services*

## 總結
<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)。 Amazon EC2 此模式提供預防性和偵測性控制，用於加密新的和現有的 EBS 磁碟區。在此模式中，您可以設定帳戶設定、建立自動修復程序，以及實作存取控制。

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

**先決條件**
+ 作用中的 Amazon Web Services (AWS) 帳戶
+ [在 macOS、Linux 或 Windows 上安裝和設定 AWS Command Line Interface (AWS CLI)](https://docs.aws.amazon.com/cli/latest/userguide/getting-started-install.html) macOS
+ 在 macOS、Linux 或 Windows 上安裝和設定 [jq](https://stedolan.github.io/jq/download/)
+ AWS Identity and Access Management (IAM) 許可佈建為具有 AWS CloudFormation、Amazon Elastic Compute Cloud (Amazon EC2)、AWS Systems Manager、AWS Config 和 AWS Key Management Service (AWS KMS) 的讀取和寫入存取權
+ AWS Organizations 設定已啟用所有功能，這是服務控制政策的需求
+ 目標帳戶中已啟用 AWS Config 

**限制**
+ 在您的目標 AWS 帳戶中，不得有名為**加密磁碟區的** 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)高可用性組態，以免影響執行個體上執行的任何應用程式的可用性。建議您只在標準維護時段內修復關鍵資源。

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

**自動化工作流程**

![\[顯示自動化程序與服務的高階架構圖\]](http://docs.aws.amazon.com/zh_tw/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) 可讓您直接存取 AWS 服務的公有應用程式程式設計界面 (APIs)。您可以使用 AWS CLI 探索服務的功能，並開發 shell 指令碼來管理您的 資源。除了低階 API 同等命令之外，數個 AWS 服務還提供 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 資源組態的詳細檢視。這包含資源彼此之間的關係和之前的組態方式，所以您可以看到一段時間中組態和關係的變化。
+ [Amazon EC2](https://docs.aws.amazon.com/ec2/?id=docs_gateway) – Amazon Elastic Compute Cloud (Amazon EC2) 是一種 Web 服務，可提供可調整大小的運算容量，讓您用來建置和託管軟體系統。
+ [AWS KMS](https://docs.aws.amazon.com/kms/latest/developerguide/overview.html) – AWS Key Management Service (AWS KMS) 是一種針對雲端擴展的加密和金鑰管理服務。其他 AWS 服務會使用 AWS KMS 金鑰和功能，您可以使用它們來保護 AWS 環境中的資料。
+ [AWS Organizations](https://docs.aws.amazon.com/organizations/latest/userguide/orgs_introduction.html) – AWS Organizations 是一種帳戶管理服務，可讓您將多個 AWS 帳戶合併到您建立並集中管理的組織。
+ [AWS Systems Manager Automation](https://docs.aws.amazon.com/systems-manager/latest/userguide/systems-manager-automation.html) – Systems Manager Automation 可簡化 Amazon EC2 執行個體和其他 AWS 資源的常見維護和部署任務。

**其他服務**
+ [jq](https://stedolan.github.io/jq/download/) – jq 是輕量且靈活的命令列 JSON 處理器。您可以使用此工具從 AWS CLI 輸出擷取金鑰資訊。

**Code**
+ 此模式的程式碼可在 GitHub [中使用客戶 KMS 金鑰儲存庫自動修復未加密的 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>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 下載指令碼和 CloudFormation 範本。 | 從 GitHub 下載 shell 指令碼、JSON 檔案和 CloudFormation 範本 [使用客戶 KMS 金鑰儲存庫自動修復未加密的 EBS 磁碟](https://github.com/aws-samples/aws-system-manager-automation-unencrypted-to-encrypted-resources/tree/main/ebs)區。 | AWS 管理員，一般 AWS | 
| 識別 AWS KMS 金鑰的管理員。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/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_tw/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) CloudFormation 範本。 | AWS 管理員，一般 AWS | 
| 部署 Stack2 CloudFormation 範本。 | 在 CloudFormation 中，部署 `Stack2.yaml` 範本。請注意下列部署詳細資訊：[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/automatically-encrypt-existing-and-new-amazon-ebs-volumes.html) | AWS 管理員，一般 AWS | 
| 建立未加密的磁碟區進行測試。 | 使用未加密的 EBS 磁碟區建立 EC2 執行個體。如需說明，請參閱[《Amazon EC2 文件》中的建立 Amazon EBS 磁碟區](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ebs-creating-volume.html)。 Amazon EC2 執行個體類型並不重要，而且不需要存取執行個體。您可以建立 t2.micro 執行個體以保留在免費方案中，而且不需要建立金鑰對。 | AWS 管理員，一般 AWS | 
| 測試 AWS Config 規則。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/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_tw/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>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 執行啟用指令碼。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/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_tw/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>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 建立服務控制政策。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/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>

**AWS 服務文件**
+ [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 自動化](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)