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(kms): add multiRegion property to a Key #31125

Merged
merged 7 commits into from
Aug 28, 2024

Conversation

kawabata-mcl
Copy link
Contributor

Issue # (if applicable)

None

Reason for this change

We can create a multi-Region primary key for a KMS key from cloudformation, but this was not supported in the AWS CDK L2 construct.

Description of changes

Add multiRegion property to KeyProps and set it in the CfnKey constructor.

Description of how you validated changes

Added both unit and integration tests.

Checklist


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

@github-actions github-actions bot added the p2 label Aug 15, 2024
@aws-cdk-automation aws-cdk-automation requested a review from a team August 15, 2024 09:40
@github-actions github-actions bot added the beginning-contributor [Pilot] contributed between 0-2 PRs to the CDK label Aug 15, 2024
@kawabata-mcl kawabata-mcl changed the title feat(kms): add multiRegion property to a Key feat(kms): add **multiRegion** property to a **Key** Aug 15, 2024
@kawabata-mcl kawabata-mcl changed the title feat(kms): add **multiRegion** property to a **Key** feat(kms): add multiRegion property to a Key Aug 15, 2024
@kawabata-mcl kawabata-mcl changed the title feat(kms): add multiRegion property to a Key feat(kms): add multiRegion property to a Key Aug 15, 2024
@kawabata-mcl kawabata-mcl changed the title feat(kms): add multiRegion property to a Key feat(kms): add multiRegion property to a Key Aug 15, 2024
@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 Aug 15, 2024
Copy link
Contributor

@go-to-k go-to-k 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 the PR. I made a few minor comments.

* regardless of the value of the UpdateReplacePolicy attribute.
* This prevents you from accidentally deleting a KMS key by changing an immutable property value.
*
* @default - false
Copy link
Contributor

Choose a reason for hiding this comment

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

If the default value is false, it would be good to write it like this.

Suggested change
* @default - false
* @default false

* This prevents you from accidentally deleting a KMS key by changing an immutable property value.
*
* @default - false
*/
Copy link
Contributor

Choose a reason for hiding this comment

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

There's a document that's helpful, and it would be good to put that here.

Suggested change
*/
* @see https://docs.aws.amazon.com/kms/latest/developerguide/multi-region-keys-overview.html
*/

@@ -41,6 +41,15 @@ const key = new kms.Key(this, 'MyKey', {
});
```


Creates a multi-Region primary key:
Copy link
Contributor

Choose a reason for hiding this comment

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

nit. (Matched elsewhere.)

Suggested change
Creates a multi-Region primary key:
Create a multi-Region primary key:


class TestStack extends Stack {
constructor(scope: App) {
super(scope, 'TestStack');
Copy link
Contributor

Choose a reason for hiding this comment

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

How about making the stack name specific to this integ test? Because there are often other integ tests with stacks of the same name, which will fail if we try to run them in parallel.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I wasn't considering about the conflict with other stacks. Thanks for telling me.

Comment on lines 475 to 477
* For a multi-Region key, set to this property to true.
* For a single-Region key, omit this property or set it to false. The default value is false.
*
Copy link
Contributor

Choose a reason for hiding this comment

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

This is obvious and it is good to remove and simplify it.

Suggested change
* For a multi-Region key, set to this property to true.
* For a single-Region key, omit this property or set it to false. The default value is false.
*

Comment on lines 472 to 473
* Creates a multi-Region primary key that you can replicate in other AWS Regions.
* You can't change the MultiRegion value after the KMS key is created.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
* Creates a multi-Region primary key that you can replicate in other AWS Regions.
* You can't change the MultiRegion value after the KMS key is created.
* Creates a multi-Region primary key that you can replicate in other AWS Regions.
*
* You can't change the `multiRegion` value after the KMS key is created.

* For a multi-Region key, set to this property to true.
* For a single-Region key, omit this property or set it to false. The default value is false.
*
* IMPORTANT: If you change the value of the MultiRegion property on an existing KMS key, the update request fails,
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
* IMPORTANT: If you change the value of the MultiRegion property on an existing KMS key, the update request fails,
* IMPORTANT: If you change the value of the `multiRegion` property on an existing KMS key, the update request fails,

@@ -646,6 +646,17 @@ test('fails if key policy has no IAM principals', () => {
expect(() => app.synth()).toThrow(/A PolicyStatement used in a resource-based policy must specify at least one IAM principal/);
});

test('creates a multi-Region primary key', () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

It's good to keep it simple.

Suggested change
test('creates a multi-Region primary key', () => {
test('multi-region primary key', () => {

@aws-cdk-automation aws-cdk-automation removed the pr/needs-community-review This PR needs a review from a Trusted Community Member or Core Team Member. label Aug 15, 2024
@go-to-k
Copy link
Contributor

go-to-k commented Aug 15, 2024

@kawabata-mcl CI is failing, but this is caused by the previous snapshot file. Please try deleting the snapshot directory (integ.key-multi-region.js.snapshot) entirety and then running the integ test again.

@kawabata-mcl
Copy link
Contributor Author

@go-to-k Thanks for replying. I will run the integ test again and resubmit.

@kawabata-mcl
Copy link
Contributor Author

@go-to-k I pulled the latest version this morning and there were lots of diffs in packages/cdk-assets.
Looks like .gitignore was deleted and cause this problem.
This is a PR when .gitignore was deleted.
#31119
Is this the expected behavior?

kawabata@kawabata01:~/cdk-contribute/aws-cdk$ git pull
remote: Enumerating objects: 83, done.
remote: Counting objects: 100% (78/78), done.
remote: Compressing objects: 100% (58/58), done.
remote: Total 83 (delta 33), reused 53 (delta 18), pack-reused 5 (from 1)
Unpacking objects: 100% (83/83), 8.00 MiB | 4.55 MiB/s, done.
From https://github.com/kawabata-mcl/aws-cdk
910a7d3..08b3cff add-kms-multi-region-keys -> origin/add-kms-multi-region-keys
4bce941..9acd528 main -> origin/main
Updating 910a7d3..08b3cff
Fast-forward
.github/workflows/request-cli-integ-test.yml | 9 +-
lerna.json | 3 +-
package.json | 3 +-
.../test/aws-elasticloadbalancingv2-targets/test/integ.alb-listner-target.js.snapshot/IntegDefaultTestDeployAssert4E6713E1.assets.json | 19 ++
.../test/aws-elasticloadbalancingv2-targets/test/integ.alb-listner-target.js.snapshot/IntegDefaultTestDeployAssert4E6713E1.template.json | 36 +++
packages/@aws-cdk-testing/framework-integ/test/aws-elasticloadbalancingv2-targets/test/integ.alb-listner-target.js.snapshot/cdk.out | 1 +
packages/@aws-cdk-testing/framework-integ/test/aws-elasticloadbalancingv2-targets/test/integ.alb-listner-target.js.snapshot/integ.json | 12 +
packages/@aws-cdk-testing/framework-integ/test/aws-elasticloadbalancingv2-targets/test/integ.alb-listner-target.js.snapshot/manifest.json | 281 +++++++++++++++++++++
.../framework-integ/test/aws-elasticloadbalancingv2-targets/test/integ.alb-listner-target.js.snapshot/nlb-alb-listner-stack.assets.json | 19 ++
.../framework-integ/test/aws-elasticloadbalancingv2-targets/test/integ.alb-listner-target.js.snapshot/nlb-alb-listner-stack.template.json | 564 ++++++++++++++++++++++++++++++++++++++++++
packages/@aws-cdk-testing/framework-integ/test/aws-elasticloadbalancingv2-targets/test/integ.alb-listner-target.js.snapshot/tree.json | 984 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
packages/@aws-cdk-testing/framework-integ/test/aws-elasticloadbalancingv2-targets/test/integ.alb-listner-target.ts | 36 +++
packages/@aws-cdk/cli-lib-alpha/THIRD_PARTY_LICENSES | 10 +
packages/@aws-cdk/cloudformation-diff/package.json | 4 +-
packages/@aws-cdk/integ-runner/package.json | 4 +-
packages/aws-cdk-lib/.jsii.tabl.json.gz | Bin 0 -> 8011256 bytes
packages/aws-cdk-lib/aws-elasticloadbalancingv2-targets/lib/alb-target.ts | 53 +++-
packages/aws-cdk-lib/aws-elasticloadbalancingv2-targets/test/alb-target.test.ts | 31 +++
packages/aws-cdk-lib/aws-elasticloadbalancingv2/README.md | 2 +-
packages/aws-cdk-lib/aws-elasticloadbalancingv2/lib/alb/application-listener.ts | 6 +
packages/aws-cdk-lib/jest.config.js | 19 +-
packages/aws-cdk-lib/package.json | 2 +-
packages/aws-cdk/THIRD_PARTY_LICENSES | 10 +
packages/aws-cdk/package.json | 2 +-
packages/aws-cdk/tsconfig.json | 3 -
packages/cdk-assets/.eslintrc.js | 3 -
packages/cdk-assets/.gitignore | 28 ---
packages/cdk-assets/.npmignore | 30 ---
packages/cdk-assets/LICENSE | 201 ---------------
packages/cdk-assets/NOTICE | 2 -
packages/cdk-assets/README.md | 190 --------------
packages/cdk-assets/bin/cdk-assets | 2 -
packages/cdk-assets/bin/cdk-assets.ts | 67 -----
packages/cdk-assets/bin/docker-credential-cdk-assets | 2 -
packages/cdk-assets/bin/docker-credential-cdk-assets.ts | 42 ----
packages/cdk-assets/bin/list.ts | 9 -
packages/cdk-assets/bin/logging.ts | 24 --
packages/cdk-assets/bin/publish.ts | 56 -----
packages/cdk-assets/jest.config.js | 11 -
packages/cdk-assets/lib/asset-manifest.ts | 313 -----------------------
packages/cdk-assets/lib/aws.ts | 163 ------------
packages/cdk-assets/lib/index.ts | 4 -
packages/cdk-assets/lib/private/archive.ts | 92 -------
packages/cdk-assets/lib/private/asset-handler.ts | 38 ---
packages/cdk-assets/lib/private/docker-credentials.ts | 93 -------
packages/cdk-assets/lib/private/docker.ts | 279 ---------------------
packages/cdk-assets/lib/private/fs-extra.ts | 31 ---
packages/cdk-assets/lib/private/handlers/container-images.ts | 238 ------------------
packages/cdk-assets/lib/private/handlers/files.ts | 292 ----------------------
packages/cdk-assets/lib/private/handlers/index.ts | 15 --
packages/cdk-assets/lib/private/placeholders.ts | 34 ---
packages/cdk-assets/lib/private/shell.ts | 127 ----------
packages/cdk-assets/lib/private/util.ts | 12 -
packages/cdk-assets/lib/progress.ts | 86 -------
packages/cdk-assets/lib/publishing.ts | 256 -------------------
packages/cdk-assets/package.json | 82 -------
packages/cdk-assets/test/archive.test.ts | 94 -------
packages/cdk-assets/test/docker-images.test.ts | 706 ----------------------------------------------------
packages/cdk-assets/test/fake-listener.ts | 17 --
packages/cdk-assets/test/files.test.ts | 344 --------------------------
packages/cdk-assets/test/manifest.test.ts | 117 ---------
packages/cdk-assets/test/mock-aws.ts | 74 ------
packages/cdk-assets/test/mock-child_process.ts | 69 ------
packages/cdk-assets/test/placeholders.test.ts | 82 -------
packages/cdk-assets/test/private/docker-credentials.test.ts | 220 -----------------
packages/cdk-assets/test/private/docker.test.ts | 94 -------
packages/cdk-assets/test/progress.test.ts | 85 -------
packages/cdk-assets/test/test-archive-follow/data/one.txt | 1 -
packages/cdk-assets/test/test-archive-follow/linked/two.txt | 1 -
packages/cdk-assets/test/test-archive/executable.txt | 0
packages/cdk-assets/test/test-archive/file1.txt | 1 -
packages/cdk-assets/test/test-archive/file2.txt | 2 -
packages/cdk-assets/test/test-archive/subdir/file3.txt | 1 -
packages/cdk-assets/test/util.test.ts | 32 ---
packages/cdk-assets/test/zipping.test.ts | 53 ----
packages/cdk-assets/tsconfig.json | 28 ---
tools/@aws-cdk/pkglint/lib/rules.ts | 18 +-
tools/@aws-cdk/spec2cdk/package.json | 4 +-
yarn.lock | 104 ++++----
79 files changed, 2130 insertions(+), 4952 deletions(-)

@go-to-k
Copy link
Contributor

go-to-k commented Aug 16, 2024

@kawabata-mcl

Such things do happen from time to time, but they are irrelevant differences to this PR and can be discarded.

(Also, I just made another comment, which is my mistake. I have already removed that.)

@kawabata-mcl
Copy link
Contributor Author

kawabata-mcl commented Aug 16, 2024

@go-to-k
The problem was solved after deleting aws-assets folder and re-run yarn install for installing aws-assets.
I pushed another commit.

Copy link
Contributor

@go-to-k go-to-k 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 the changes.

@aws-cdk-automation aws-cdk-automation added the pr/needs-maintainer-review This PR needs a review from a Core Team Member label Aug 16, 2024
@GavinZZ
Copy link
Contributor

GavinZZ commented Aug 28, 2024

Love it, thanks @kawabata-mcl for the changes and thanks @go-to-k for the thorough reviews!

GavinZZ
GavinZZ previously approved these changes Aug 28, 2024
Copy link
Contributor

mergify bot commented Aug 28, 2024

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 aws-cdk-automation removed the pr/needs-maintainer-review This PR needs a review from a Core Team Member label Aug 28, 2024
Copy link
Contributor

mergify bot commented Aug 28, 2024

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 dismissed GavinZZ’s stale review August 28, 2024 16:26

Pull request has been modified.

@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

  • CodeBuild project: AutoBuildv2Project1C6BFA3F-wQm2hXv2jqQv
  • Commit ID: 86132a5
  • 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 Aug 28, 2024

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 3dc4c50 into aws:main Aug 28, 2024
11 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 Aug 28, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
beginning-contributor [Pilot] contributed between 0-2 PRs to the CDK p2
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants