我想知道 Amazon Machine Image (AMI) 或快照是否已加密。如果已加密,則想知道它是使用 AWS Key Management Service (KMS) 受管金鑰還是客戶受管金鑰。
解決方法
注意:
- 如果您在執行 AWS Command Line Interface (AWS CLI) 命令時收到錯誤,請確定您使用的是最新的 AWS CLI 版本。
- JSON 是預設 AWS CLI 輸出。您可以使用預設格式,或將 --output json 附加至命令,以接收類似下列範例輸出的輸出。如需詳細資訊,請參閱選取輸出格式。
使用 AWS CLI 命令檢視加密資訊
1. 若要檢視與 AMI 相關聯的快照,請使用 BlockDeviceMappings 查詢篩選條件執行 describe-images 命令。在下列範例中,將 image-ids 和 region 取代為您的 AMI 的 ID 和 AWS 區域。
# aws ec2 describe - images--image - ids ami - xxxxxxxxx--region eu - west - 1--query "Images[*].BlockDeviceMappings" [
[{
"DeviceName": "/dev/xvda",
"Ebs": {
"DeleteOnTermination": true,
"SnapshotId": "snap-xxxxxxxxx",
"VolumeSize": 8,
"VolumeType": "gp2",
"Encrypted": true
}
}]
]
上述範例輸出會顯示與 AMI 相關聯的快照。快照的 Encrypted 參數設定為 true。
2. 執行 describe-snapshots 命令。使用 describe-images 命令輸出中所列快照的 snapshot-id:
# aws ec2 describe - snapshots--snapshot - ids snap - xxxxxxxxx--region eu - west - 1 {
"Snapshots": [{
"Description": "Copied for DestinationAmi ami-xxxxxxxxx from SourceAmi ami-xxxxxxxxx for SourceSnapshot snap-xxxxxxxxx. Task created on 1,579,611,950,318.",
"Encrypted": true,
"KmsKeyId": "arn:aws:kms:eu-west-1:9208xxxxxxxxx:key/dcd4d062-xxxxxxxxx-xxxxxxxxxx",
"OwnerId": "111122223333",
"Progress": "100%",
"SnapshotId": "snap-xxxxxxxxx",
"StartTime": "2020-01-21T13:05:53.887Z",
"State": "completed",
"VolumeId": "vol-ffffffff",
"VolumeSize": 8
}]
}
在命令輸出中,記下 KMSKeyId。
3. 若要判斷金鑰是 AWS KMS 金鑰還是客戶受管金鑰,請執行 describe-key 命令。在下列命令中,將 key-id 取代為 describe-snapshot 命令中列出的 KMSKeyId。將 region 取代為快照的區域。
# aws kms describe - key--key - id dcd4d062 - xxxxxxxxx - xxxxxxxxx--region eu - west - 1 {
"KeyMetadata": {
"AWSAccountId": "92xxxxxxxxx",
"KeyId": "dcd4d062-xxxxxxxxx-xxxxxxxx",
"Arn": "arn:aws:kms:eu-west-1:92xxxxxxxxx:key/dcd4d062-xxxxxxxxx-xxxxxxx",
"CreationDate": 1579611763.538,
"Enabled": true,
"Description": "02-example-CMK",
"KeyUsage": "ENCRYPT_DECRYPT",
"KeyState": "Enabled",
"Origin": "AWS_KMS",
"KeyManager": "CUSTOMER",
"CustomerMasterKeySpec": "SYMMETRIC_DEFAULT",
"EncryptionAlgorithms": ["SYMMETRIC_DEFAULT"]
}
}
在上述範例輸出中,KeyManager 參數為 Customer。這表示此金鑰是客戶受管金鑰。針對 AWS KMS 金鑰,KeyManager 參數為 AWS。
使用主控台檢視加密資訊
- 開啟 Amazon Elastic Compute Cloud (Amazon EC2) 主控台,然後選擇 AMI。
- 複製您想要其詳細資訊的 AMI 的 ID。
- 在 Elastic Block Store 下,選擇快照。
- 輸入 AMI ID,然後按下 ENTER 鍵。
- 選取快照,然後在說明索引標籤上驗證加密是設定為已加密還是未加密。如果快照已加密,請記下 KMS 金鑰 ID 和 KMS 金鑰 ARN。
- 開啟 AWS KMS 主控台。
- 選擇 AWS 受管金鑰,然後輸入 KMS 金鑰 ID。如果沒有顯示任何結果,請選擇客戶受管金鑰,然後輸入 KMS 金鑰 ID。
**注意:**您無法共用使用 AWS 受管金鑰加密的 AMI。如需詳細資訊,請參閱共用快照之前。
相關資訊
AWS KMS 概念