Sub topic 4
Referring to keys with IDs, ARNs and aliases
This chapter assumes you can use the AWS CLI, know what a KMS key is, and have read about customer managed keys and key types. It covers the four ways to name a KMS key and when each one works.
Four ways to name a key
Every KMS key has several identifiers. API calls accept different ones depending on the operation.
| Identifier | Example | Notes |
|---|---|---|
| Key ID | `1234abcd-12ab-34cd-56ef-1234567890ab` | A UUID. Unique within a Region. |
| Key ARN | `arn:aws:kms:us-east-1:111122223333:key/1234abcd-12ab-34cd-56ef-1234567890ab` | Includes Region and account. |
| Alias name | `alias/tutorial-key` | A friendly name you choose. Must start with `alias/`. |
| Alias ARN | `arn:aws:kms:us-east-1:111122223333:alias/tutorial-key` | Includes Region and account. |
A key ID or alias name is enough when the key is in your own account and Region. To use a key from another account, you must use the key ARN or the alias ARN. A bare key ID or alias name is resolved in the caller's account.
Aliases
An alias is a separate resource that points to one KMS key. Create one right after you create the key:
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>Applications can then use alias/tutorial-key instead of the key ID. Aliases have these properties:
- An alias points to exactly one key. A key can have several aliases.
- An alias name is unique within an account and Region.
- You can repoint an alias with
aws kms update-alias. The application code does not change, but it now uses a different key. - Names starting with
alias/aws/are reserved for AWS managed keys. - An alias belongs to one Region. The same alias name can exist in another Region and point to a different key.
Where aliases do not work
Aliases are convenient, but some places need the key ID or ARN:
- Decrypt output. Ciphertext from a symmetric key records the key ID, not the alias. That is why
decryptin the next chapter needs no--key-id. - Key policies. The
Resourceelement of a key policy is*, which means "this key". You cannot name an alias there. - Grants. The key identifier for a grant must be a key ID or key ARN.
- Some IAM policies. A policy that lists an alias ARN in
Resourcedoes not match a key by default. Use the condition keykms:ResourceAliasesorkms:RequestAliasif you want to allow access by alias.
Because an alias can be repointed, an IAM policy that allows access by alias lets anyone who can update the alias redirect the policy to another key. Restrict kms:UpdateAlias and kms:CreateAlias accordingly.
Finding the key behind an alias
List aliases to see their targets, then describe the key:
aws kms list-aliases --query "Aliases[?AliasName=='alias/tutorial-key']"
aws kms describe-key \
--key-id alias/tutorial-key \
--query KeyMetadata.[KeyId,Arn]describe-key accepts an alias name and returns the real key ID and ARN.
Exercise
Your application in account 111122223333 must encrypt with a key owned by account 444455556666. Can it pass alias/shared-key as the key ID? What should it pass instead?
Show answer
No. A bare alias name is resolved in the caller's own account, so KMS would look for the alias in 111122223333. The application must pass the full key ARN or the alias ARN, for example arn:aws:kms:us-east-1:444455556666:alias/shared-key. The key policy in the owning account must also allow the caller.