Skip to content

Lesson 9 of 13 · 20m

KMS key policies: who can actually decrypt

The required resource policy every key carries, envelope encryption, service grants, and the conditions that scope Decrypt.

Every KMS key carries its own resource policy — a fourth flavor of IAM policy, and the only AWS service where the resource policy is required. There is no such thing as a KMS key without a key policy. And the statement nearly every key ships with is the one engineers misread:

{
  "Sid": "Enable IAM User Permissions",
  "Effect": "Allow",
  "Principal": { "AWS": "arn:aws:iam::123456789012:root" },
  "Action": "kms:*",
  "Resource": "*"
}

The mental model that breaks

That statement does not grant anyone anything. It delegates: it tells KMS "the account's own IAM policies may grant access to this key." Delete it and IAM policies lose all effect on the key — access can then be granted only inside the key policy itself, which is a real pattern for high-value keys (the security team owns the key policy; nobody can self-grant via IAM). Leave it in and a developer with kms:* in an identity policy effectively has the key. Which reading is correct decides whether your encryption is a control or a comfort blanket.

How the crypto actually works

KMS never exposes the plaintext key. GenerateDataKey returns both a plaintext data key and its ciphertext blob; your app encrypts locally with the plaintext half, stores or attaches the blob, and discards the plaintext. Decryption reverses it: Decrypt hands back the data key only if the caller's principal holds kms:Decrypt on that key — via the key policy, or via IAM if the key policy delegates. Encrypt, Decrypt, ReEncrypt, GenerateDataKey, and DescribeKey are separate permissions; read s3:GetObject plus kms:Decrypt on Resource: "*" and a stolen credential reads every SSE-KMS object it can reach.

Grants: how AWS services get in

EBS, RDS, and S3 SSE-KMS do not assume your role. They use grants — scoped delegations the service creates on the fly. The key policy permits kms:CreateGrant for the service (usually constrained with kms:ViaService and kms:CallerAccount), and the service creates a grant limited to specific operations for a specific grantee principal. That is why a key policy for EBS encryption names ec2.us-east-1.amazonaws.com in a ViaService condition: the grant path is the only door, and it only opens from inside that service in that region. EBS reaches KMS through the EC2 endpoint — there is no ebs. service prefix.

Cross-account sharing uses the same delegation shape: put the account ARN in the key policy (Principal: {"AWS": "arn:aws:iam::222233334444:root"}), which lets that account's own IAM policies grant access. Two hops — key policy delegates to the account, IAM grants to the principal — is the correct shape. "Principal": "*" in a key policy is the incorrect shape: KMS requests are authenticated, so * means any AWS principal anywhere, and the "key open to the world" bug has shipped more than once.

The conditions that earn their keep

  • kms:ViaService — force the call through a named AWS service in a named region (s3.us-east-1.amazonaws.com). Kills the "decrypt from my laptop" path even when kms:Decrypt is granted.
  • kms:EncryptionContext: — encryption context is free additional authenticated data. Encrypt with {"tenant": "acme"} and the ciphertext is bound to that context; Decrypt must present it. In IAM, "kms:EncryptionContext:tenant": "acme" scopes decrypt to one tenant — poor-man's data segregation on a shared key.
  • kms:CallerAccount, kms:GrantOperations — the plumbing behind the grant path above.

The attack surface nobody audits

kms:PutKeyPolicy rewrites who can use the key — a takeover path as real as AttachUserPolicy. kms:ScheduleKeyDeletion is sabotage with a mandatory 7–30 day waiting window: deny it broadly and alarm on it. kms:DisableKey is the quiet version. Every Decrypt is a data event in CloudTrail — enable them for keys that protect regulated data, because key-use logs are how you prove who read what.

Customer-managed keys versus AWS-managed keys (aws/s3, aws/ebs, ...): AWS-managed keys are free and transparent, but their key policies are not editable — no scoping, no conditions, no cross-account grants, and limited visibility. Customer-managed keys cost ~$1/month and buy you the policy, rotation control, and full CloudTrail on use. For anything regulated, that is the trade worth making. Enable automatic rotation (yearly, keeps old material so old ciphertext still decrypts) as a checkbox that costs nothing.

Exercise

Create a customer-managed key. Inspect the default key policy and find the delegation statement. Attach an identity policy granting kms:Decrypt to a test role — works. Remove the delegation statement from the key policy — the same call now fails. Restore it, add a kms:ViaService condition, and prove that direct aws kms decrypt from the CLI dies while decrypts through S3 still work.

Field notes

  • Deleting key material destroys the data it protects permanently. The 7-day minimum ScheduleKeyDeletion window exists because people have done it by accident; prefer DisableKey plus monitoring.
  • Multi-Region keys replicate key material across regions with a shared key ID — the right answer for DR-encrypted data, and a larger blast radius to govern accordingly.
  • kms:Decrypt appearing where the code path should only encrypt (or vice versa) is a finding. Split the permissions to match the data flow.

Was this lesson helpful?

Sign in to rate

Keep reading

Related articles from the SudoSecurity blog.