Certopolis

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.

Written from these sources

Try 3 questions on this

Pick an answer to see why each option is right or wrong.

  1. A company encrypts application data with a customer managed AWS KMS key. An auditor requires the key material to change every year. The application already holds several years of ciphertext, and the company cannot afford an outage or a bulk re-encryption job. Which solution will meet these requirements?

    Right. In the game that’s Renown for your Security building.

    Not that one: A is right. In the game your Security building would lose a little Renown, and this question would come back later.

    Show the full explanation and doc quotes

    AWS KMS retains all previous key material and automatically selects the version that encrypted a given ciphertext, so existing data decrypts with no code change and no re-encryption.

    Written from docs.aws.amazon.com/kms/latest/developerguide/rotate-keys.html

  2. A company uses envelope encryption for files in Amazon S3. Data keys are generated under a customer managed KMS key that has automatic rotation enabled. A plaintext data key for one file was accidentally written to an application log, and the log was exposed. The security team must ensure that the exposed key can no longer decrypt the file. What should the developer do to remediate the exposure?

    Right. In the game that’s Renown for your Security building.

    Not that one: B is right. In the game your Security building would lose a little Renown, and this question would come back later.

    Show the full explanation and doc quotes

    KMS documentation is explicit that key rotation will not mitigate the effect of a compromised data key.

    Written from docs.aws.amazon.com/kms/latest/developerguide/rotate-keys.html

  3. A developer encrypts large files in an application before writing them to a local volume. The developer calls the AWS KMS GenerateDataKey operation and encrypts each file with the plaintext data key that AWS KMS returns. What should the developer do to ensure that the files can be decrypted later?

    Right. In the game that’s Renown for your Security building.

    Not that one: C is right. In the game your Security building would lose a little Renown, and this question would come back later.

    Show the full explanation and doc quotes

    At decryption time the application passes the encrypted data key to the Decrypt operation, which returns the plaintext key needed to decrypt the file.

    Written from docs.aws.amazon.com/kms/latest/developerguide/data-keys.html

Ask for something