Sub topic 2
Who owns the key: AWS owned, AWS managed and customer managed
This chapter assumes you know IAM users, roles and policies, can run the AWS CLI, and can read short Python scripts. You should also know what plaintext and ciphertext are. The previous chapter covered what KMS protects. Here we look at a question that comes up before any encryption call: who owns the key, and what can you do with it?
Three kinds of keys by ownership
Every encryption you do with an AWS service uses a key from one of three categories. The category decides who can see the key, who can change its policy, whether you can audit its use, and what it costs.
- AWS owned keys belong to an AWS service and live in accounts that AWS controls.
- AWS managed keys are created in your account by an AWS service on your behalf.
- Customer managed keys are created and controlled by you.
The category is about ownership and control, not about cryptographic strength. All three use the same AES-256-based algorithms for symmetric encryption.
AWS owned keys
An AWS owned key is part of a collection of keys that an AWS service owns and manages for use across many customer accounts. You never see it. It does not appear in the KMS console, in list-keys, or in your CloudTrail logs, and you cannot set its policy, rotate it or delete it.
Amazon DynamoDB uses an AWS owned key by default for encryption at rest. The data is encrypted and you did nothing to ask for it.
- Cost: no charge.
- Control: none. AWS handles rotation and policy.
- Audit: you cannot see individual uses of the key.
- Good fit: you need encryption at rest to be on by default and have no requirement to prove or restrict who used the key.
Because you cannot see the key, you cannot answer an auditor who asks "show me every decrypt operation on this data". If that question matters to you, pick a different category.
AWS managed keys
An AWS managed key is created in your account the first time you use encryption with a given service. It appears in your account with an alias of the form alias/aws/<service>, such as alias/aws/s3, alias/aws/ebs or alias/aws/secretsmanager.
You can view these keys and see their key policies. Their use is logged in CloudTrail. You cannot edit the key policy, disable or delete the key, or change its rotation. AWS rotates them automatically about once a year.
The key policy of an AWS managed key limits use to the owning account and to requests that come through the named service. It does this with condition keys such as kms:ViaService and kms:CallerAccount. A user in your account cannot call kms:Decrypt on alias/aws/s3 directly and expect it to work in general. The call has to arrive through S3.
- Cost: no monthly fee. You pay for KMS requests above the free tier, as with any key.
- Control: you decide which IAM principals may use the service, but not the key's own policy.
- Audit: use appears in CloudTrail.
- Good fit: you want visibility with the least setup.
Customer managed keys
A customer managed key is one you create, as in the first example from this tutorial's plan:
aws kms create-key --description "Tutorial key"
# Use the KeyId returned by create-key as the target
aws kms create-alias \
--alias-name alias/tutorial-key \
--target-key-id <key-id>With a customer managed key you control nearly everything:
- You write the key policy, including which accounts and roles may use it.
- You can enable or disable the key and schedule its deletion.
- You turn automatic rotation on or off. It is off by default for keys you create.
- You can create grants, add aliases and tags, and use the key from other accounts.
- You can choose advanced options such as Multi-Region keys or imported key material, covered in later chapters.
The price is a monthly fee per key, prorated by the hour, plus a charge for requests beyond the free tier. Check the current KMS pricing page for the exact amounts, since they change. You also take on responsibility: a badly written key policy can lock everyone out, and a deleted key makes its data unrecoverable.
Comparing the three
| Property | AWS owned | AWS managed | Customer managed |
|---|---|---|---|
| Visible in your account | No | Yes | Yes |
| Created by | AWS service | AWS service, in your account | You |
| Edit key policy | No | No | Yes |
| Use shown in your CloudTrail | No | Yes | Yes |
| Rotation | AWS decides | About yearly, automatic | Your choice |
| Disable or delete | No | No | Yes |
| Cross-account use | Not applicable | No | Yes |
| Monthly fee | None | None | Yes, per key |
Telling them apart with the CLI
The KeyManager field of describe-key reports AWS for AWS managed keys and CUSTOMER for customer managed keys. AWS owned keys never show up, because they are not in your account.
aws kms describe-key \
--key-id alias/aws/s3 \
--query "KeyMetadata.[KeyId,KeyManager]" \
--output text
aws kms describe-key \
--key-id alias/tutorial-key \
--query "KeyMetadata.[KeyId,KeyManager]" \
--output textIf alias/aws/s3 does not exist yet, the first call fails. AWS creates it when you first use S3 encryption with KMS in that Region.
To audit a whole Region, this script lists every alias and reports who manages the target key:
import boto3
kms = boto3.client("kms")
paginator = kms.get_paginator("list_aliases")
for page in paginator.paginate():
for alias in page["Aliases"]:
key_id = alias.get("TargetKeyId")
if key_id is None:
continue # alias exists but points at nothing
meta = kms.describe_key(KeyId=key_id)["KeyMetadata"]
print(f'{alias["AliasName"]:40} {meta["KeyManager"]:10} {meta["KeyState"]}')Keys without an alias do not show up here. Use list_keys if you need those too.
How services choose a key
Most services let you pick the category when you turn on encryption. The pattern is similar everywhere:
- The service has a default, which is either an AWS owned key or the AWS managed key for that service.
- You can replace the default with a customer managed key by giving its ARN or alias.
- The service then calls KMS for you, usually to get a data key, as described in the envelope encryption chapter.
Defaults differ by service and can change, so check the service's documentation. For example, DynamoDB tables default to an AWS owned key, while an S3 bucket configured for SSE-KMS without a key choice uses aws/s3. Amazon S3's SSE-S3 option is a different mechanism that does not use KMS keys you can see at all.
Choosing: decision criteria
Start from your requirements rather than from the cheapest option.
- Compliance demands proof of key use. Use AWS managed or customer managed keys so CloudTrail records each use.
- You must restrict who can decrypt, beyond IAM in your account. Use a customer managed key, because only then can you write the key policy.
- Another account needs to read the data. Use a customer managed key.
- You need to revoke access quickly. A customer managed key can be disabled, which stops decryption of everything under it. Be sure you accept that effect.
- You have many small, low-risk datasets and want no key overhead. AWS owned or AWS managed keys are fine.
- You need separation between workloads. Create one customer managed key per application or data classification so that a policy mistake on one does not expose the others.
A common pattern is to use customer managed keys for sensitive or shared data and leave defaults for everything else. This keeps the monthly fees limited to the places where control pays for itself.
Common mistakes
- Assuming "AWS managed" means "managed by AWS for you, so I can tune it". You cannot change its policy or rotation.
- Choosing
aws/ebsfor snapshots you plan to share, then discovering the other account cannot copy them. - Creating a customer managed key and forgetting that automatic rotation is off until you enable it.
- Looking for AWS owned key activity in CloudTrail. It will not be there.
- Counting keys in
list-keysto estimate cost. That list includes AWS managed keys, which have no monthly fee.
Exercise
Your team stores customer files in S3 and must let a second AWS account read them. Which key category can you use for SSE-KMS, and why can't you use the others?
Show answer
Use a customer managed key. Its key policy can grant the second account (or a role in it) permission to decrypt. The AWS managed key aws/s3 has a policy you cannot edit and is limited to your own account, so another account cannot use it. An AWS owned key is not exposed in your account at all and offers no policy to edit.
Exercise
A script runs aws kms describe-key --key-id alias/aws/ebs --query KeyMetadata.KeyManager --output text. What does it print, and what would it print for a key you created with aws kms create-key?
Show answer
It prints AWS for the AWS managed key, and CUSTOMER for the key created with create-key.