為 Amazon ECS 的 Fargate 暫時性儲存建立加密金鑰 - Amazon Elastic Container Service

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

為 Amazon ECS 的 Fargate 暫時性儲存建立加密金鑰

建立客戶受管金鑰來加密儲存在 Fargate 暫時性儲存體上的資料。

注意

Fargate 暫時性儲存加密搭配客戶受管金鑰不適用於 Windows 任務叢集。

使用客戶受管金鑰的 Fargate 暫時性儲存加密不適用於platformVersions早於 的 1.4.0

Fargate 會在僅供 Fargate 使用的暫時性儲存體上保留空間,且不會向您收取該空間的費用。配置可能與非客戶受管金鑰任務不同,但總空間保持不變。您可以在 等工具中檢視此變更df

Fargate 暫時性儲存不支援多區域金鑰。

Fargate 暫時性儲存不支援 KMS 金鑰別名。

若要建立客戶受管金鑰 (CMK) 來加密 Fargate 中的暫時性儲存 AWS KMS,請遵循下列步驟。

  1. 導覽至 https://https://console.aws.amazon.com/kms

  2. 請遵循《 AWS Key Management Service 開發人員指南》中建立金鑰的指示。

  3. 建立 AWS KMS 金鑰時,請務必在金鑰政策中提供 Fargate 服務相關的 AWS KMS 操作許可。政策中必須允許下列 API 操作,才能將客戶受管金鑰與 Amazon ECS 叢集資源搭配使用。

    • kms:GenerateDataKeyWithoutPlainText ‐ 呼叫 從提供的金鑰GenerateDataKeyWithoutPlainText產生加密的資料 AWS KMS 金鑰。

    • kms:CreateGrant ‐ 將授予新增至客戶受管金鑰。授予控制對指定 AWS KMS 金鑰的存取,該金鑰允許存取授予 Amazon ECS Fargate 所需的操作。如需使用授權的詳細資訊,請參閱 AWS Key Management Service 開發人員指南。這可讓 Amazon ECS Fargate 執行下列動作:

      • 呼叫 Decrypt AWS KMS 以取得加密金鑰,以解密暫時性儲存資料。

      • 設定淘汰委託人以允許 服務至 RetireGrant

    • kms:DescribeKey ‐ 提供客戶受管金鑰詳細資訊,以允許 Amazon ECS 驗證金鑰是否對稱且已啟用。

    下列範例顯示您要套用至目標 AWS KMS 金鑰以進行加密的金鑰政策。若要使用範例政策陳述式,請以您自己的資訊取代使用者輸入預留位置。一如往常,只設定您需要的許可,但您需要為至少一個使用者提供 AWS KMS 許可,以避免錯誤。

    { "Sid": "Allow generate data key access for Fargate tasks.", "Effect": "Allow", "Principal": { "Service":"fargate.amazonaws.com" }, "Action": [ "kms:GenerateDataKeyWithoutPlaintext" ], "Condition": { "StringEquals": { "kms:EncryptionContext:aws:ecs:clusterAccount": [ "customerAccountId" ], "kms:EncryptionContext:aws:ecs:clusterName": [ "clusterName" ] } }, "Resource": "*" }, { "Sid": "Allow grant creation permission for Fargate tasks.", "Effect": "Allow", "Principal": { "Service":"fargate.amazonaws.com" }, "Action": [ "kms:CreateGrant" ], "Condition": { "StringEquals": { "kms:EncryptionContext:aws:ecs:clusterAccount": [ "customerAccountId" ], "kms:EncryptionContext:aws:ecs:clusterName": [ "clusterName" ] }, "ForAllValues:StringEquals": { "kms:GrantOperations": [ "Decrypt" ] } }, "Resource": "*" }, { "Sid": "Allow describe key permission for cluster operator - CreateCluster and UpdateCluster.", "Effect": "Allow", "Principal": { "AWS":"arn:aws:iam::customerAccountId:role/customer-chosen-role" }, "Action": [ "kms:DescribeKey" ], "Resource": "*" }

    Fargate 任務使用 aws:ecs:clusterAccountaws:ecs:clusterName加密內容金鑰搭配 金鑰進行密碼編譯操作。客戶應新增這些許可,以限制對特定帳戶和/或叢集的存取。當您指定叢集時,請使用叢集名稱而非 ARN。

    如需詳細資訊,請參閱 AWS KMS 開發人員指南中的加密內容

    建立或更新叢集時,您可以選擇使用 條件金鑰 fargateEphemeralStorageKmsKeyId。此條件金鑰可讓客戶更精細地控制 IAM 政策。fargateEphemeralStorageKmsKeyId 組態的更新只會在新的服務部署上生效。

    以下是允許客戶僅將許可授予一組特定核准 AWS KMS 金鑰的範例。

    { "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": [ "ecs:CreateCluster", "ecs:UpdateCluster" ], "Resource": "*", "Condition": { "StringEquals": { "ecs:fargate-ephemeral-storage-kms-key": "arn:aws:kms:us-west-2:111122223333:key/a1b2c3d4-5678-90ab-cdef-EXAMPLE11111" } } } ] }

    接下來是拒絕嘗試移除已與叢集建立關聯的 AWS KMS 金鑰的範例。

    { "Version": "2012-10-17", "Statement": { "Effect": "Deny", "Action": [ "ecs:CreateCluster", "ecs:UpdateCluster" ], "Resource": "*", "Condition": { "Null": { "ecs:fargate-ephemeral-storage-kms-key": "true" } } } }

    客戶可以使用 describe-cluster、 或 AWS CLI describe-tasksdescribe-services命令,查看其未受管任務或服務任務是否使用 金鑰加密。

    如需詳細資訊,請參閱《 AWS KMS 開發人員指南》中的 的條件金鑰 AWS KMS

AWS Management Console
  1. 開啟主控台,網址為 https://console.aws.amazon.com/ecs/v2

  2. 選擇左側導覽中的叢集,然後在右上角建立叢集,或選擇現有叢集。針對現有叢集,選擇右上角的更新叢集

  3. 在工作流程的加密區段下,您可以選擇在受管儲存Fargate 暫時性儲存下選取 AWS KMS 金鑰。您也可以從這裡選擇建立 AWS KMS 金鑰

  4. 完成建立新叢集後,請選擇建立,如果您要更新現有的叢集,請選擇更新

AWS CLI

以下是使用 建立叢集和設定 Fargate 暫時性儲存的範例 AWS CLI (使用您自己的值取代紅色值):

aws ecs create-cluster --cluster clusterName \ --configuration '{"managedStorageConfiguration":{"fargateEphemeralStorageKmsKeyId":"arn:aws:kms:us-west-2:012345678901:key/a1b2c3d4-5678-90ab-cdef-EXAMPLE11111"}}' { "cluster": { "clusterArn": "arn:aws:ecs:us-west-2:012345678901:cluster/clusterName", "clusterName": "clusterName", "configuration": { "managedStorageConfiguration": { "fargateEphemeralStorageKmsKeyId": "arn:aws:kms:us-west-2:012345678901:key/a1b2c3d4-5678-90ab-cdef-EXAMPLE11111" } }, "status": "ACTIVE", "registeredContainerInstancesCount": 0, "runningTasksCount": 0, "pendingTasksCount": 0, "activeServicesCount": 0, "statistics": [], "tags": [], "settings": [], "capacityProviders": [], "defaultCapacityProviderStrategy": [] }, "clusterCount": 5 }
AWS CloudFormation

以下是使用 AWS CloudFormation (使用您自己的值取代紅色值) 建立叢集和設定 Fargate 暫時性儲存的範例範本:

AWSTemplateFormatVersion: 2010-09-09 Resources: MyCluster: Type: AWS::ECS::Cluster Properties: ClusterName: "clusterName" Configuration: ManagedStorageConfiguration: FargateEphemeralStorageKmsKeyId: "arn:aws:kms:us-west-2:012345678901:key/a1b2c3d4-5678-90ab-cdef-EXAMPLE11111"