使用 KMS CMK 進行磁碟加密 - Amazon EMR

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

使用 KMS CMK 進行磁碟加密

EMR Serverless 預設會使用服務擁有的加密金鑰來加密連接至工作者的所有磁碟。您可以選擇使用自己的 AWS KMS 客戶受管金鑰 (CMKs來加密這些磁碟。這可讓您進一步控制加密金鑰,包括建立和維護金鑰政策的能力,以及稽核金鑰用量。

您可以在建立應用程式或提交個別任務時設定磁碟加密。在應用程式層級啟用時,該應用程式上的所有任務都會繼承加密設定。您也可以在提交任務時指定磁碟加密組態,覆寫應用程式的預設值。

注意

EMR Serverless 磁碟加密僅支援對稱 KMS 金鑰。不支援非對稱 KMS 金鑰。您必須使用在 中建立的對稱加密 KMS 金鑰 AWS KMS。如需詳細資訊 AWS KMS,請參閱什麼是 AWS KMS?

使用加密內容

或者,EMR Serverless 使用加密內容,為加密操作提供額外的已驗證資料。加密內容是一組金鑰/值對,可包含非秘密的其他已驗證資料。加密內容以密碼編譯方式繫結至加密的資料,因此需要相同的加密內容才能解密資料。

在 EMR Serverless 中,您可以在設定磁碟加密時指定自訂加密內容。此加密內容包含在 AWS CloudTrail 日誌中,可協助您識別和了解 KMS 操作。

注意

請勿在加密內容中存放敏感資訊,因為它在 AWS CloudTrail 日誌中以純文字顯示。

使用客戶受管金鑰設定磁碟加密

CreateApplication

若要使用您自己的 KMS 金鑰加密磁碟,請在建立 EMR Serverless 應用程式時包含 diskEncryptionConfiguration 參數。

aws emr-serverless create-application \ --type TYPE \ --name APPLICATION_ID \ --release-label RELEASE_LABEL \ --region AWS_REGION \ --disk-encryption-configuration '{ "encryptionKeyArn": "key-arn", "encryptionContext": { "key": "value" } }'

UpdateApplication

若要更新 KMS 金鑰 ARN 和/或加密內容,請在更新應用程式時以新值指定 diskEncryptionConfiguration 參數。

aws emr-serverless update-application \ --name APPLICATION_ID \ --region AWS_REGION \ --disk-encryption-configuration '{ "encryptionKeyArn": "key-arn", "encryptionContext": { "key": "value" } }'
注意

若要在應用程式上取消設定設定的磁碟加密,請在更新應用程式diskEncryptionConfiguration期間傳遞空的 。

StartJobRun

若要使用您自己的 KMS 金鑰加密磁碟,請在提交任務執行時使用 diskEncryptionConfiguration組態。

--configuration-overrides '{ "diskEncryptionConfiguration": { "encryptionKeyArn": "key-arn", "encryptionContext": { "key": "value" } } }'

Public Livy 端點

若要在透過公有 Livy 端點建立 Spark 工作階段時,使用您自己的 KMS 金鑰加密磁碟,請在工作階段的 conf 物件中指定加密組態。

data = { "kind": "pyspark", "heartbeatTimeoutInSecond": 60, "conf": { "emr-serverless.session.executionRoleArn": "role_arn", "spark.emr-serverless.disk.encryptionKeyArn": "key-arn", "spark.emr-serverless.disk.encryptionContext": "key1:value1,key2:value2" # Optional } } # Send request to create a session with the Livy API endpoint request = AWSRequest(method='POST', url=endpoint + "/sessions", data=json.dumps(data), headers=headers)

磁碟加密所需的許可

EMR Serverless 的加密金鑰許可

當您使用自己的加密金鑰加密磁碟時,您必須為emr-serverless.amazonaws.com委託人設定下列 KMS 金鑰許可:

  • kms:GenerateDataKey :產生用於加密磁碟區的資料金鑰

  • kms:Decrypt :存取加密磁碟內容時解密資料金鑰

{ "Effect": "Allow", "Principal":{ "Service": "emr-serverless.amazonaws.com" }, "Action": [ "kms:Decrypt", "kms:GenerateDataKey" ], "Resource": "*", "Condition": { "StringLike": { "aws:SourceArn": "arn:aws:emr-serverless:region:aws-account-id:/applications/application-id" }, "StringEquals": { "kms:EncryptionContext:applicationId": "application-id", "aws:SourceAccount": "aws-account-id" } } }

作為安全最佳實務,我們建議您將 aws:SourceArn條件金鑰新增至 KMS 金鑰政策。IAM 全域條件金鑰aws:SourceArn有助於確保 EMR Serverless 僅針對應用程式 ARN 使用 KMS 金鑰。此外,包括 aws:SourceAccount 條件金鑰,可將 KMS 金鑰的使用限制為來自條件中指定之 AWS 帳戶 ID 的請求,以提供另一層安全性。

任務執行期角色在其 IAM 政策中必須具有下列許可:

{ "Sid": "Enable GDK and Decrypt", "Version": "2012-10-17", "Statement": { "Effect": "Allow", "Action": [ "kms:GenerateDataKey", "kms:Decrypt" ], "Resource": "key-arn" } }

必要的使用者許可

提交任務的使用者必須具有使用金鑰的許可。您可以在 KMS 金鑰政策或使用者、群組或角色的 IAM 政策中指定許可。如果提交任務的使用者缺少 KMS 金鑰許可,EMR Serverless 會拒絕任務執行提交。

範例金鑰政策

下列金鑰政策提供 kms:DescribeKeykms:GenerateDataKey和 的許可kms:Decrypt

  • kms:DescribeKey :在使用前,驗證客戶受管 KMS 金鑰已啟用和 SYMMETRIC。

{ "Sid": "Enable DescribeKey", "Effect": "Allow", "Principal":{ "AWS": "arn:aws:iam::111122223333:user/user-name" }, "Action": [ "kms:DescribeKey" ], "Resource": "*" }, { "Sid": "Enable GDK and Decrypt", "Effect": "Allow", "Principal":{ "AWS": "arn:aws:iam::111122223333:user/user-name" }, "Action": [ "kms:GenerateDataKey", "kms:Decrypt" ], "Resource": "*", "Condition": { "StringEquals": { "kms:ViaService": "emr-serverless.region.amazonaws.com", "kms:EncryptionContext:key": "value" } } }

作為安全最佳實務,建議您將 kms:viaService條件金鑰新增至 KMS 金鑰政策。它將 KMS 金鑰的使用限制為僅來自 emr-serverless 的驗證請求。

IAM 政策範例

下列 IAM 政策提供許可給 kms:DescribeKeykms:GenerateDataKeykms:Decrypt

{ "Version": "2012-10-17", "Statement": { "Effect": "Allow", "Action": [ "kms:DescribeKey", "kms:GenerateDataKey", "kms:Decrypt" ], "Resource": "key-arn" } }

監控金鑰用量

您可以監控 EMR Serverless through AWS CloudTrail. AWS CloudTrail captures 中客戶受管金鑰對 的所有 API 呼叫 AWS KMS 做為事件的使用,包括來自 EMR Serverless 主控台、EMR Serverless API、 AWS CLI 或 AWS SDK 的呼叫。

擷取的資訊包含您指定的加密內容,可協助您識別和稽核使用 KMS 金鑰的特定 EMR Serverless 資源。例如,您可能會在 中看到類似下列的事件 AWS CloudTrail。如需使用 的詳細資訊 AWS CloudTrail,請參閱 AWS CloudTrail 使用者指南

GenerateDataKey

EMR Serverless 正在建立加密磁碟區時 GenerateDataKey 操作的範例事件

{ "eventVersion": "1.11", "userIdentity": { "type": "AWSService", "principalId": "user", "invokedBy": "AWS Internal" }, "eventTime": "2025-07-28T21:43:51Z", "eventSource": "kms.amazonaws.com", "eventName": "GenerateDataKey", "awsRegion": "us-west-2", "sourceIPAddress": "ipAddress", "userAgent": "userAgent", "requestParameters": { "encryptionContext": { "applicationId": "test" }, "keyId": "arn:aws:kms:region:accountId:key/ffffffff-fffff-aaaaa-eeee-sample", "keySpec": "AES_256" }, "responseElements": null, "additionalEventData": { "keyMaterialId": "145c963debe558dfb01848d2a4539da940f3478852f86cfe2f52d5df796a5a02" }, "requestID": "cc9d1c5e-97c4-4a4f-ae7a-e576sample", "eventID": "0b0fef09-f28d-4da8-a5a1-17b74sample", "readOnly": true, "resources": [ { "accountId": "account", "type": "AWS::KMS::Key", "ARN": "arn:aws:kms:region:accountId:key/ffffffff-fffff-aaaaa-eeee-sample" } ], "eventType": "AwsApiCall", "managementEvent": true, "recipientAccountId": "accountId", "eventCategory": "Management" }

解密

EMR Serverless 存取加密資料時解密操作的範例事件。

{ "eventVersion": "1.11", "userIdentity": { "type": "AWSService", "principalId": "user", "invokedBy": "AWS Internal" }, "eventTime": "2025-07-28T21:43:51Z", "eventSource": "kms.amazonaws.com", "eventName": "Decrypt", "awsRegion": "us-west-2", "sourceIPAddress": "ipAddress", "userAgent": "userAgent", "requestParameters": { "encryptionContext": { "applicationId": "test" }, "keyId": "arn:aws:kms:region:accountId:key/ffffffff-fffff-aaaaa-eeee-sample", "keySpec": "AES_256" }, "responseElements": null, "additionalEventData": { "keyMaterialId": "145c963debe558dfb01848d2a4539da940f3478852f86cfe2f52d5df796a5a02" }, "requestID": "cc9d1c5e-97c4-4a4f-ae7a-e576sample", "eventID": "0b0fef09-f28d-4da8-a5a1-17b74sample", "readOnly": true, "resources": [ { "accountId": "account", "type": "AWS::KMS::Key", "ARN": "arn:aws:kms:region:accountId:key/ffffffff-fffff-aaaaa-eeee-sample" } ], "eventType": "AwsApiCall", "managementEvent": true, "recipientAccountId": "accountId", "eventCategory": "Management" }

進一步了解

下列資源會提供有關靜態資料加密的詳細資訊。