aws-cdk icon indicating copy to clipboard operation
aws-cdk copied to clipboard

KMS: import key as immutable

Open Cushdrive opened this issue 5 years ago • 2 comments

Similar to mutable=False or withoutPolicyUpdates for IAM Roles, I need a way to prevent automatic KMS resource policy updates on my behalf. This automatic policy update is happening when adding an SQS queue destination to an S3 bucket notification. Because I'm simply importing a KMS key and associating it with a new SQS queue, then setting up the notification with a bucket, I get the following exception:

jsii.errors.JSIIError: Unable to add statement to IAM resource policy for KMS key: "..."

Use Case

This feature is needed because, in my case, KMS keys are created and managed by a separate team, and the policy is also managed by them out-of-band. Another valid reason is that the key already has a sufficiently lenient policy to allow this type of decrypt operation without CDK adding its own policy that's specific to the s3 notification.

Proposed Solution

Option 1 (only covers the specific S3 notification use case):


            self.bucket.add_event_notification(
                s3.EventType.OBJECT_CREATED,
                dest=notify.SqsDestination(queue=newqueue**.without_policy_updates()**)
            )

Option 2 (covers more use cases):


           kms_key = kms.Key.from_key_arn(self, "stream_kms_key", key_arn=kms_key_arn**, mutable=False**)```

Cushdrive avatar Sep 20 '21 19:09 Cushdrive

Sounds reasonable.

For now, your best way to unblock yourself is to make a class that implements IKey, and that implements addToResourcePolicy() to do nothing.

Otherwise, if you want to submit a PR to add the option to Key.fromKeyArn, that would be welcome too.

rix0rrr avatar Sep 29 '21 15:09 rix0rrr

This issue has not received any attention in 1 year. If you want to keep this issue open, please leave a comment below and auto-close will be canceled.

github-actions[bot] avatar Oct 07 '22 16:10 github-actions[bot]