Lesson 4 of 4 Data Classification and Encryption at Rest

Troubleshooting AWS KMS Errors

This lesson explains how KMS errors surface in many services, and how a systematic check of the key and its policies resolves most cases.

Learning outcomes

After completing this lesson, you will be able to:

  • Recognise common KMS errors and their fixes.
  • Follow a checking sequence with CloudTrail.
  • Fix instances that terminate at launch because of key permissions.

Common errors

The following table lists the KMS problems most often seen in operations and their fixes.

SymptomCauseFix
AccessDeniedException calling kms:DecryptKey policy does not allow the principal or account, or IAM policy lacks permissionAdd the principal to the key policy and/or IAM policy
KMSInvalidStateException / key is disabledKey disabled or pending deletionEnable the key or cancel deletion
Instance terminates immediately at launch (Client.InternalError)Encrypted volume and the launching principal or service-linked role cannot use the keyGrant the role access in the key policy
Cannot share a snapshot or AMIEncrypted with an AWS managed keyCopy with a customer managed key, then share
Cross-Region copy failsDestination key not specified or not usableSpecify a key in the destination Region
ThrottlingException from KMSRequest rate quota exceeded (for example SSE-KMS on a busy bucket)Enable S3 Bucket Keys, cache data keys, request a quota increase
Service cannot publish to encrypted SNS/SQSKey policy does not allow the service principalAllow the service principal kms:GenerateDataKey* and kms:Decrypt

The following diagram shows a common access denied error: a service-linked role missing from the key policy.

Why a service fails when its service-linked role is missing from a key policy. When a launch template encrypts volumes with a customer managed key, Auto Scaling launches instances with its service-linked role, AWSServiceRoleForAutoScaling, and the launches fail if the key policy does not allow that role. Adding the role to the key policy, with permission to create grants, fixes the launches.
The same pattern applies to any service that uses the key through its own service-linked role.
Match the pairs

KMS errors

Exam skills 4.2.2

Match each KMS error with its usual cause.

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

A checking sequence

When a KMS-related failure occurs, check the following points in order.

  1. Key, Region and account

    Which key is used, and where? Keys are Regional; aliases are per account and Region.

  2. Key state

    Is it Enabled, Disabled, PendingDeletion or PendingImport?

  3. Key policy

    Does it allow the calling principal or its account (with the root statement enabling IAM)?

  4. IAM, SCPs and boundaries

    Does the principal's IAM policy allow the KMS action, and do SCPs or permissions boundaries deny it?

  5. Conditions

    Do conditions such as kms:ViaService, kms:CallerAccount or encryption context match the request?

  6. Service integrations

    Is the service principal or service-linked role allowed, and does a grant exist?

CloudTrail records every KMS API call, including failed ones with the error code, which identifies the exact principal and operation.

The following diagram shows the checks as a sequence.

A checking sequence for KMS failures: the key, Region and account in use; the key state; whether the key policy allows the caller; IAM policies, SCPs and boundaries; conditions such as kms:ViaService or the encryption context; and, for service integrations, the service-linked role and grants. CloudTrail shows the failed call.
Most failures are found in the first three checks.
Worked example

Auto Scaling launches fail after encryption

After a launch template is changed to encrypt volumes with a new customer managed key, the Auto Scaling group's activity history shows Instance became unhealthy while waiting for instance to be in InService state. Termination reason: Client.InternalError: Client error on launch. The key policy allows only the security team. Auto Scaling launches instances with its service-linked role, AWSServiceRoleForAutoScaling, which needs permission to use the key and to create grants. Adding a key policy statement for that role with kms:Encrypt, kms:Decrypt, kms:ReEncrypt*, kms:GenerateDataKey*, kms:DescribeKey and kms:CreateGrant (with kms:GrantIsForAWSResource) fixes the launches.

Check yourself

A service publishes to an encrypted SQS queue and fails. What does the key policy need?

Show answer

A statement allowing that service principal to use the key.

Exam Tips

Remember for the exam

  • Check key Region, state, key policy, IAM policy, SCPs and conditions in that order.
  • Auto Scaling needs its service-linked role allowed in the key policy for encrypted launches.
  • Services publishing to encrypted SNS or SQS need the key policy to allow their service principal.
  • KMS throttling on S3: enable Bucket Keys.