Lesson 2 of 4 Data Classification and Encryption at Rest

Configuring AWS KMS Keys and Key Policies

This lesson explains how AWS Key Management Service (AWS KMS) creates and controls the keys that most AWS services use to encrypt data at rest, and how to configure key types and key policies correctly.

Learning outcomes

After completing this lesson, you will be able to:

  • Distinguish AWS owned, AWS managed and customer managed keys.
  • Control access with key policies, IAM policies and grants.
  • Explain envelope encryption and key rotation.
  • Share a key across accounts.

Key types

KMS keys come in three ownership types. AWS owned keys are used by services on your behalf, are invisible to you and free. AWS managed keys, with aliases such as aws/s3, aws/ebs and aws/rds, are created in your account by a service; you can see their use in CloudTrail, but you cannot change their key policies, rotate them on demand, or share them with other accounts, and they rotate automatically every year. Customer managed keys are created and controlled by you: you write the key policy, add grants, enable automatic rotation (every 90 to 2,560 days, default 365) or rotate on demand, disable and schedule deletion, and share across accounts. Keys are Regional; multi-Region keys share key material across Regions so data encrypted in one Region can be decrypted in another, which simplifies DR.

CapabilityAWS ownedAWS managedCustomer managed
Visible in your accountNoYesYes
Edit key policyNoNoYes
Cross-account useNoNoYes
RotationAWS controlledYearly, automaticOptional automatic (90-2,560 days) and on demand
CostFreePer useMonthly fee plus per use

90–2,560days

Range of the automatic rotation period

365days

Default automatic rotation period

Sort into groups

Which KMS key type?

Exam skills 4.2.2

Decide which kind of KMS key each statement describes.

Log in to try this activity Interactive activities are free with an account.

Key policies, IAM policies and grants

Every KMS key has a key policy, the primary access control. The default key policy contains a statement allowing the account root principal (arn:aws:iam::<account>:root) full access, which enables IAM policies in that account to grant permissions to the key; without it, only principals named in the key policy can use the key. Other statements name key administrators and key users. Grants give temporary, delegated permissions, and AWS services such as EBS and RDS create grants automatically when they use a customer managed key. The kms:ViaService condition limits a key's use to requests made through specific services, and encryption context conditions bind use to specific resources.

{
  "Sid": "AllowUseThroughEBSInThisAccount",
  "Effect": "Allow",
  "Principal": {"AWS": "arn:aws:iam::111122223333:role/AppServers"},
  "Action": ["kms:Encrypt", "kms:Decrypt", "kms:ReEncrypt*", "kms:GenerateDataKey*", "kms:CreateGrant", "kms:DescribeKey"],
  "Resource": "*",
  "Condition": {"StringEquals": {"kms:ViaService": "ec2.eu-west-1.amazonaws.com", "kms:CallerAccount": "111122223333"}}
}

The following diagram shows what the root statement changes.

How the key policy and IAM policies combine. The default key policy's statement for the account root principal lets IAM policies in the account grant use of the key. Without it, only principals named in the key policy can use the key. Grants give temporary, delegated permissions, which services such as EBS and RDS create.
The account ID is illustrative.

Envelope encryption and key lifecycle

Services use envelope encryption: KMS generates a data key, the service encrypts data with the plaintext data key and stores the data key encrypted under the KMS key. Rotation creates new key material for new encryptions while keeping old material for decryption, so rotation never requires re-encrypting data. Disabling a key makes all data encrypted under it unusable until it is re-enabled. Scheduling deletion starts a waiting period of 7 to 30 days during which the key is unusable and deletion can be cancelled; after deletion, data encrypted under the key is unrecoverable. A CloudWatch alarm on CloudTrail events for ScheduleKeyDeletion or on attempts to use a key pending deletion warns before data is lost.

7–30days

Waiting period before a scheduled key deletion completes

Put in order

Envelope encryption

Exam skills 4.2.2

Put the steps of envelope encryption in order.

Log in to try this activity Interactive activities are free with an account.
Worked example

Sharing a key across accounts

A central backup account must be able to copy encrypted RDS snapshots from workload accounts. Snapshots encrypted with aws/rds cannot be shared. The workload accounts create a customer managed key whose key policy grants the backup account kms:Decrypt, kms:DescribeKey and kms:CreateGrant, configure RDS to use it, and share snapshots with the backup account. In the backup account, an IAM policy also allows the copying role to use the workload key, and the copy re-encrypts the snapshot with the backup account's own key.

Check yourself

Does rotating a KMS key require data to be re-encrypted?

Show answer

No. KMS keeps earlier key material to decrypt existing data.

Exam Tips

Remember for the exam

  • AWS managed keys cannot be shared across accounts or have their policies changed.
  • The key policy's root principal statement enables IAM policies to grant key access.
  • Customer managed keys support configurable and on-demand rotation; rotation needs no re-encryption.
  • Disabling a key makes its data unusable; deletion waits 7-30 days and can be cancelled.
  • Multi-Region keys let data encrypted in one Region be decrypted in another.