本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。
靜態加密
根據預設,Amazon Inspector 會使用 AWS 加密解決方案存放靜態資料。Amazon Inspector 會加密資料,如下所示:
-
使用 收集的資源庫存 AWS Systems Manager。
-
從 Amazon Elastic Container Registry 映像剖析的資源庫存
-
使用來自 的 AWS 擁有加密金鑰產生安全調查結果 AWS Key Management Service
您無法管理、使用或檢視 AWS 擁有的金鑰。不過,您不需要採取動作或變更程式來保護加密資料的金鑰。如需詳細資訊,請參閱 AWS 擁有的金鑰。
如果您停用 Amazon Inspector,它會永久刪除其為您存放或維護的所有資源,例如收集的庫存和安全性調查結果。
對問題清單中的程式碼進行靜態加密
對於 Amazon Inspector Lambda 程式碼掃描,Amazon Inspector 會與 Amazon Q 合作掃描您的程式碼是否有漏洞。偵測到漏洞時,Amazon Q 會擷取包含漏洞的程式碼片段,並存放該程式碼,直到 Amazon Inspector 請求存取為止。根據預設,Amazon Q 會使用 AWS 擁有的金鑰來加密擷取的程式碼。不過,您可以將 Amazon Inspector 設定為使用自己的客戶受管 AWS KMS 金鑰進行加密。
下列工作流程說明 Amazon Inspector 如何使用您設定的金鑰來加密程式碼:
-
您可以使用 Amazon Inspector UpdateEncryptionKey API 將 AWS KMS 金鑰提供給 Amazon Inspector。
-
Amazon Inspector 會將 AWS KMS 金鑰的相關資訊轉送至 Amazon Q,Amazon Q 會儲存資訊以供日後使用。
-
Amazon Q 透過金鑰政策使用您在 Amazon Inspector 中設定的 KMS 金鑰。
-
Amazon Q 會從金鑰建立加密的資料 AWS KMS 金鑰,並將其存放。此資料金鑰用於加密 Amazon Q 存放的程式碼資料。
-
當 Amazon Inspector 從程式碼掃描請求資料時,Amazon Q 會使用 KMS 金鑰來解密資料金鑰。當您停用 Lambda 程式碼掃描時,Amazon Q 會刪除相關聯的資料金鑰。
使用客戶受管金鑰進行程式碼加密的許可
對於加密,您必須建立 KMS 金鑰,其中包含允許 Amazon Inspector 和 Amazon Q 執行下列動作的陳述式的政策。
-
kms:Decrypt
-
kms:DescribeKey
-
kms:Encrypt
-
kms:GenerateDataKey
-
kms:GenerateDataKeyWithoutPlainText
政策聲明
您可以在建立 KMS 金鑰時使用下列政策陳述式。
注意
將 取代
為您的 12 位數 AWS 帳戶 ID。account-id
將 取代為您啟用 Amazon Inspector 和 Lambda 程式碼掃描 AWS 區域 的 。Region
將 取代為您的 IAM 角色的 Amazon Resource Name。role-ARN
{ "Effect": "Allow", "Principal": { "Service": "q.amazonaws.com" }, "Action": [ "kms:Encrypt", "kms:Decrypt", "kms:GenerateDataKeyWithoutPlaintext", "kms:GenerateDataKey" ], "Resource": "*", "Condition": { "StringLike": { "kms:EncryptionContext:aws:qdeveloper:lambda-codescan-scope": "
account-id
" }, "StringEquals": { "aws:SourceAccount": "account-id
" }, "ArnLike": { "aws:SourceArn": "arn:aws:qdeveloper:Region
:account-id
:scans/*" } } }, { "Effect": "Allow", "Principal": { "Service": "q.amazonaws.com" }, "Action": "kms:DescribeKey", "Resource": "*", "Condition": { "StringEquals": { "aws:SourceAccount": "account-id
" }, "ArnLike": { "aws:SourceArn": "arn:aws:qdeveloper:Region
:account-id
:scans/*" } } }, { "Effect": "Allow", "Action": [ "kms:Encrypt", "kms:Decrypt", "kms:GenerateDataKeyWithoutPlaintext", "kms:GenerateDataKey" ], "Principal": { "AWS": "role-ARN
" }, "Resource": "*", "Condition": { "StringEquals": { "kms:ViaService": "inspector2.Region
.amazonaws.com" }, "StringLike": { "kms:EncryptionContext:aws:qdeveloper:lambda-codescan-scope": "account-id
" } } }, { "Effect": "Allow", "Action": [ "kms:DescribeKey" ], "Principal": { "AWS": "role-ARN
" }, "Resource": "*", "Condition": { "StringEquals": { "kms:ViaService": "inspector2.Region
.amazonaws.com" } } }
政策陳述式的格式為 JSON。包含 陳述式之後,請檢閱政策以確保語法有效。如果陳述式是政策中的最後一個陳述式,請將逗號放在前一個陳述式的關閉架構之後。如果陳述式是政策中的第一個陳述式或在兩個現有陳述式之間,請在陳述式的關閉架構之後加上逗號。
注意
Amazon Inspector 不再支援授權來加密從套件擷取的程式碼片段。如果您使用以授予為基礎的政策,您仍然可以存取問題清單。不過,如果您更新或重設 KMS 金鑰或停用 Lambda 程式碼掃描,您將需要使用本節所述的 KMS 金鑰政策。
如果您設定、更新或重設帳戶的加密金鑰,您必須使用 Amazon Inspector 管理員政策,例如 AWS 受管政策AmazonInspector2FullAccess
。
使用客戶受管金鑰設定加密
若要使用客戶受管金鑰設定帳戶的加密,您必須是具有 中所述許可的 Amazon Inspector 管理員使用客戶受管金鑰進行程式碼加密的許可。此外,您將需要與 AWS 問題清單位於相同區域中的 AWS KMS 金鑰,或多區域金鑰。您可以使用帳戶中現有的對稱金鑰,或使用 AWS 管理主控台或 AWS KMS APIs 建立對稱客戶受管金鑰。如需詳細資訊,請參閱《 AWS KMS 使用者指南》中的建立對稱加密 AWS KMS 金鑰。
注意
自 2025 年 6 月 13 日起,在程式碼片段加密/解密期間在 CloudTrail 中記錄的 AWS KMS 請求中的服務主體將從「codeguru-reviewer」變更為「q」。
使用 Amazon Inspector API 設定加密
以 Amazon Inspector 管理員身分登入時,設定用於加密 Amazon Inspector API UpdateEncryptionKey 操作的金鑰。在 API 請求中,使用 kmsKeyId
欄位來指定您要使用的 AWS KMS 金鑰 ARN。針對 scanType
輸入 CODE
,針對 resourceType
輸入 AWS_LAMBDA_FUNCTION
。
您可以使用 UpdateEncryptionKey API 來檢查 Amazon Inspector 用於加密的 AWS KMS 金鑰檢視。
注意
如果您在尚未設定客戶受管金鑰GetEncryptionKey
時嘗試使用 , 操作會傳回ResourceNotFoundException
錯誤,這表示正在使用 AWS 擁有的金鑰進行加密。
如果您刪除金鑰或變更拒絕存取 Amazon Inspector 或 Amazon Q 的政策,您將無法存取程式碼漏洞問題清單,而且您帳戶的 Lambda 程式碼掃描將會失敗。
您可以使用 ResetEncryptionKey
來繼續使用 AWS 擁有的金鑰來加密擷取為 Amazon Inspector 調查結果一部分的程式碼。