0Pricing
AWS Security Academy · Lesson

Key Policies, Grants, and Conditions

Control exactly who can use a key and under what context.

Key Policies, Grants, and Conditions is a free AWS Security Academy lesson on CoddyKit — lesson 3 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the AWS Security Academy learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.

Controlling Who Uses a Key

Creating a key is half the job; controlling who may use it is the other half. KMS uses several access mechanisms layered together.

The most important is the key policy, the resource-based policy attached directly to the key.

The Key Policy

Every KMS key has a key policy that is the primary authority over access.

  • Unlike most services, a KMS key must have a key policy.
  • If the key policy does not grant access, IAM policies alone cannot.

This makes the key policy the gatekeeper.

Key Policy and IAM Together

Access to a KMS key requires the key policy to enable IAM, then IAM and key policy combine.

The default key policy includes a statement giving the account's IAM principals access subject to their IAM policies. Without that statement, only principals named directly in the key policy can use the key.

{
  "Sid": "EnableIAM",
  "Effect": "Allow",
  "Principal": { "AWS": "arn:aws:iam::111122223333:root" },
  "Action": "kms:*",
  "Resource": "*"
}

Grants

A grant is a flexible, temporary way to delegate use of a key.

  • It allows specific operations to a principal, often programmatically.
  • AWS services use grants to access keys on your behalf.

Grants can be retired or revoked when no longer needed, ideal for short-lived delegation.

Grants vs Key Policy

Choose by lifetime and granularity:

  • Use the key policy and IAM for long-standing, broad access.
  • Use grants for fine-grained, temporary permissions, often created dynamically by services or apps.

Grants avoid editing the key policy for short-term needs.

Condition Keys

KMS supports powerful condition keys in policies, such as kms:ViaService.

ViaService restricts key use to requests coming through a specific AWS service (like only via S3), so a principal can decrypt only when S3 makes the call, not directly.

Encryption Context

Encryption context is a set of key-value pairs passed with encrypt/decrypt that is cryptographically bound to the operation.

  • The same context must be supplied to decrypt.
  • It appears in CloudTrail for auditing.

Policies can require a specific context with the kms:EncryptionContext condition.

Cross-Account Key Access

To let another account use a key, the key policy must allow that external account, and the external principal needs IAM permission too.

This is the same two-sided pattern as cross-account roles: the resource policy (here, the key policy) and the caller's IAM policy must both permit the action.

Least Privilege for Keys

Apply least privilege to keys:

  • Separate key administrators (manage the key) from key users (encrypt/decrypt).
  • Avoid kms:* for users.
  • Use ViaService and encryption context to tighten scope.

This limits blast radius if a principal is compromised.

The Default Key Policy Pitfall

A classic mistake is editing a key policy and removing the statement that enables IAM.

Without it, even account administrators lose access, and because the key policy is the gatekeeper, you can lock yourself out of the key entirely. Always keep an account-level administrative principal in the key policy to avoid an unrecoverable key.

Auditing Key Access

Combine CloudTrail (every KMS call with context) and IAM Access Analyzer (key policies granting external access) to audit who can and does use each key.

Regular review catches over-broad key policies before they become a risk.

Quick Check

Reason about KMS access.

Recap

You learned how KMS access is controlled.

  • The key policy is the primary gatekeeper and must enable IAM to use it.
  • Grants give temporary, fine-grained delegation.
  • Conditions like ViaService and encryption context tighten scope.

Frequently asked questions

Is the “Key Policies, Grants, and Conditions” lesson free?

Yes — the full text of “Key Policies, Grants, and Conditions” is free to read here on the web, and the AWS Security Academy course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the AWS Security Academy course, upgrade to CoddyKit PRO.

What will I learn in “Key Policies, Grants, and Conditions”?

Control exactly who can use a key and under what context. You practise AWS Security Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.

Do I need any experience to start AWS Security Academy?

No prior experience is required. AWS Security Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 3 of 4, so you can start here or from the beginning and move at your own pace.

How long does the “Key Policies, Grants, and Conditions” lesson take?

Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.

Can I write and run code in this AWS Security Academy lesson?

Yes. Every AWS Security Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.

All lessons in this course

  1. What KMS Keys Are and Do
  2. Symmetric, Asymmetric, and Multi-Region Keys
  3. Key Policies, Grants, and Conditions
  4. Envelope Encryption and Data Keys
← Back to AWS Security Academy