IAM policy example: write a KMS key policy, with a least privilege rewrite
Facts read 16 Nov 2026. Page reviewed 16 Nov 2026.
A key policy with the two statements the AWS documentation describes: one gives the account root access so IAM policies can grant key use, and one lets a named role use the key for cryptographic actions. The rewrite narrows the key user to calls made through S3.
Open the workbench ยท All examples
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "EnableIamPolicies",
"Effect": "Allow",
"Principal": {
"AWS": "arn:aws:iam::111122223333:root"
},
"Action": "kms:*",
"Resource": "*"
},
{
"Sid": "KeyUsers",
"Effect": "Allow",
"Principal": {
"AWS": "arn:aws:iam::111122223333:role/app-role"
},
"Action": [
"kms:Encrypt",
"kms:Decrypt",
"kms:ReEncrypt*",
"kms:GenerateDataKey*",
"kms:DescribeKey"
],
"Resource": "*"
}
]
}
What it allows
- The first statement lets the account's IAM policies grant any KMS action on this key.
- The second statement lets the role app-role encrypt, decrypt, re-encrypt, generate data keys and describe the key.
What it allows
Allow 58 actions (kms:*) on every resource for AWS arn:aws:iam::111122223333:root.
Action or pattern Actions Access levels kms:*58 List 7, Read 7, Write 38, Permissions management 4, Tagging 2 Allow 9 actions (kms:Encrypt, kms:Decrypt, kms:ReEncrypt*, kms:GenerateDataKey*, kms:DescribeKey) on every resource for AWS arn:aws:iam::111122223333:role/app-role.
Action or pattern Actions Access levels kms:Encrypt1 Write 1 kms:Decrypt1 Write 1 kms:ReEncrypt*2 Write 2 kms:GenerateDataKey*4 Write 4 kms:DescribeKey1 Read 1
Checks
- High Allows 42 write or permissions-management actions (4 permissions management) on every resource ("Resource": "*"). AWS documentation for this check
- Medium Allows 8 write or permissions-management actions on every resource ("Resource": "*"). AWS documentation for this check
The root statement uses kms:*, which delegates 58 actions to IAM, and the user statement has no condition on the calling service.
Least privilege rewrite
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "EnableIamPolicies",
"Effect": "Allow",
"Principal": {
"AWS": "arn:aws:iam::111122223333:root"
},
"Action": "kms:*",
"Resource": "*"
},
{
"Sid": "KeyUsers",
"Effect": "Allow",
"Principal": {
"AWS": "arn:aws:iam::111122223333:role/app-role"
},
"Action": [
"kms:Encrypt",
"kms:Decrypt",
"kms:ReEncrypt*",
"kms:GenerateDataKey*",
"kms:DescribeKey"
],
"Resource": "*",
"Condition": {
"StringEquals": {
"kms:ViaService": "s3.us-east-1.amazonaws.com",
"kms:CallerAccount": "111122223333"
}
}
}
]
}
The rewrite keeps the root statement, which prevents lockout, and limits the key user to calls through S3 from account 111122223333.
What it allows
Allow 58 actions (kms:*) on every resource for AWS arn:aws:iam::111122223333:root.
Action or pattern Actions Access levels kms:*58 List 7, Read 7, Write 38, Permissions management 4, Tagging 2 Allow 9 actions (kms:Encrypt, kms:Decrypt, kms:ReEncrypt*, kms:GenerateDataKey*, kms:DescribeKey) on every resource for AWS arn:aws:iam::111122223333:role/app-role when kms:ViaService StringEquals s3.us-east-1.amazonaws.com and kms:CallerAccount StringEquals 111122223333.
Action or pattern Actions Access levels kms:Encrypt1 Write 1 kms:Decrypt1 Write 1 kms:ReEncrypt*2 Write 2 kms:GenerateDataKey*4 Write 4 kms:DescribeKey1 Read 1
Checks
- High Allows 42 write or permissions-management actions (4 permissions management) on every resource ("Resource": "*"). AWS documentation for this check
- Medium Allows 8 write or permissions-management actions on every resource ("Resource": "*"). AWS documentation for this check
Related pages
Sources
- AWS KMS Developer Guide: default key policy, read 16 Nov 2026
- AWS KMS Developer Guide: key policies, read 16 Nov 2026
- AWS Service Authorization Reference, programmatic access (fetched 16 Nov 2026), read 16 Nov 2026
Last reviewed 16 Nov 2026.