A KMS-encrypted resource fails with `AccessDeniedException ... is not authorized to perform: kms:CreateGrant`, though the role has `kms:*` in its IAM policy.
AdvancedTroubleshootingAuthentication and Cloud API Errors
Answer
Likely causes → KMS needs both the key policy and IAM policy to allow access (unless the key policy delegates to IAM with the account root principal). Cross-account keys need the key policy to name your account.
Diagnose →
aws kms get-key-policy --key-id <key-id> --policy-name default --output text | jq .
Look for the root principal statement or your role.
Fix → Add the Terraform role (or root delegation) to the key policy, including kms:CreateGrant with kms:GrantIsForAWSResource for services like EBS/RDS.
Prevent → Manage key policies in Terraform with the consumers declared explicitly, and test with a sandbox key.
More on Authentication and Cloud API Errors
`Error: No valid credential sources found` followed by `no EC2 IMDS role found ... context deadline exceeded`.Beginner`Error: Cannot assume IAM Role` — `api error AccessDenied: User: arn:aws:iam::111111111111:user/ci is not authorized to perform: sts:AssumeRole on resource: arn:aws:iam::222222222222:role/terraform`.IntermediateGitHub Actions: `Could not assume role with OIDC: Not authorized to perform sts:AssumeRoleWithWebIdentity`.IntermediateGitHub Actions log says `It looks like you might be trying to authenticate with OIDC. Did you mean to set the id-token permission?`BeginnerApplies that run longer than an hour fail with `ExpiredToken: The security token included in the request is expired`.Intermediate`InvalidClientTokenId: The security token included in the request is invalid.`Beginner