Skip to Content
Asterrr's Handbook
5 · Data protection

KMS key policy, IAM and grants

How KMS authorizes a request. Key policy, IAM policy and grants, the root principal statement, condition keys and encryption context.

Exam tasks: 5.2.1 (choose KMS and server- or client-side encryption), 5.3.5 (create and manage KMS keys across one or many Regions)

The decision: who is allowed to use and administer this key, and through which service?

Every KMS key has exactly one key policy. It is the only policy that is always required. IAM policies and grants work only on top of it.

listed directlyif account trustedas granteePrincipalKey policyIAM policyGrantKMS key
Three ways to authorize a principal on one KMS key. Only the key policy is mandatory. IAM works only if the key policy delegates to the account. Grants can only allow.

Key policy vs IAM policy vs grant

Key policyIAM policyGrant
RequiredYes, one per keyNoNo
Works aloneYesOnly if the key policy allows the account or the principalYes
Can denyYesYesNo, allow only
ScopeOne keyMany keys, by ARNOne key
Typical useBaseline: admins, users, cross-accountDay-to-day delegation inside the accountTemporary or programmatic access, AWS services
RevokeEdit policyEdit policyRetireGrant or RevokeGrant
  • A key policy does not trust the account by default. The statement "Principal": {"AWS": "arn:aws:iam::<acct>:root"} with kms:* is what lets IAM policies work. The root there means the account and its IAM principals, not the root user alone.
  • The default console key policy adds key administrators (manage, no crypto use) and key users (crypto use plus grants for AWS resources). Administrators can still change the key policy or create grants, so they can grant themselves use.
  • An explicit deny in any policy wins.
{
  "Sid": "LetAccountIamDecide",
  "Effect": "Allow",
  "Principal": { "AWS": "arn:aws:iam::444455556666:root" },
  "Action": "kms:*",
  "Resource": "*"
}
  • The statement above does not grant access to everyone in the account. It lets IAM policies in that account grant access. Remove it and only principals named in the key policy can use the key.
  • Split duties in the policy. Key administrators get kms:Create*, kms:Put*, kms:ScheduleKeyDeletion and kms:EnableKeyRotation. Key users get kms:Encrypt, kms:Decrypt, kms:GenerateDataKey* and kms:ReEncrypt*. Administrators usually should not be able to decrypt.
  • The policy lockout safety check refuses a policy that would stop the caller from managing the key. If you bypass it and lock yourself out, only AWS Support can help, and only if the account root still has access.
  • IAM Access Analyzer reports key policies that grant access outside your organization.

Grants

  • Created with CreateGrant, which returns a grant token and a grant ID. A grant has a grantee, an optional retiring principal, an operation list and optional constraints.
  • A grant is eventually consistent. Pass the grant token to use it immediately.
  • Constraints narrow a grant by encryption context or by SourceArn.
  • Limit is 50,000 grants per key.
  • AWS services such as EBS and Redshift create grants for you. The key user needs kms:CreateGrant with kms:GrantIsForAWSResource true.
  • The retiring principal calls RetireGrant. A key administrator calls RevokeGrant.
  • Services use grants behind the scenes. EBS creates one when a volume attaches, RDS when an instance is created, and Secrets Manager and Lambda for their own use.
  • ListGrants shows who holds grants. Check it after a compromise, because a grant can outlive a deleted IAM policy.

Cross-account use

  1. The key policy in the key account allows the external account or principal.
  2. An IAM policy in the external account allows the KMS actions on the key ARN.
  3. The caller uses the key ARN or alias ARN, never a bare alias name.

The other account cannot see the key in its console and cannot manage it. A common pattern is a central security account that owns customer managed keys per data domain, while workload accounts get use-only permissions combined with kms:ViaService.

Useful condition keys

ConditionWhat it restrictsExample use
kms:ViaServiceOnly requests that arrive through a named serviceThe analytics role can decrypt only via s3.eu-west-1.amazonaws.com, never by calling KMS directly
kms:EncryptionContext:<key>Only requests with a specific context valueTenant acme can decrypt only data encrypted with tenant=acme
kms:EncryptionContextKeysWhich context keys must be presentRequire that every call carries a project key
kms:CallerAccountWhich account's principalsAllow all principals in one account, used with kms:ViaService for AWS managed-style keys
kms:GrantIsForAWSResourceGrants only when an integrated service creates themLet EBS or RDS create grants for your role without letting the role hand out grants itself
kms:RotationPeriodInDaysAllowed rotation period valuesForce a 180-day rotation period across the organization
kms:RequestAlias, kms:ResourceAliasesAccess based on aliasesABAC: roles may use any key aliased alias/finance-*

ViaService and the direct call

A role that can call kms:Decrypt directly can pull the data key for any ciphertext it holds, bypassing the bucket policy. When the requirement is "only through S3" or "only through Secrets Manager", add kms:ViaService. An IAM policy that only restricts s3:* leaves the KMS path open.

Encryption context

  • Optional non-secret name-value pairs bound to the ciphertext as additional authenticated data. Symmetric keys only.
  • Decrypt must supply an exact, case-sensitive match or it fails with InvalidCiphertextException.
  • Appears in plaintext in CloudTrail. Never put secrets in it.
  • Use it for policy conditions and to stop ciphertext being replayed in the wrong place (confused deputy).
  • Key policies and grants can condition on it.

Exam signal

"Grant temporary access programmatically and revoke it later" means grants. "Key only usable from S3 in one Region" means kms:ViaService. "Prevent an administrator from decrypting" means separate administrator and user statements.

Exam trap

An IAM policy that allows kms:Decrypt does nothing if the key policy lacks the account root statement and does not name the principal. Giving a key a policy that names one deleted user can leave it unmanageable.

Scenarios

Scenario
A healthcare analytics company stores patient extracts in an S3 bucket encrypted with a customer managed KMS key. A data engineering role needs to read the extracts through Amazon Athena. The security team is worried that the role could call the KMS Decrypt API directly on data keys it copies out of object metadata. What is the MOST effective control?

Further reading

On this page