AWS KMS Key Policies and Grants
You'll learn how to control access to AWS KMS keys using key policies, IAM permissions, and temporary grants.
Understanding KMS Access Control
AWS KMS uses a layered access control model. Unlike most AWS services where IAM is primary, KMS keys always require a key policy—even if IAM permissions exist, the key policy must explicitly allow that access. Think of the key policy as the bouncer at the door: even if someone has an invitation (IAM permissions), the bouncer (key policy) must let them in.
Key Policies: The Primary Control
A key policy is a JSON document attached directly to a KMS key. It defines who can use and manage the key. Every KMS key must have exactly one key policy, which is the primary determinant of access.
{
"Version": "2012-10-17",
"Statement": [{
"Sid": "Enable IAM User Permissions",
"Effect": "Allow",
"Principal": {
"AWS": "arn:aws:iam::123456789012:root"
},
"Action": "kms:*",
"Resource": "*"
}]
}
This default policy enables IAM policies in your account to work alongside the key policy.
IAM Permissions: The Secondary Layer
Once the key policy permits your account, IAM policies can grant specific users or roles KMS actions like kms:Encrypt, kms:Decrypt, or kms:GenerateDataKey.
Grants: Temporary Delegated Access
Grants provide programmatic, temporary access without modifying the key policy. They're ideal for granting short-lived permissions to services or applications. Use CreateGrant API to establish them, and they automatically expire or can be revoked.
Grants are commonly used when services like EBS or RDS need to encrypt/decrypt data on your behalf using your KMS keys.
Key Takeaway: AWS KMS requires both a key policy (primary gatekeeper) and optional IAM permissions (secondary layer) for access control, while grants provide temporary, programmatic delegation without policy modification.