Description
Separate who may use a KMS key from who can administer it. In its key policy, Resource: "*" means this key. Creating a key without a policy applies a default that lets the owning account delegate access through IAM.
Potential impact
Unnecessary decryption rights can expose data. Excessive disable or policy-change rights, or loss of necessary administration rights, can interrupt access and recovery.
Remediation
Grant users only the cryptographic operations they need. Review the key policy, applicable service conditions, IAM policies and KMS grants together. Preserve the ability of authorized administrators and deployment identities to update the key policy. Test required encryption and decryption, and confirm unwanted requests are denied.
Examples
Replace the account ID and CMKUser ARN with approved values. Limit the permissions delegated through the owning account’s IAM policies as well.
Before
resource "aws_kms_key" "kms_key" {
description = "KMS key 1"
deletion_window_in_days = 10
policy = <<POLICY
{
"Version": "2012-10-17",
"Statement":[
{
"Effect":"Allow",
"Principal": {"AWS":"*"},
"Action":["kms:*"],
"Resource":"*"
}
]
}
POLICY
}
The first policy grants kms:* to a wildcard principal.
After
resource "aws_kms_key" "kms_key" {
description = "KMS key 1"
deletion_window_in_days = 10
policy = <<POLICY
{
"Version": "2012-10-17",
"Statement":[
{
"Sid": "EnableAccountIAMPermissions",
"Effect": "Allow",
"Principal": {"AWS": "arn:aws:iam::111122223333:root"},
"Action": "kms:*",
"Resource": "*"
},
{
"Effect":"Allow",
"Principal": {"AWS": [
"arn:aws:iam::111122223333:user/CMKUser"
]},
"Action": [
"kms:Encrypt",
"kms:Decrypt",
"kms:ReEncrypt*",
"kms:GenerateDataKey*",
"kms:DescribeKey"
],
"Resource":"*"
}
]
}
POLICY
}
The second retains account delegation and directly grants the listed key-use operations to the named user. Remove operations that user does not need.