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

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

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

建立客戶自管金鑰,加密儲存於 Fargate 暫時性儲存中的資料。

注意

使用客戶自管金鑰的 Fargate 暫時性儲存加密,不適用於 Windows 任務叢集。

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

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

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

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

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

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

  2. 請遵循 AWS Key Management Service Developer Guide 中的 Creating Keys 的說明操作。

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

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

    • kms:CreateGrant:新增客戶自管金鑰的授權。授予控制對指定 AWS KMS 金鑰的存取,該金鑰允許存取授予 Amazon ECS Fargate 所需的操作。如需詳細資訊,請參閱 AWS Key Management Service Developer Guide 中的 Using Grants。此授權使 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 金鑰的範例。

    JSON
    { "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 金鑰的範例。

    JSON
    { "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 Developer Guide 中的 Condition keys for AWS KMS

AWS 管理主控台
  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 }
CloudFormation

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

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"