Description
In a KMS key policy, Principal and Action define who can do what. Resource: "*" refers to the key the policy is attached to. Check IAM policies and KMS grants when determining effective access.
Potential impact
Unnecessary decryption rights can expose data. Removing the last administrator’s permission to change the policy can leave the key unmanageable.
Remediation
Separate key users from administrators and allow each only the operations they need. Preserve required existing statements and the deployment identity’s ability to call kms:PutKeyPolicy. Keep the lockout safety check enabled. After applying, test required service, administration and recovery operations, and check that unwanted requests are denied.
Examples
An API-created key with no explicit policy lets the owning account delegate access through IAM. For an existing key, omitting the policy in amazon.aws 11.4.0 preserves the current policy. Replace my-kms-key with the actual alias.
Before
- name: Update IAM policy on an existing KMS key
amazon.aws.kms_key:
alias: my-kms-key
policy:
Version: "2012-10-17"
Id: auto-ebs-2
Statement:
- Action:
- "kms:*"
Effect: Allow
Principal:
AWS: "*"
Resource: "*"
Sid: Allow access through EBS for all principals
state: present
The first policy grants kms:* to a wildcard principal.
After
- name: Update IAM policy on an existing KMS key
amazon.aws.kms_key:
alias: my-kms-key
policy: |
{
"Id": "auto-ebs-2",
"Statement": [
{
"Sid": "EnableIAMUserPermissions",
"Effect": "Allow",
"Principal": {"AWS": "arn:aws:iam::{{ key_account_id }}:root"},
"Action": "kms:*",
"Resource": "*"
},
{
"Action": [
"kms:Encrypt",
"kms:Decrypt",
"kms:ReEncrypt*",
"kms:GenerateDataKey*",
"kms:CreateGrant",
"kms:DescribeKey"
],
"Condition": {
"StringEquals": {
"kms:CallerAccount": "{{ key_account_id }}",
"kms:ViaService": "ec2.{{ aws_region }}.amazonaws.com"
}
},
"Effect": "Allow",
"Principal": {
"AWS": "*"
},
"Resource": "*",
"Sid": "Allow controlled access through EBS"
}
],
"Version": "2012-10-17"
}
state: present
The second preserves the owning account’s IAM delegation. Its EBS statement limits requests to kms:CallerAccount and the regional EC2 service in kms:ViaService. Supply the actual key_account_id and aws_region and test that service path.