Lesson 1 of 4 AWS KMS

Choosing and Controlling Access to AWS KMS Keys

This lesson explains how AWS Key Management Service (AWS KMS) creates and controls encryption keys that never leave the service unencrypted. A key policy decides who may use a key, and code refers to it by its ID, ARN or alias.

Learning outcomes

After completing this lesson, you will be able to:

  • Distinguish AWS owned, AWS managed and customer managed keys.
  • Distinguish symmetric and asymmetric keys and their uses.
  • Explain how key policies, IAM policies and grants combine to control access to a key.
  • Describe how aliases, multi-Region keys and the deletion waiting period work.

Types of KMS key

AWS KMS keys are classified by who creates and manages them, and the type decides how much control and visibility the customer has.

AWS owned keys belong to AWS and are shared across many accounts. A service uses them to encrypt data by default, as DynamoDB does for every table unless another key is chosen. They do not appear in the account, their use is not recorded in CloudTrail, and they cost nothing. AWS managed keys are created in the account by a service the first time it needs one, with aliases such as aws/s3 or aws/lambda. They are visible and their use is logged, but their key policy cannot be changed, so they cannot be shared with other accounts, and AWS rotates them every year.

Customer managed keys are created by the customer, who writes the key policy, decides which principals and accounts may use the key, enables or disables it, chooses the rotation period and can schedule its deletion. They cost a monthly fee per key plus request charges. The following table summarises the three types.

Key typeCreated byYou control the policy?RotationExample
AWS ownedAWS, used internally by services across many accountsNoManaged by AWSDefault DynamoDB encryption
AWS managedAWS, per service in your accountNoEvery year, automaticallyaws/s3, aws/lambda
Customer managedYouYesOptional, 90 to 2,560 daysalias/orders-key

Customer managed keys cost a monthly fee per key plus requests, and are required when you need to control the key policy, share the key with another account or audit and disable it yourself.

Sort into groups

Which type of key?

Exam skills 2.2.4 · 2.2.1

Recognise AWS owned, AWS managed and customer managed keys from their behaviour.

Log in to try this activity Interactive activities are free with an account.

Symmetric and asymmetric keys

A KMS key is either symmetric or asymmetric, and the choice is made when the key is created.

A symmetric key is a single 256-bit secret that both encrypts and decrypts. It never leaves KMS unencrypted, so every encryption and decryption is a call to KMS made with AWS credentials, and every use is authorised by the key policy and logged in CloudTrail. AWS services that encrypt data on your behalf, such as S3, EBS and DynamoDB, use symmetric keys, and it is the default type.

An asymmetric key is a public and private key pair, based on RSA or elliptic curve cryptography. The private key never leaves KMS, but the public key can be downloaded and used anywhere. This allows two things that a symmetric key does not: parties outside AWS, without AWS credentials, can encrypt data with the public key that only KMS can decrypt, and KMS can sign data, such as a software release, whose signature anyone can verify with the public key. An HMAC key generates and verifies message authentication codes, for example to check that a token has not been altered. The following table summarises the key types.

Key specUsed forKey material
Symmetric (SYMMETRIC_DEFAULT)Encryption and decryption inside KMS; integrated with AWS servicesNever leaves KMS
Asymmetric RSA or ECCEncryption outside AWS, or signing and verificationThe public key can be downloaded; the private key never leaves KMS
HMACGenerating and verifying message authentication codesNever leaves KMS

AWS services that encrypt data for you use symmetric keys.

Key policies and grants

Every KMS key has exactly one key policy, its primary access control. IAM policies take effect only if the key policy allows the account to delegate access through IAM, which the default key policy does with this statement:

{
  "Sid": "Enable IAM User Permissions",
  "Effect": "Allow",
  "Principal": {"AWS": "arn:aws:iam::111122223333:root"},
  "Action": "kms:*",
  "Resource": "*"
}

The statement above allows IAM policies to grant access to the key. The following list describes further controls over the use of KMS keys.

  • If that statement is removed, only principals named in the key policy can use or manage the key.
  • Grants give a principal temporary, programmatic use of a key for specific operations; AWS services such as EBS create grants on your behalf.
  • Condition keys such as kms:ViaService limit a key to use through a particular service, such as S3.

Aliases and multi-Region keys

KMS provides aliases, multi-Region keys and a waiting period before deletion. The following list describes these features.

  • An alias, such as alias/orders-key, lets code refer to a key by name, so you can point the alias at a new key without changing code. Aliases are Regional.
  • Multi-Region keys share key ID and key material across Regions, so data encrypted in one Region decrypts in another without a cross-Region call; useful for global tables, cross-Region replication and disaster recovery.
  • A key scheduled for deletion waits 7 to 30 days first; disabling a key is the reversible alternative.
aws kms create-key --description "Orders data" --query KeyMetadata.KeyId --output text
aws kms create-alias --alias-name alias/orders-key --target-key-id 1234abcd-12ab-34cd-56ef-1234567890ab
Scenario questions

Aliases, Regions and deletion

Exam skills 2.2.4

Practise aliases, multi-Region keys and safe deletion.

Log in to try this activity Interactive activities are free with an account.
Worked example

Choosing a key type

The appropriate type of KMS key depends on the level of control required. The following table identifies the key suited to several requirements.

RequirementKey
Encrypt an S3 bucket with no key management at allSSE-S3, or the AWS managed key aws/s3
Audit and restrict who can decrypt payroll filesCustomer managed key with a restrictive key policy
Share encrypted snapshots with a disaster recovery accountCustomer managed key that allows the other account
Decrypt replicated data in a second Region without cross-Region callsMulti-Region customer managed key
Sign software releases so customers can verify themAsymmetric signing key; the public key is distributed

Applications refer to each key through an alias such as alias/payroll, so a key can be replaced later without code changes.

Check yourself

When must a customer managed key be used instead of an AWS managed key?

Show answer

When you need to control the key policy, share the key with other accounts, disable or delete it yourself, or choose its rotation period. AWS managed keys cannot be shared and their policies cannot be changed.

Exam Tips

Remember for the exam

  • Control over the key policy, cross-account sharing or your own audit trail requires a customer managed key.
  • IAM policies grant KMS access only when the key policy allows the account to use IAM.
  • Refer to keys by alias so a key can be replaced without code changes.
  • To decrypt replicated data in another Region, use multi-Region keys.
  • Deleting a KMS key makes its data unrecoverable; disable the key if access must stop temporarily.