fix(template): use bucket ARN for SSE-KMS encryption context#540
Merged
Conversation
PR #533 scoped kms:EncryptionContext:aws:s3:arn to the object ARN (<bucket>/<BucketKey>). That works for plain SSE-KMS, but the state bucket has BucketKeyEnabled: true, so S3 generates a short-lived bucket-level data key and derives per-object keys locally — the encryption context S3 forwards to KMS is the bucket ARN, not the object ARN. The condition therefore never matched at runtime and every sync failed with: AccessDenied: ... is not authorized to perform: kms:Decrypt on resource: arn:aws:kms:...:key/... because no identity-based policy allows the kms:Decrypt action (IAM reports a condition-mismatched Allow as "not allowed".) Change both KMSGetDataPolicy and KMSDecryptPolicy to pin the bucket ARN. The role can still only reach the single state object via the S3ObjectPolicy ARN scoping; kms:ViaService still forces all KMS access through S3. Also update docs/Whats-New.md to describe the correct behavior and link to the S3 Bucket Keys docs. Refs: #521, #533 Ref: https://docs.aws.amazon.com/AmazonS3/latest/userguide/bucket-key.html Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
AccessDenied … kms:Decrypt … no identity-based policy allows the kms:Decrypt action.kms:EncryptionContext:aws:s3:arnto the object ARN, but the state bucket hasBucketKeyEnabled: true. With Bucket Keys enabled, S3 generates a short-lived bucket-level data key and derives per-object keys locally — the encryption context S3 forwards to KMS is the bucket ARN, never the object ARN. The condition therefore never matched, and IAM reports a condition-mismatchedAllowas "not allowed".KMSGetDataPolicyandKMSDecryptPolicynow pin the bucket ARN. The role still cannot reach any other object (theS3ObjectPolicyARN scoping handles that), andkms:ViaServicestill forces all KMS access through S3.docs/Whats-New.mdto describe the correct behavior and link to the AWS S3 Bucket Keys docs.Observed error (before this fix)
Test plan
template.yaml.rate(15 minutes)invocation) and confirm the sync completes without thekms:DecryptAccessDenied.kms:Decryptcall from S3 carrieskms:EncryptionContext:aws:s3:arn = arn:aws:s3:::<bucket>(bucket ARN, no object suffix) — i.e. the new condition matches what S3 actually sends.S3ObjectPolicy, not the KMS condition).Refs: #521, #533
🤖 Generated with Claude Code