I can't seem to use the "kms:CallerAccount"
condition in a KMS customer managed key used for encrypting existing CloudWatch log groups.
I followed the official docs and created a symmetric KMS key with the following policy which allows the key to be used with any log group (account ID redacted):
{
"Version": "2012-10-17",
"Id": "key-default-1",
"Statement": [
{
"Sid": "Enable IAM User Permissions",
"Effect": "Allow",
"Principal": {
"AWS": "arn:aws:iam::xxx:root"
},
"Action": "kms:*",
"Resource": "*"
},
{
"Effect": "Allow",
"Principal": {
"Service": "logs.eu-central-1.amazonaws.com"
},
"Action": [
"kms:Encrypt*",
"kms:Decrypt*",
"kms:ReEncrypt*",
"kms:GenerateDataKey*",
"kms:Describe*"
],
"Resource": "*",
"Condition": {
"ArnEquals": {
"kms:EncryptionContext:aws:logs:arn": "arn:aws:logs:eu-central-1:xxx:*"
},
"StringEquals": {
"kms:CallerAccount": "xxx"
}
}
}
]
}
The only difference between the policy from the docs and my policy is that my policy has the "kms:CallerAccount"
condition:
"StringEquals": {
"kms:CallerAccount": "xxx"
}
I get the following error when I try to associate my key with the log group /aws/batch/job
:
❯ aws logs associate-kms-key --log-group-name /aws/batch/job --kms-key-id arn:aws:kms:eu-central-1:xxx:key/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
An error occurred (AccessDeniedException) when calling the AssociateKmsKey operation: The specified KMS key does not exist or is not allowed to be used with LogGroup 'arn:aws:logs:eu-central-1:xxx:log-group:/aws/batch/job'
I can associate the key with the log group without errors when I remove the "kms:CallerAccount" condition from the key's policy.
How do I include the "kms:CallerAccount"
condition in a customer managed key used for encrypting CloudWatch log groups?