Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(pipes-alpha): support for customer-managed KMS keys to encrypt pipe data #33546

Merged
merged 12 commits into from
Feb 27, 2025

Conversation

badmintoncryer
Copy link
Contributor

@badmintoncryer badmintoncryer commented Feb 21, 2025

Issue # (if applicable)

Closes #31453

Reason for this change

AWS Pipes supports for encrypting data by customer managed KMS key instead of Amazon managed key.

https://docs.aws.amazon.com/eventbridge/latest/userguide/eb-encryption-pipes-cmkey.html

The L2 Pipe construct does not support this feature now.

Description of changes

  • Add kmsKey prop to PipeProps

Describe any new or updated permissions being added

  • Add KMS key policy which enables pipes to access to the key.

https://docs.aws.amazon.com/eventbridge/latest/userguide/eb-encryption-key-policy.html#eb-encryption-key-policy-pipe

Description of how you validated changes

Add both unit and integ tests.

Checklist


By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license

@badmintoncryer badmintoncryer changed the title feat(aws-pipes-alpha): support customer managed key to encrypt pipe data feat(aws-pipes-alpha): support customer managed kms key to encrypt pipe data Feb 21, 2025
@aws-cdk-automation aws-cdk-automation requested a review from a team February 21, 2025 14:28
@github-actions github-actions bot added p2 distinguished-contributor [Pilot] contributed 50+ PRs to the CDK labels Feb 21, 2025
@@ -23,7 +23,7 @@ can be filtered, transformed and enriched.

![diagram of pipes](https://d1.awsstatic.com/product-marketing/EventBridge/Product-Page-Diagram_Amazon-EventBridge-Pipes.cd7961854be4432d63f6158ffd18271d6c9fa3ec.png)

For more details see the [service documentation](https://docs.aws.amazon.com/eventbridge/latest/userguide/eb-pipes.html).
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed several unnecessary spaces.

Copy link
Collaborator

@aws-cdk-automation aws-cdk-automation left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(This review is outdated)

@badmintoncryer badmintoncryer changed the title feat(aws-pipes-alpha): support customer managed kms key to encrypt pipe data feat(pipes-alpha): support customer managed kms key to encrypt pipe data Feb 21, 2025
Copy link

codecov bot commented Feb 21, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 82.21%. Comparing base (7ebb92c) to head (8ce477f).
Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main   #33546   +/-   ##
=======================================
  Coverage   82.21%   82.21%           
=======================================
  Files         119      119           
  Lines        6876     6876           
  Branches     1162     1162           
=======================================
  Hits         5653     5653           
  Misses       1120     1120           
  Partials      103      103           
Flag Coverage Δ
suite.unit 82.21% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Components Coverage Δ
packages/aws-cdk ∅ <ø> (∅)
packages/aws-cdk-lib/core 82.21% <ø> (ø)

@aws-cdk-automation aws-cdk-automation dismissed their stale review February 21, 2025 14:39

✅ Updated pull request passes all PRLinter validations. Dismissing previous PRLinter review.

@badmintoncryer badmintoncryer changed the title feat(pipes-alpha): support customer managed kms key to encrypt pipe data feat(pipes-alpha): support for customer-managed KMS keys to encrypt pipe data Feb 22, 2025
@aws-cdk-automation aws-cdk-automation added the pr/needs-community-review This PR needs a review from a Trusted Community Member or Core Team Member. label Feb 22, 2025
Copy link
Contributor

@mazyu36 mazyu36 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your contribution! I think it's mostly fine.
I've added one question.

Also, I previously opened an issue here: #31453.
Would it be possible to link this contribution to that issue?

@@ -295,6 +303,7 @@ export class Pipe extends PipeBase {
targetParameters: target.targetParameters,
desiredState: props.desiredState,
logConfiguration: logConfiguration,
kmsKeyIdentifier: props.kmsKey?.keyArn,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a question—did it work correctly even without setting a key policy?

When I previously attempted to contribute to this, I encountered an error without a key policy, but I couldn't come up with a proper way to configure it and had to give up at the time.

It might have been my misunderstanding back then, or something might have changed with an update. If it worked fine, please just ignore this question.

Ref: https://docs.aws.amazon.com/eventbridge/latest/userguide/eb-encryption-key-policy.html#eb-encryption-key-policy-pipe

Copy link
Contributor Author

@badmintoncryer badmintoncryer Feb 25, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are absolutely right.. I misunderstood that this implementation would be work fine. Thank you for your great suggestion.

How about adding the restriction that makes pipeName mandatory when kmsKey is provided?
This idea is not ideal, but it would provide the minimum feature that enables us to configure CMK for Pipes.

Copy link
Contributor

@mazyu36 mazyu36 Feb 25, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for confirming. So that's how it is...
I think your suggested solution is good.​​​​​​​​​​​​​​​​

Personally, I've been considering the following three options:

  1. Make name mandatory when kmsKey is specified. This is the same as the suggestion you provided.
  2. Instead of setting name to undefined when it's not specified, automatically generate it using Names.uniquid. However, I understand this would be a breaking change.
  3. Configure kmsKey using a custom resource. I think this option is not ideal.

Based on the above, I believe option 1 or option 2 would be good, and I think option 1 would be better to avoid a breaking change.

Copy link
Contributor Author

@badmintoncryer badmintoncryer Feb 26, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I hadn't thought of option 2. I think implementing option 2 with a feature flag is also a good idea.
For now, I'll proceed with option 1. Of course, I'll also add integration testing to verify the functionality.

Copy link
Contributor Author

@badmintoncryer badmintoncryer Feb 26, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've just noticed that the feature flag is not essential because this is alpha module..
I think the option 2 might be preferable for alpha module. I'll leave the decision to the maintainer.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I also think Options2 is smarter, but since the impact is significant, I'd like to wait for the maintainer's opinion.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the deep dive. I think Option 1 makes sense to me. Can you help me understand Option 2 + feature flag solution?
In my understanding, we can't create the policy without knowing the pipe name. If we add a feature flag, for new stacks, we will always create a default pipe name if not specified which would solve the issue. However, for existing stack (who did not enable this feature flag), we will still have the same issue right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@GavinZZ

Thank you for the clarification.

However, for existing stack (who did not enable this feature flag), we will still have the same issue right?

You're absolutely right! When setting a CMK for stacks under an App where the function flag is not enabled, the pipeName cannot be obtained, resulting in the inability to set the correct key policy.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the quick response. Given the above discussion, I'll remove the do-not-merge label and let's go with the solution you had here. Thank you!

@github-actions github-actions bot added effort/medium Medium work item – several days of effort feature-request A feature should be added or improved. labels Feb 26, 2025
@badmintoncryer
Copy link
Contributor Author

@mazyu36 Thank you for your nice review!! I've addressed your comments.

Copy link
Contributor

@mazyu36 mazyu36 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! LGTM

@aws-cdk-automation aws-cdk-automation added pr/needs-maintainer-review This PR needs a review from a Core Team Member and removed pr/needs-community-review This PR needs a review from a Trusted Community Member or Core Team Member. labels Feb 26, 2025
Copy link
Contributor

@GavinZZ GavinZZ left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great, thank you!

@@ -295,6 +303,7 @@ export class Pipe extends PipeBase {
targetParameters: target.targetParameters,
desiredState: props.desiredState,
logConfiguration: logConfiguration,
kmsKeyIdentifier: props.kmsKey?.keyArn,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the deep dive. I think Option 1 makes sense to me. Can you help me understand Option 2 + feature flag solution?
In my understanding, we can't create the policy without knowing the pipe name. If we add a feature flag, for new stacks, we will always create a default pipe name if not specified which would solve the issue. However, for existing stack (who did not enable this feature flag), we will still have the same issue right?

@GavinZZ GavinZZ added the pr/do-not-merge This PR should not be merged at this time. label Feb 26, 2025
@GavinZZ
Copy link
Contributor

GavinZZ commented Feb 26, 2025

Adding a do-not-merge flag for this thread #33546 (comment)

@GavinZZ GavinZZ self-assigned this Feb 26, 2025
@aws-cdk-automation aws-cdk-automation removed the pr/needs-maintainer-review This PR needs a review from a Core Team Member label Feb 26, 2025
@GavinZZ GavinZZ removed the pr/do-not-merge This PR should not be merged at this time. label Feb 27, 2025
Copy link
Contributor

mergify bot commented Feb 27, 2025

Thank you for contributing! Your pull request will be updated from main and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork).

@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

  • CodeBuild project: AutoBuildv2Project1C6BFA3F-wQm2hXv2jqQv
  • Commit ID: 8ce477f
  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

Copy link
Contributor

mergify bot commented Feb 27, 2025

Thank you for contributing! Your pull request will be updated from main and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork).

@mergify mergify bot merged commit dd0d62f into aws:main Feb 27, 2025
20 checks passed
Copy link

Comments on closed issues and PRs are hard for our team to see.
If you need help, please open a new issue that references this one.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 27, 2025
@badmintoncryer badmintoncryer deleted the pipes-cmk branch February 27, 2025 00:55
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
distinguished-contributor [Pilot] contributed 50+ PRs to the CDK effort/medium Medium work item – several days of effort feature-request A feature should be added or improved. p2
Projects
None yet
Development

Successfully merging this pull request may close these issues.

pipes: support Customer Managed Key for EventBridge pipes
4 participants