Suppose I have a bucket that is encrypted with a KMS key, the KMS key policy is like so
{
"Effect" : "Allow",
"Principal" : {
"AWS" : "arn:aws:iam:::my_role_here"
},
"Action" : [
"kms:Encrypt",
"kms:Decrypt",
"kms:ReEncrypt*",
"kms:GenerateDataKey*",
"kms:DescribeKey"
],
"Resource" : "arn:aws:kms:::long_kms_id",
"Condition": {
"StringLike": {
"kms:RequestAlias": "alias/my_kms_alias"
}
}
}
And the policy for my IAM role is
{
"Sid": "AllowUseOfKmsKey",
"Effect": "Allow",
"Action": [
"kms:Decrypt",
"kms:DescribeKey",
"kms:Encrypt",
"kms:GenerateDataKey*",
"kms:ReEncrypt*"
],
"Resource": "*",
"Condition": {
"StringLike": {
"kms:RequestAlias": "alias/my_kms_alias"
}
}
}
However when I do a PUT operation, I get an access denied: An error occurred (AccessDenied) when calling the PutObject operation: Access Denied
. However this works if I remove the Condition
on the IAM role policy.
I've ben following this doc, but nothing seems to work or explained clearly. How do I ensure that the role that I want to access my S3 bucket is able to access it if I gave it a KMS alias?