[小ネタ] KMS の AWS マネージドキーは DescribeKey によって作成される話
DescribeKey - AWS Key Management Service
In general, DescribeKey is a non-mutating operation. It returns data about KMS keys, but doesn't change them. However, AWS services use DescribeKey to create AWS managed keys from a predefined AWS alias with no key ID.
上記仕様に関する話です。
試してみた
新規 AWS アカウントで S3 バケットを作成し、SSE-KMS による暗号化を指定してバケットの作成、オブジェクトのアップロードを行いました。
その結果、KSM にはエイリアス aws/s3 の AWS マネージドキーが自動的に作成されていました。
この時の記録を CloudTrail で確認したところ、aws/s3 の AWS マネージドキーが作成された時刻とほぼ同じ時刻に DescribeKey の記録がありました。
CloudTrail の DescribeKey の記録
{
"eventVersion": "1.11",
"userIdentity": {
"type": "AssumedRole",
"principalId": "xxx",
"arn": "xxx",
"accountId": "012345678901",
"accessKeyId": "xxx",
"sessionContext": {
"sessionIssuer": {
"type": "Role",
"principalId": "xxx",
"arn": "xxx",
"accountId": "012345678901",
"userName": "xxx"
},
"attributes": {
"creationDate": "2025-02-01T07:43:44Z",
"mfaAuthenticated": "true"
}
}
},
"eventTime": "2025-02-01T07:49:34Z",
"eventSource": "kms.amazonaws.com",
"eventName": "DescribeKey",
"awsRegion": "ap-northeast-1",
"sourceIPAddress": "xxx",
"userAgent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/132.0.0.0 Safari/537.36",
"requestParameters": {
"keyId": "xxx"
},
"responseElements": null,
"requestID": "2dfac2a9-2e72-4d1e-8969-5a53446f359c",
"eventID": "bab2293d-cdf3-43cc-a265-0a3936ec21f0",
"readOnly": true,
"resources": [
{
"accountId": "012345678901",
"type": "AWS::KMS::Key",
"ARN": "arn:aws:kms:ap-northeast-1:012345678901:key/xxx"
}
],
"eventType": "AwsApiCall",
"managementEvent": true,
"recipientAccountId": "012345678901",
"eventCategory": "Management",
"tlsDetails": {
"tlsVersion": "TLSv1.3",
"cipherSuite": "TLS_AES_256_GCM_SHA384",
"clientProvidedHostHeader": "kms.ap-northeast-1.amazonaws.com"
},
"sessionCredentialFromConsole": "true"
}
describe-key コマンドの結果
{
"KeyMetadata": {
"AWSAccountId": "012345678901",
"KeyId": "xxx",
"Arn": "arn:aws:kms:ap-northeast-1:012345678901:key/xxx",
"CreationDate": "2025-02-01T07:49:26.400000+00:00",
"Enabled": true,
"Description": "Default key that protects my S3 objects when no other key is defined",
"KeyUsage": "ENCRYPT_DECRYPT",
"KeyState": "Enabled",
"Origin": "AWS_KMS",
"KeyManager": "AWS",
"CustomerMasterKeySpec": "SYMMETRIC_DEFAULT",
"KeySpec": "SYMMETRIC_DEFAULT",
"EncryptionAlgorithms": [
"SYMMETRIC_DEFAULT"
],
"MultiRegion": false
}
}
- CloudTrail の DescribeKey の記録日時: 2025-02-01T07:49:34Z
- 日本時間で 2025-02-01 16:49:34
- describe-key コマンドの CreationDate: 2025-02-01T07:49:26.400000+00:00
- 日本時間で 2025-02-01 16:49:26
上記の通り、ほぼ同じ時刻に記録が残っていました。
おそらく以下の時系列であったと思われます。
- SSE-KMS の設定でバケット作成
- DescribeKey によって aws/s3 の AWS マネージドキーが作成される
- CloudTrail に DescribeKey が記録される
CreateKey について
CreateKey - AWS Key Management Service
Creates a unique customer managed KMS key in your AWS account and Region.
上記ドキュメントに記載の通り、CreateKey は CMK を作成するために使用される API です。
そのため、CreateKey で AWS マネージドキーを作成することはできません。
まとめ
今回は KMS の AWS マネージドキーは DescribeKey によって作成される話を紹介しました。
どなたかの参考になれば幸いです。
Discussion