AWS Certified Developer – Associate
KMS key rotation and envelope encryption for DVA-C03
The AWS KMS Developer Guide says rotation changes only a KMS key's current key material. The KMS key stays the same logical resource with the same properties, and KMS keeps older material to decrypt existing ciphertext. Automatic rotation runs every 365 days by default. Rotation does not rotate data keys or re-encrypt data.
Automatic, on-demand and manual rotation
Automatic rotation is optional on customer managed keys. It is supported only on symmetric encryption KMS keys whose key material KMS generated (AWS_KMS origin). The default rotation period is 365 days, and you can set a custom period with RotationPeriodInDays. AWS managed keys are rotated every year and you cannot change that.
On-demand rotation starts a rotation immediately, whether or not automatic rotation is enabled, and does not change the automatic schedule. It works on symmetric encryption keys with AWS_KMS origin and on symmetric encryption keys with imported key material (EXTERNAL origin).
Asymmetric KMS keys, HMAC KMS keys and keys in custom key stores support neither. For those you rotate manually: create a new KMS key and point your applications or alias at it.
What does rotation change?
Rotation replaces the current key material, the secret used for new encryption operations. The KMS key remains the same logical resource and its properties do not change, so applications need no code change.
KMS keeps all earlier key material for a key with AWS_KMS origin until the key is deleted. On decrypt, KMS picks the material that encrypted the ciphertext. You cannot choose it yourself.
Rotation has no effect on data already protected by the key. It does not rotate the data keys the KMS key generated and does not re-encrypt anything. If a plaintext data key is exposed, rotating the KMS key does not help. The data has to be re-encrypted under a new data key.
Data keys and envelope encryption
Envelope encryption uses two or more keys. A data key encrypts the data, and a KMS key encrypts the data key. A symmetric KMS key cannot be downloaded, while data keys are returned for use outside KMS.
GenerateDataKey returns a plaintext data key and a copy encrypted under the KMS key you name. Encrypt the data with the plaintext key, remove that key from memory, and store the encrypted copy next to the data. GenerateDataKeyWithoutPlaintext returns only the encrypted copy.
To decrypt, pass the encrypted data key to Decrypt, use the returned plaintext key on the data, then remove it from memory. KMS does not store, manage or track data keys.
Where the exam catches people
- Believing rotation re-encrypts existing data: actually it only changes the key material used for new encryption, and old ciphertext is decrypted with the older material.
- Believing rotating the KMS key fixes a leaked data key: actually rotation does not rotate data keys, so the data must be re-encrypted with a new data key.
- Believing automatic rotation can be enabled on an asymmetric key: actually asymmetric, HMAC and custom key store keys need manual rotation to a new key.
- Believing a key with imported key material supports automatic rotation: actually it supports on-demand rotation only.
- Believing the plaintext data key should be stored for later decryption: actually you store the encrypted copy and ask KMS to decrypt it when needed.