Lesson 5 of 8 AWS KMS and AWS CloudHSM

Bringing Your Own Key Material to AWS KMS

This lesson explains how KMS imports key material that an organisation generates itself or must keep outside AWS, and the responsibility the organisation takes on in return.

Learning outcomes

After completing this lesson, you will be able to:

  • Describe the steps for importing key material.
  • Explain how imported material differs in durability and rotation.
  • Decide when imported key material meets a requirement.

The import process

Some organisations must generate key material in their own hardware security modules, for example to meet a regulation, to keep a copy outside AWS, or to be able to withdraw the key from AWS at any time. KMS supports this with imported key material, often called bring your own key (BYOK). The key material is generated outside AWS and is protected in transit by wrapping it with a public key that KMS provides, so it is never exposed in plaintext. The import consists of the following steps.

  1. Create the key

    Create a KMS key with origin EXTERNAL.

  2. Get the wrapping key

    Download a wrapping public key and import token.

  3. Import the material

    Generate the key material, wrap it and import it, optionally with an expiration date.

Put in order

Importing key material

Exam skills 5.3.2

Arrange the steps for importing your own key material into KMS.

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

How imported material differs

Imported key material gives the customer more control, but it also gives the customer more responsibility. KMS keeps the imported material in its HSMs, but AWS cannot regenerate it, so the customer must keep a secure copy outside AWS. The customer can also remove the material at any time, which makes all data encrypted under it unreadable until the same material is imported again. The following list describes the principal differences from key material generated by KMS.

  • Durability is your responsibility: you must keep a copy.
  • Material can be deleted immediately, with no waiting period, and re-imported later to restore access.
  • Material can be given an expiration date, after which KMS deletes it.
  • No automatic rotation: rotate on demand by importing new material, or move an alias.

The following diagram shows the import of key material into a KMS key and how deleting it acts as a kill switch.

A KMS key with imported material as a kill switch. Material generated in the company's HSM, with an escrow copy kept there, is wrapped with KMS's public key and imported. Deleting the imported material makes data unreadable immediately, unlike the 7 to 30-day key deletion wait; reimporting from escrow restores access.
The scenario is illustrative.
Sort into groups

AWS-generated or imported material?

Exam skills 5.3.3

Decide which kind of key material each statement describes.

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

When to choose imported material

Imported material suits requirements for an escrow copy of keys, for generating keys in the organisation's own HSMs, or for the ability to make data unreadable instantly. Where the requirement is that keys must never be held in AWS at all, an external key store is needed instead.

Worked example

An instant kill switch for encrypted data

A company must be able to make its data in AWS unreadable immediately, and keep an escrow copy of the key in its own HSM. It creates a KMS key with external origin and imports material generated in its HSM:

KEY_ID=$(aws kms create-key --origin EXTERNAL --query KeyMetadata.KeyId --output text)
aws kms get-parameters-for-import --key-id $KEY_ID \
  --wrapping-algorithm RSAES_OAEP_SHA_256 --wrapping-key-spec RSA_4096
# Wrap the key material with the returned public key in the on-premises HSM, then:
aws kms import-key-material --key-id $KEY_ID --encrypted-key-material fileb://wrapped.bin \
  --import-token fileb://token.bin --expiration-model KEY_MATERIAL_DOES_NOT_EXPIRE

# In an emergency
aws kms delete-imported-key-material --key-id $KEY_ID

Deletion takes effect immediately, unlike the 7 to 30-day wait for deleting a key. Importing the same material again from the escrow copy restores access, so the company keeps full control of durability as well as deletion.

Check yourself

Does imported key material rotate automatically?

Show answer

No. It is rotated on demand after new material is imported into the same key, or manually by moving an alias to a new key.

Exam Tips

Remember for the exam

  • When key material must be deletable instantly, use imported key material.
  • To keep an escrow copy of keys outside AWS, use imported key material.
  • Imported key material does not rotate automatically.
  • You are responsible for keeping a copy of imported material.
  • Imported material can be given an expiration date.