I am using the Key Management service (KMS) in AWS and am currently setting up key policies.
I created two roles KmsUser and KmsAdmin and attached the following key policy to my CMK:
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "KMS KeyAdmin access",
"Effect": "Allow",
"Principal": {"AWS": [
"arn:aws:iam::1234567890:role/KmsAdmin",
"arn:aws:iam::1234567890:user/myadmin"
]},
"Action": [
"kms:Create*",
"kms:Describe*",
"kms:Enable*",
"kms:List*",
"kms:Put*",
"kms:Update*",
"kms:Revoke*",
"kms:Disable*",
"kms:Get*",
"kms:Delete*",
"kms:TagResource",
"kms:UntagResource",
"kms:ScheduleKeyDeletion",
"kms:CancelKeyDeletion"
],
"Resource": "*"
},
{
"Sid": "KMS KeyUser access",
"Effect": "Allow",
"Principal": {"AWS": [
"arn:aws:iam::1234567890:role/KmsUser"
]},
"Action": [
"kms:Encrypt",
"kms:Decrypt",
"kms:ReEncrypt*",
"kms:GenerateDataKey*",
"kms:DescribeKey"
],
"Resource": "*"
}
]
}
The problem is that now if I try to use my key as the myadmin user (which has the AdministratorAccess policy attached) I get an error in the CLI:
$ aws kms encrypt --key-id "alias/test-key" --plaintext fileb:///tmp/plaintext.dat
An error occurred (AccessDeniedException) when calling the Encrypt operation: User: arn:aws:iam::1234567890:user/myadmin is not authorized to perform: kms:Encrypt on resource: arn:aws:kms:eu-north-1:1234567890:key/99999999-9999-9999-9999-99999999999
What is especially strange, is that the IAM policy simulator tells me that everything should work as expected:
If I manually add the myadmin user as a pricipal to the Key User policy, everything works fine.