KMS: import key as immutable
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**)```
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.
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.