Sub topic 16
Imported key material and custom key stores
This chapter covers two advanced ways to control where key material comes from and where it lives. It assumes you know the three key owners, symmetric keys, key policies, and how rotation and deletion work. Most workloads never need either option. Use them only when a compliance rule requires it.
Why you might need them
By default, KMS generates the key material (the secret bytes behind a KMS key) inside its own hardware security modules (HSMs). Some organizations must prove they created the key material themselves, or must keep it in hardware they control. KMS supports two features for this.
| Feature | Who generates the key material | Where the key lives |
|---|---|---|
| Default KMS key | KMS | KMS HSMs |
| Imported key material | You | KMS HSMs, as a copy you supplied |
| Custom key store | KMS or the HSM | An AWS CloudHSM cluster or an external key manager |
Imported key material
With imported key material (also called bring your own key, or BYOK), you create a KMS key with no material and then upload your own. The key's origin is EXTERNAL.
The import works in four steps:
- Create a symmetric KMS key with origin
EXTERNAL. - Download a wrapping public key and an import token.
- Encrypt your key material with the wrapping public key, so it is protected in transit.
- Upload the wrapped material with the import token.
aws kms create-key \
--origin EXTERNAL \
--description "Imported key"
aws kms get-parameters-for-import \
--key-id <key-id> \
--wrapping-algorithm RSAES_OAEP_SHA_256 \
--wrapping-key-spec RSA_2048The second command returns a PublicKey and an ImportToken. You wrap your material with the public key, then call aws kms import-key-material with the wrapped bytes and the token. The public key and token expire, so complete the upload before they do.
What changes with imported material
- You are responsible for durability. Keep a secure copy of the original material. If KMS loses the imported copy, only you can re-import it, and you must import the same material.
- You can set an expiration time. When it passes, KMS deletes the material and the key cannot be used until you re-import it.
- You can delete the material on demand with
aws kms delete-imported-key-material. This makes the key unusable but does not delete the KMS key, its policy, or its alias. - Automatic rotation is not available for these keys. To rotate, create a new KMS key, import new material, and point the alias at it.
Custom key stores
A custom key store is a KMS feature that keeps key material outside the standard KMS HSMs. KMS still handles the API calls, policies and CloudTrail logging. Only the cryptographic operation runs elsewhere. There are two kinds:
- A CloudHSM key store uses an AWS CloudHSM cluster in your account. You own the HSMs, and you manage the cluster.
- An external key store (XKS) uses a key manager outside AWS, such as one in your data center. KMS calls it through an XKS proxy that you operate.
You create the key store, connect it, then create KMS keys in it:
aws kms create-key \
--origin AWS_CLOUDHSM \
--custom-key-store-id <key-store-id>Trade-offs
- Availability depends on you. If the cluster or external manager is disconnected, keys in that store cannot be used, and services encrypted with them fail to read data.
- Latency and throughput are usually worse than for standard keys, and request quotas are lower.
- Many features differ. Check the documentation before relying on automatic rotation, asymmetric keys, or Multi-Region keys with a custom key store.
Choosing
Use standard KMS keys unless a requirement says otherwise. Choose imported material when you must control key generation. Choose a custom key store when you must control the hardware or keep the key outside AWS entirely.
Exercise
A team imports its own key material into a KMS key and sets it to expire in 90 days. What happens at expiry, and what must the team have done to recover?
Show answer
KMS deletes the imported material, so the key cannot encrypt or decrypt until the team re-imports it. Recovery is possible only if they kept a secure copy of the original material, because they must import the same material to decrypt existing ciphertext.