KMS (Key Management Service) is AWS’s cryptographic key management service. A KMS key can be one of three types:
AWS owned keyAWS managed keyCustomer Managed Key (CMK)
An HSM (Hardware Security Module) is a dedicated piece of hardware, physically protected against tampering, that generates, stores and uses cryptographic keys without ever exposing them in plaintext outside the device. The HSMs used by KMS are FIPS 140-3 Security Level 3 certified.
AWS owned key#
An AWS owned key never leaves KMS. It is stored in the KMS HSMs.
It is used to encrypt the data of some services (e.g. DynamoDB, which is encrypted at rest by default with an AWS owned key).
It does not live in the customer’s AWS account: the customer can neither see it, nor view its key policy (the document that defines who is allowed to use the key), nor manage it. Its rotation is handled by AWS, on a schedule that varies from service to service.
Its usage cannot be audited.
The key is therefore used by AWS, and the same key may be used to encrypt the data of several customer accounts.
AWS managed key#
An AWS managed key never leaves KMS. It is stored in the KMS HSMs.
It is used by default to encrypt the data of some services, without having to specify anything. Each service has its own, identified by an alias of the form aws/<service> (e.g. aws/ebs for EBS, aws/rds for RDS).
Its key policy can be viewed but not modified. The key cannot be deleted, and its rotation is automatic: every year, with no way to change that schedule.
Its usage can be audited.
It belongs to a single AWS account.
Since 2021, AWS no longer creates AWS managed keys for new services, which use an AWS owned key by default instead. You will therefore mostly come across them with older services, such as EBS or RDS.
Customer Managed Key (CMK)#
A CMK is a key that customers create themselves in their AWS account. They control its key policy and can schedule its deletion, with a waiting period of 7 to 30 days (deletion is irreversible: data encrypted under the key can no longer be decrypted). They can also enable or disable its automatic rotation and choose the rotation period (365 days by default), but only for symmetric keys whose key material is generated by KMS (AWS_KMS origin, see below).
For a CMK, there are several options for the origin of the key material:
| Origin | Where the material is generated | Does it leave KMS? |
|---|---|---|
| AWS_KMS (default) | In the KMS HSMs | Never |
| EXTERNAL (import, BYOK) | On your side, then imported into KMS | You keep a copy outside AWS |
| AWS_CLOUDHSM (custom key store) | In your CloudHSM cluster | It stays in your CloudHSM |
| EXTERNAL_KEY_STORE (XKS) | In your external key manager, outside AWS (hardware or software) | It never enters KMS |
Example: encrypting an EBS volume#
The other AWS services used in this example:
- EC2 (Elastic Compute Cloud): AWS virtual machines, called “instances”.
- EBS (Elastic Block Store): block storage volumes attached to EC2 instances, in other words their virtual hard drives.
- RDS (Relational Database Service): AWS’s managed relational database service (MySQL, PostgreSQL…). For most engines, the data and logs of an RDS instance are stored on EBS volumes.
Nitro cards are electronic cards designed by AWS (through Annapurna Labs, a company Amazon acquired in 2015). They equip new-generation EC2 instances, starting with the C5 instances launched in 2017. They play several roles; in our example, they present EBS volumes to the VM (the RDS or EC2 instance) as local NVMe disks, even though the volumes actually sit on the network.
In this example, I do not cover the older instance families based on the Xen hypervisor (prior to the 2017 C5 instances).
To encrypt the EBS volume of an EC2 or RDS instance, the service asks KMS to generate a data key. A data key is a random key that is encrypted under the chosen KMS key (AWS managed key or CMK).
This encrypted data key is stored in the metadata of the EBS volume or RDS instance: if it is stolen, it is useless without permission to use the KMS key that encrypted it.
The service (EC2 or RDS) calls KMS to decrypt the data key and keeps it in plaintext only in the memory of the Nitro card, for as long as the volume is attached to the instance. The Nitro card encrypts and decrypts blocks on the fly.
This mechanism is called envelope encryption: the data is encrypted with a data key, and that data key is itself encrypted under another key, here the KMS key. The encrypted data key can therefore be safely stored alongside the data it protects, and KMS is only called to decrypt the data key, not for every block of the volume.
Sources and references#
- KMS key types (AWS owned, AWS managed, customer managed), key policy, rotation, AWS managed keys no longer created for new services since 2021: AWS KMS concepts
- KMS HSMs validated at FIPS 140-3 Security Level 3: AWS KMS overview
- DynamoDB encrypted by default with an AWS owned key: DynamoDB encryption at rest
- Deleting KMS keys (CMK only, 7 to 30 day waiting period): Delete an AWS KMS key
- Rotating KMS keys: Rotate AWS KMS keys
- Key material origin (
AWS_KMS,EXTERNAL,AWS_CLOUDHSM,EXTERNAL_KEY_STORE): Create keys · KeyMetadata (KMS API) ·AWS_KMSorigin by default: CreateKey (KMS API) · External key stores - What EBS is: What is Amazon EBS? · RDS storage on EBS volumes: Amazon RDS DB instance storage
- Nitro cards, Annapurna Labs (acquired in 2015): The Security Design of the AWS Nitro System: the components of the Nitro System
- Nitro starting with C5 instances (2017): The Nitro System journey · C5 instances announcement, November 6, 2017
- EBS volumes exposed as NVMe disks: Instances built on the Nitro System
- Default key for EBS: EBS encryption examples · for RDS: RDS encryption keys
- Data key, stored with the volume, plaintext key in Nitro hardware: How EBS encryption works
- Envelope encryption: AWS KMS cryptography essentials: envelope encryption
