靜態加密:如何使用客戶受管金鑰加密 Amazon 金 Keyspaces 中的表格 - Amazon Keyspaces (適用於 Apache Cassandra)

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

靜態加密:如何使用客戶受管金鑰加密 Amazon 金 Keyspaces 中的表格

您可以使用主控台或 CQL 陳述式,AWS KMS key為新資料表指定,並更新 Amazon Key Keyspaces 中現有資料表的加密金鑰。下列主題概述如何為新資料表和現有資料表實作客戶管理金鑰。

先決條件:使用建立客戶受管金鑰,AWS KMS並授與權限給 Amazon 金 Keyspaces

您必須先在AWS Key Management Service (AWS KMS) 中建立金鑰,然後授權 Amazon 密鑰空間使用該金鑰,然後授權 Amazon 金鑰空間使用該金鑰,才能使用客戶受管金鑰。

步驟 1:使用建立客戶受管金鑰AWS KMS

若要建立用於保護 Amazon 金鑰空間表的客戶受管金鑰,您可以按照使用主控台或AWS API 建立對稱加密 KMS 金鑰中的步驟進行操作。

步驟 2:授權使用客戶管理的金鑰

在選擇客戶受管金鑰來保護 Amazon Key角資料表之前,該客戶受管金鑰上的政策必須授予 Amazon Keyspaces 許可,以代您使用該金鑰。您有客戶受管金鑰的政策和授予,您有客戶受管金鑰的政策和授予。您可以在金鑰政策IAM 政策授予中提供這些許可。

Amazon Keyspaces 不需要額外的授權,就能使用預設AWS 擁有的金鑰保護AWS帳戶中的 Amazon Keyspaces space 資料表。

下列主題說明如何使用允許 Amazon 密鑰 Keyspaces 表使用客戶受管金鑰的 IAM 政策和授權來設定所需的許可。

客戶受管理鑰的金鑰政策

當您選取客戶受管金鑰來保護 Amazon Key角資料表時,Amazon Keyspaces 會取得許可,以代表進行選取的委託人使用客戶受管金鑰。該主體 (使用者或角色) 必須具有 Amazon 金鑰 Keyspaces 所需之客戶受管金鑰的許可。

至少,Amazon 金 Keyspaces 在客戶受管金鑰上需要具備下列許可:

範例金鑰政策

例如,以下範例金鑰政策只會提供必要許可。政策具有下列效果:

  • 允許 Amazon Keyspaces space 在加密操作中使用客戶受管金鑰並建立授予,但只有在其代表具備使用 Amazon Keyspace 許可的帳戶中的委託人時才能進行。如果政策陳述式中指定的委託人沒有使用 Amazon Key space 的許可,Keyspaces 叫便會失敗,即使呼叫是來自 Amazon Keyspace 服務也一樣。

  • kms:ViaService 條件金鑰只會在請求來自 Amazon KKeyspaces space 時,才會代表政策陳述式中列出的委託人時才會允許可。這些委託人無法直接呼叫這些操作。請注意,kms:ViaService 值 (cassandra.*.amazonaws.com) 在區域位置中有星號 (*)。Amazon Keyspaces 需要許可獨立於任何特定的權限AWS 區域。

  • 給予客戶受管金鑰管理員 (可取得db-team角色的使用者) 對客戶受管金鑰的唯讀存取權以及撤銷授予的許可,包括 Amazon Key角需要用來保護資料表的授予。

  • 提供 Amazon 金 Keyspaces 對客戶受管金鑰的唯讀存取權。在這種情況下,Amazon Keyspaces 可以直接調用這些操作。不必代表帳戶委託人。

在使用範例金鑰政策前,請將範例委託人替換成您 AWS 帳戶 中的實際委託人。

{ "Id": "key-policy-cassandra", "Version":"2012-10-17", "Statement": [ { "Sid" : "Allow access through Amazon Keyspaces for all principals in the account that are authorized to use Amazon Keyspaces", "Effect": "Allow", "Principal": {"AWS": "arn:aws:iam::111122223333:user/db-lead"}, "Action": [ "kms:Encrypt", "kms:Decrypt", "kms:ReEncrypt*", "kms:GenerateDataKey*", "kms:DescribeKey", "kms:CreateGrant" ], "Resource": "*", "Condition": { "StringLike": { "kms:ViaService" : "cassandra.*.amazonaws.com" } } }, { "Sid": "Allow administrators to view the customer managed key and revoke grants", "Effect": "Allow", "Principal": { "AWS": "arn:aws:iam::111122223333:role/db-team" }, "Action": [ "kms:Describe*", "kms:Get*", "kms:List*", "kms:RevokeGrant" ], "Resource": "*" } ] }

使用授權 Amazon Keyspaces

除了金鑰政策外,Amazon Keyspaces 使用授予在客戶受管金鑰上設定許可。若要檢視您帳戶中客戶管理金鑰的授權,請使用ListGrants作業。Amazon Keyspaces 不需要授予或任何其他許可,就能使用AWS 擁有的金鑰來保護您的資料表。

Amazon Keyspaces space 在執行背景系統維護和持續資料保護任務時使用授予許可。它還使用授與來產生資料表金鑰。

每個授與都專屬於一個資料表。如果帳戶包含使用相同客戶受管金鑰加密的多個資料表,則每個資料表有每一種類型的授予。授權受 Amazon 密 Keyspaces 加密內容的限制,其中包括表名稱和AWS 帳戶 ID。如果不再需要授權,則授予包括退休授權的權限。

若要建立授予,Amazon Keyspaces 必須具有代表建立加密資料表使用者呼叫CreateGrant的許可。

金鑰政策也會允許帳戶撤銷客戶受管金鑰的授予。不過,如果您撤銷作用中加密資料表上的授予,Keyspaces space 將無法保護和維護資料表。

步驟 3:為新資料表指定客戶受管金鑰

請依照下列步驟,使用 Amazon Keyspaces space 主控台或 CQL 在新資料表中指定客戶受管金鑰。

使用客戶受管金鑰建立加密資料表 (主控台)

  1. 登入AWS Management Console,並在 https://console.aws.amazon.com/keyspaces/home 開啟 Amazon 索 Keyspaces 主控台。

  2. 在導覽窗格中,選擇 Tables (資料表),然後選擇 Create table (建立資料表)。

  3. 在「表格詳細資訊」段落的「建立表格」頁面中,選取索引鍵空間並輸入新表格的名稱。

  4. 在 [結構描述] 區段中,建立資料表的結構定義。

  5. [表格設定] 區段中,選擇 [自訂設定]

  6. 繼續前往 「加密設定」

    在此步驟中,您會為資料表選取加密設定。

    在 [選擇一個] 下的 [靜態加密] 區段中AWS KMS key,選擇 [選擇其他 KMS 金鑰 (進階)] 選項,然後在搜尋欄位中選擇AWS KMS key或輸入 Amazon 資源名稱 (ARN)。

    注意

    如果您選取的金鑰無法存取或遺失必要權限,請參閱AWS Key Management Service開發人員指南中的「疑難排解金鑰存取」。

  7. 選擇 Create (建立) 以建立加密資料表。

使用客戶受管金鑰建立新資料表以進行靜態加密 (CQL)

若要建立使用客戶受管金鑰進行靜態加密的新資料表,您可以利用下列範例所示的CREATE TABLE陳述式。請務必使用 ARN 取代金鑰 ARN,以取得授予 Amazon 金鑰 Keyspaces 許可的有效金鑰。

CREATE TABLE my_keyspace.my_table(id bigint, name text, place text STATIC, PRIMARY KEY(id, name)) WITH CUSTOM_PROPERTIES = { 'encryption_specification':{ 'encryption_type': 'CUSTOMER_MANAGED_KMS_KEY', 'kms_key_identifier':'arn:aws:kms:eu-west-1:5555555555555:key/11111111-1111-111-1111-111111111111' } };

如果您收到Invalid Request Exception,則需要確認客戶受管金鑰是否有效,而且 Amazon 金 Keyspaces 具有必要的許可。若要確認金鑰已正確設定,請參閱AWS Key Management Service開發人員指南中的金鑰存取疑難排解

步驟 4:更新現有資料表的加密金鑰

您也隨時可以使用 Amazon KMS 主控台或 CQL,變更AWS 擁有的金鑰和客戶受管金鑰之間的現有資料表加密金鑰。

使用新的客戶管理金鑰 (主控台) 更新現有資料表

  1. 登入AWS Management Console,並在 https://console.aws.amazon.com/keyspaces/home 開啟 Amazon 索 Keyspaces 主控台。

  2. 在導覽窗格中,選擇 Tables (資料表)。

  3. 選擇您要更新的資料表,然後選擇 [其他設定] 索引標籤。

  4. 在「靜態加密」區段中,選擇「管理加密」以編輯表格的加密設定。

    在 [選擇一個] 下方AWS KMS key,選擇 [選擇不同的 KMS 金鑰 (進階)] 選項,然後在搜尋欄位中選擇AWS KMS key或輸入 Amazon 資源名稱 (ARN)。

    注意

    如果您選取的金鑰無效,請參閱AWS Key Management Service開發人員指南中的金鑰存取疑難排解

    或者,您也可以選擇使AWS 擁有的金鑰用客戶受管金鑰加密的資料表。

  5. 選擇儲存變更以儲存對表格的變更。

更新用於現有資料表的加密金鑰

若要變更現有資料表的加密金鑰,您可以使用ALTER TABLE陳述式來指定用於靜態加密的客戶管理金鑰。請務必使用 ARN 取代金鑰 ARN,以取得授予 Amazon 金鑰 Keyspaces 許可的有效金鑰。

ALTER TABLE my_keyspace.my_table WITH CUSTOM_PROPERTIES = { 'encryption_specification':{ 'encryption_type': 'CUSTOMER_MANAGED_KMS_KEY', 'kms_key_identifier':'arn:aws:kms:eu-west-1:5555555555555:key/11111111-1111-111-1111-111111111111' } };

如果您收到Invalid Request Exception,則需要確認客戶受管金鑰是否有效,而且 Amazon 金 Keyspaces 具有必要的許可。若要確認金鑰已正確設定,請參閱AWS Key Management Service開發人員指南中的金鑰存取疑難排解

若要使用將加密金鑰變更回預設的靜態加密選項AWS 擁有的金鑰,您可以使用下列範例所示的ALTER TABLE陳述式。

ALTER TABLE my_keyspace.my_table WITH CUSTOM_PROPERTIES = { 'encryption_specification':{ 'encryption_type' : 'AWS_OWNED_KMS_KEY' } };

步驟 5:在日誌中使用 Amazon Keyspaces 加密內容

加密內容是一組金鑰/值對,其中包含任意非私密資料。在加密資料的請求中包含加密內容時,AWS KMS 會以密碼編譯方式將加密內容繫結至加密的資料。若要解密資料,您必須傳遞相同的加密內容。

Amazon Keyspaces 在所有密AWS KMS編譯操作中使用相同的加密內容。如果您使用客戶受管金鑰來保護您的 Amazon Keyspaces 資料表,您可以使用加密內容來識別客戶受管金鑰在稽核記錄和日誌中的使用情況。它也會以純文字顯示在日誌中,例如在AWS CloudTrailAmazon 日誌的 CloudWatch 日誌中。

在其請求中AWS KMS,Amazon Key space 會使用具有三個鍵值對的加密內容。

"encryptionContextSubset": { "aws:cassandra:keyspaceName": "my_keyspace", "aws:cassandra:tableName": "mytable" "aws:cassandra:subscriberId": "111122223333" }
  • 鍵空間 — 第一個鍵值對會識別包含 Amazon Keyspace 正在加密資料表的索引鍵空間。金鑰為 aws:cassandra:keyspaceName。值是索引鍵空間的名稱。

    "aws:cassandra:keyspaceName": "<keyspace-name>"

    例如:

    "aws:cassandra:keyspaceName": "my_keyspace"
  • 資料表 — 第二個鍵值對會識別 Amazon Keyspaces 正在加密的資料表。金鑰為 aws:cassandra:tableName。值是資料表的名稱。

    "aws:cassandra:tableName": "<table-name>"

    例如:

    "aws:cassandra:tableName": "my_table"
  • 帳戶 — 第三個鍵值對會識別AWS 帳戶。金鑰為 aws:cassandra:subscriberId。值是帳戶 ID。

    "aws:cassandra:subscriberId": "<account-id>"

    例如:

    "aws:cassandra:subscriberId": "111122223333"

步驟 6:使用設定監視AWS CloudTrail

如果您使用客戶受管金鑰來保護您的 Amazon Keyspaces space 資料表,您可以使用AWS CloudTrail日誌來追蹤 Amazon Keyspaces space 代表您傳送到AWS KMS的請求。

GenerateDataKeyDescribeKeyDecrypt、和CreateGrant請求將在本節中討論。此外,當您刪除資料表時,Amazon Keyspaces 會使用RetireGrant作業移除授權。

GenerateDataKey

Amazon 金 Keyspaces 會建立唯一的資料表金鑰,用來加密靜態資料表金鑰。它會傳送GenerateDataKey要求AWS KMS,以指定資料表的 KMS 金鑰。

記錄 GenerateDataKey 操作的事件類似於以下範例事件。使用者是 Amazon 索 Keyspaces 服務帳戶。參數包括客戶受管金鑰的 Amazon Resource Name (ARN)、需要 256 位元金鑰的金鑰規範,以及識別金鑰空間、資料表和的加密內容AWS 帳戶。

{ "eventVersion": "1.08", "userIdentity": { "type": "AWSService", "invokedBy": "AWS Internal" }, "eventTime": "2021-04-16T04:56:05Z", "eventSource": "kms.amazonaws.com", "eventName": "GenerateDataKey", "awsRegion": "us-east-1", "sourceIPAddress": "AWS Internal", "userAgent": "AWS Internal", "requestParameters": { "keySpec": "AES_256", "encryptionContext": { "aws:cassandra:keyspaceName": "my_keyspace", "aws:cassandra:tableName": "my_table", "aws:cassandra:subscriberId": "123SAMPLE012" }, "keyId": "arn:aws:kms:eu-west-1:5555555555555:key/11111111-1111-111-1111-111111111111" }, "responseElements": null, "requestID": "5e8e9cb5-9194-4334-aacc-9dd7d50fe246", "eventID": "49fccab9-2448-4b97-a89d-7d5c39318d6f", "readOnly": true, "resources": [ { "accountId": "123SAMPLE012", "type": "AWS::KMS::Key", "ARN": "arn:aws:kms:eu-west-1:5555555555555:key/11111111-1111-111-1111-111111111111" } ], "eventType": "AwsApiCall", "managementEvent": true, "eventCategory": "Management", "recipientAccountId": "123SAMPLE012", "sharedEventID": "84fbaaf0-9641-4e32-9147-57d2cb08792e" }
DescribeKey

Amazon 金 Keyspaces 會使用DescribeKey操作來判斷您選取的 KMS 金鑰是否存在於帳戶和區域內。

記錄 DescribeKey 操作的事件類似於以下範例事件。使用者是 Amazon 索 Keyspaces 服務帳戶。參數包括客戶受管金鑰的 ARN 以及需要 256 位元金鑰的金鑰規範。

{ "eventVersion": "1.08", "userIdentity": { "type": "IAMUser", "principalId": "AIDAZ3FNIIVIZZ6H7CFQG", "arn": "arn:aws:iam::123SAMPLE012:user/admin", "accountId": "123SAMPLE012", "accessKeyId": "AKIAIOSFODNN7EXAMPLE", "userName": "admin", "sessionContext": { "sessionIssuer": {}, "webIdFederationData": {}, "attributes": { "mfaAuthenticated": "false", "creationDate": "2021-04-16T04:55:42Z" } }, "invokedBy": "AWS Internal" }, "eventTime": "2021-04-16T04:55:58Z", "eventSource": "kms.amazonaws.com", "eventName": "DescribeKey", "awsRegion": "us-east-1", "sourceIPAddress": "AWS Internal", "userAgent": "AWS Internal", "requestParameters": { "keyId": "arn:aws:kms:eu-west-1:5555555555555:key/11111111-1111-111-1111-111111111111" }, "responseElements": null, "requestID": "c25a8105-050b-4f52-8358-6e872fb03a6c", "eventID": "0d96420e-707e-41b9-9118-56585a669658", "readOnly": true, "resources": [ { "accountId": "123SAMPLE012", "type": "AWS::KMS::Key", "ARN": "arn:aws:kms:eu-west-1:5555555555555:key/11111111-1111-111-1111-111111111111" } ], "eventType": "AwsApiCall", "managementEvent": true, "eventCategory": "Management", "recipientAccountId": "123SAMPLE012" }
解密

當您存取 Amazon Keyspaces 料表時,Amazon Keyspaces space 需要解密資料表金鑰,以便解密階層下方的金鑰。然後解密資料表中的資料。為了解密資料表金鑰,Amazon 金 Keyspaces 會傳送解密請求至AWS KMS,指定資料表的 KMS 金鑰。

記錄 Decrypt 操作的事件類似於以下範例事件。使用者是您 AWS 帳戶 中存取資料表的委託人。參數包括加密的資料表金鑰 (作為加密文字 Blob) 以及識別資料表和的加密內容AWS 帳戶。 AWS KMS從加密文字衍生客戶管理金鑰的 ID。

{ "eventVersion": "1.08", "userIdentity": { "type": "AWSService", "invokedBy": "AWS Internal" }, "eventTime": "2021-04-16T05:29:44Z", "eventSource": "kms.amazonaws.com", "eventName": "Decrypt", "awsRegion": "us-east-1", "sourceIPAddress": "AWS Internal", "userAgent": "AWS Internal", "requestParameters": { "encryptionContext": { "aws:cassandra:keyspaceName": "my_keyspace", "aws:cassandra:tableName": "my_table", "aws:cassandra:subscriberId": "123SAMPLE012" }, "encryptionAlgorithm": "SYMMETRIC_DEFAULT" }, "responseElements": null, "requestID": "50e80373-83c9-4034-8226-5439e1c9b259", "eventID": "8db9788f-04a5-4ae2-90c9-15c79c411b6b", "readOnly": true, "resources": [ { "accountId": "123SAMPLE012", "type": "AWS::KMS::Key", "ARN": "arn:aws:kms:eu-west-1:5555555555555:key/11111111-1111-111-1111-111111111111" } ], "eventType": "AwsApiCall", "managementEvent": true, "eventCategory": "Management", "recipientAccountId": "123SAMPLE012", "sharedEventID": "7ed99e2d-910a-4708-a4e3-0180d8dbb68e" }
CreateGrant

當您使用客戶受管金鑰來保護您的 Amazon Key角資料表時,Amazon Keyspaces 會使用授予來允許服務執行持續的資料保護以及維護和耐用性任務。上不需要這些贈款AWS 擁有的金鑰

Amazon Keyspaces 建立的授予專屬於特定資料表。CreateGrant請求中的主參與者是建立表格的使用者。

記錄 CreateGrant 操作的事件類似於以下範例事件。參數包括資料表客戶受管金鑰的 ARN、受受受受受管金鑰和淘汰委託人 (Amazon Keyspaces 服務),以及授予涵蓋的操作。它也包含要求所有加密作業都使用指定加密內容的條件約束。

{ "eventVersion": "1.08", "userIdentity": { "type": "IAMUser", "principalId": "AIDAZ3FNIIVIZZ6H7CFQG", "arn": "arn:aws:iam::arn:aws:kms:eu-west-1:5555555555555:key/11111111-1111-111-1111-111111111111:user/admin", "accountId": "arn:aws:kms:eu-west-1:5555555555555:key/11111111-1111-111-1111-111111111111", "accessKeyId": "AKIAI44QH8DHBEXAMPLE", "userName": "admin", "sessionContext": { "sessionIssuer": {}, "webIdFederationData": {}, "attributes": { "mfaAuthenticated": "false", "creationDate": "2021-04-16T04:55:42Z" } }, "invokedBy": "AWS Internal" }, "eventTime": "2021-04-16T05:11:10Z", "eventSource": "kms.amazonaws.com", "eventName": "CreateGrant", "awsRegion": "us-east-1", "sourceIPAddress": "AWS Internal", "userAgent": "AWS Internal", "requestParameters": { "keyId": "a7d328af-215e-4661-9a69-88c858909f20", "operations": [ "DescribeKey", "GenerateDataKey", "Decrypt", "Encrypt", "ReEncryptFrom", "ReEncryptTo", "RetireGrant" ], "constraints": { "encryptionContextSubset": { "aws:cassandra:keyspaceName": "my_keyspace", "aws:cassandra:tableName": "my_table", "aws:cassandra:subscriberId": "123SAMPLE012" } }, "retiringPrincipal": "cassandratest.us-east-1.amazonaws.com", "granteePrincipal": "cassandratest.us-east-1.amazonaws.com" }, "responseElements": { "grantId": "18e4235f1b07f289762a31a1886cb5efd225f069280d4f76cd83b9b9b5501013" }, "requestID": "b379a767-1f9b-48c3-b731-fb23e865e7f7", "eventID": "29ee1fd4-28f2-416f-a419-551910d20291", "readOnly": false, "resources": [ { "accountId": "123SAMPLE012", "type": "AWS::KMS::Key", "ARN": "arn:aws:kms:eu-west-1:5555555555555:key/11111111-1111-111-1111-111111111111" } ], "eventType": "AwsApiCall", "managementEvent": true, "eventCategory": "Management", "recipientAccountId": "123SAMPLE012" }