A developer has configured an application running on an Amazon EC2 instance to decrypt database credentials using an AWS KMS customer managed key. The EC2 instance profile has an IAM policy attached that allows the `kms:Decrypt` action on the key's Amazon Resource Name (ARN). However, the application receives an `AccessDeniedException` error when attempting to decrypt the credentials. Which configuration change is required to resolve this authorization error?
- AUpdate the trust policy of the EC2 instance's IAM role to allow the `kms.amazonaws.com` service principal to assume the role.
- Modify the KMS key policy to grant the EC2 instance's IAM role permission to perform the `kms:Decrypt` action.Answer
- CUse the `GenerateDataKey` API operation to download the plaintext private key of the customer managed key, storing it locally to decrypt the credentials without invoking KMS.
- DMigrate the credentials to Systems Manager Parameter Store as a Standard string parameter to bypass AWS KMS validation checks.
Answer
Modify the KMS key policy to grant the EC2 instance's IAM role permission to perform the `kms:Decrypt` action.
For AWS KMS customer managed keys, authorization is determined by both the key policy and IAM policies. If the key policy does not explicitly permit the caller or delegate authority to the root AWS account (which allows IAM policies to take effect), any IAM policies permitting KMS actions will have no effect, resulting in an AccessDeniedException. Granting the EC2 role access in the key policy resolves the issue.
Step-by-Step Solution
Key Concept
AWS KMS Key Policy Authorization
Estimated Time:1m 30s