Sub topic 11
Rotating keys
This chapter assumes you can create a customer managed key and an alias, and that you know how envelope encryption stores an encrypted data key with its data. Those topics are covered in earlier chapters.
What rotation changes
Rotating a KMS key replaces its backing key material, which is the secret cryptographic bytes inside the key. The key ID, ARN, alias, key policy and grants stay the same. Applications keep using the same identifier and need no change.
KMS keeps every earlier version of the key material. New encryption uses the newest version. When you decrypt, KMS reads the key version from the ciphertext metadata and uses the matching material, so old ciphertext still decrypts.
Rotation does not re-encrypt your data. A data key wrapped under an old version stays wrapped under it. Rotation only limits how much data is protected by any one version of the material.
Automatic rotation
Automatic rotation is available for customer managed symmetric keys with key material created by KMS. Enable it with one command. The default period is 365 days, and you can choose a period from 90 to 2560 days.
aws kms enable-key-rotation --key-id <key-id> --rotation-period-in-days 180
aws kms get-key-rotation-status --key-id <key-id>The status output shows whether rotation is enabled, the period, and the next rotation date. To rotate immediately, for example after a suspected exposure, run aws kms rotate-key-on-demand --key-id <key-id>. KMS limits how many on-demand rotations a key can have.
Which keys rotate
| Key | Rotation |
|---|---|
| Customer managed symmetric (KMS key material) | Automatic, which you enable |
| AWS managed keys | Automatic, managed by AWS, about once a year |
| AWS owned keys | Managed by the owning service |
| Asymmetric and HMAC keys | No automatic rotation |
| Imported key material, custom key stores | No automatic rotation |
Manual rotation
If a key cannot rotate automatically, rotate it yourself:
- Create a new KMS key.
- Point the alias at the new key with
aws kms update-alias --alias-name alias/tutorial-key --target-key-id <new-key-id>. - Keep the old key enabled until nothing needs its ciphertext.
Applications that use the alias switch to the new key without code changes. Ciphertext from the old key still needs the old key, because the new key has a different ID. Decrypting a symmetric ciphertext works without a key ID, so the old key must remain available. Do not delete it until you have re-encrypted or discarded the old data.
Common errors
- Assuming rotation re-encrypts existing data. It does not.
- Trying to enable rotation on an asymmetric or HMAC key. The call fails.
- Hard-coding key IDs. After a manual rotation these point at the old key. Use aliases.
- Disabling the old key after a manual rotation while data still depends on it. Decryption then fails.
Exercise
A key rotated three times this year. You hold a ciphertext produced before the first rotation. Do you need to re-encrypt it before you can decrypt it, and does your application need a new key ID?
Show answer
No to both. The key ID is unchanged, and KMS keeps all earlier key material and picks the right version from the ciphertext metadata, so the old ciphertext decrypts as before.