Sub topic 1
What KMS is and what it protects
Prerequisites
This chapter assumes you know the following:
- Basic AWS account and IAM concepts: users, roles and policies.
- The AWS CLI, plus a programming language such as Python.
- The difference between plaintext and ciphertext, and how symmetric encryption works.
What AWS KMS is
AWS Key Management Service (KMS) is a managed service that creates, stores and uses cryptographic keys for you. Your applications ask KMS to perform operations. KMS performs them inside hardware security modules (HSMs), which are tamper-resistant devices that hold key material.
The central object is the KMS key. A KMS key is a logical container that points to key material. The key material never leaves KMS unencrypted. You send data to KMS, or you ask KMS for a data key, and the key material stays inside the service.
KMS keys and data keys
Two kinds of keys appear throughout this tutorial. Keeping them apart avoids most early confusion.
| Property | KMS key | Data key |
|---|---|---|
| Where it lives | Inside KMS | Wherever your application uses it |
| Typical use | Protect other keys and small payloads | Encrypt your actual data |
| Leaves KMS in plaintext | Never | Yes, briefly, in memory |
| Size limit on direct use | Encrypts at most 4 KB per call | No practical limit |
A data key is an ordinary symmetric key that your code uses locally. KMS can generate one and return it in two forms: plaintext, and encrypted under a KMS key. Later chapters build on this idea as envelope encryption.
What KMS protects
KMS protects the keys that protect your data. It does not store your data. Its main guarantees are:
- Key secrecy. Plaintext key material is never exported for standard KMS keys.
- Access control. Every use of a key is checked against policies you write.
- Auditability. Every call to KMS is recorded in AWS CloudTrail.
- Lifecycle control. You can rotate, disable or delete keys.
KMS does not protect data that is already decrypted in your application's memory. It also does not replace IAM or network controls. It adds a separate permission check. A person who can read an encrypted S3 object still needs permission to use the KMS key before they can read the contents.
How a request flows
The diagram shows a direct call. Your application never sees the KMS key itself.
Each call is authorized against the key policy and any IAM policies. Each call also produces a CloudTrail event.
Check your setup
Before you create keys in later chapters, confirm that your CLI identity works and that you can reach KMS. This command lists the KMS keys that exist in your current Region. A new account may return an empty list.
aws sts get-caller-identity
aws kms list-keys --max-items 5KMS keys are Regional. A key created in us-east-1 cannot be used from eu-west-1 unless you use a Multi-Region key, which a later chapter covers.
Common errors
- AccessDeniedException. Your identity lacks permission in the key policy or in IAM. KMS requires both layers to agree, as later chapters explain.
- Wrong Region. The key exists, but your CLI is configured for a different Region. Check
aws configure get region. - Confusing the key with the data. Direct KMS calls only handle small payloads. Large data needs a data key.
Exercise
A teammate says, "KMS stores our encrypted files." What is wrong with that statement, and what does KMS actually hold?
Show answer
KMS does not store your data. It holds KMS keys and performs cryptographic operations with them, either on small payloads you send or by generating and encrypting data keys. Your application or another service, such as S3, stores the encrypted data.
Exercise
Why does a KMS key never leave KMS in plaintext, while a data key can?
Show answer
A KMS key is the long-lived root that protects other keys, so it stays inside KMS HSMs. A data key is a short-lived working key that your application needs in memory to encrypt data locally. KMS returns it in plaintext once, together with a copy encrypted under the KMS key.