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(pipeline): allow enabling KMS key rotation for cross-region-stacks #14381

Closed
wants to merge 18 commits into from

Conversation

hross-frae
Copy link

@hross-frae hross-frae commented Apr 26, 2021

Enabling KMS Key rotation for cross-region-stacks as it is a recommended best practice.
https://docs.aws.amazon.com/kms/latest/developerguide/rotate-keys.html

In #13466 it was considered not necessary due to extra costs, but I don't think that reason applies in this use case due to the following reasons:

  • There is already extra cost due to the use of codebuild and pipelines, an extra $1/month a year will not greatly affect overall costs
  • Cross account/region imply advanced deployments which would already incur extra costs, so similar to above, the extra costs could be considered negligible.
  • For simple one account and region deployments, this extra cost would not be applicable.

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

@gitpod-io
Copy link

gitpod-io bot commented Apr 26, 2021

@github-actions github-actions bot added the @aws-cdk/aws-kms Related to AWS Key Management label Apr 26, 2021
@njlynch njlynch added @aws-cdk/pipelines CDK Pipelines library @aws-cdk/aws-codepipeline Related to AWS CodePipeline and removed @aws-cdk/pipelines CDK Pipelines library labels Apr 26, 2021
@mergify mergify bot dismissed rix0rrr’s stale review April 26, 2021 16:51

Pull request has been modified.

Copy link
Contributor

@skinny85 skinny85 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 contribution @hross-frae!

A few minor comments, mainly about naming.

@skinny85
Copy link
Contributor

Also - unit tests are missing 😉.

@mergify mergify bot dismissed skinny85’s stale review April 27, 2021 16:21

Pull request has been modified.

Copy link
Contributor

@skinny85 skinny85 left a comment

Choose a reason for hiding this comment

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

Looks great @hross-frae! A few minor comments before I merge this in.

@skinny85 skinny85 changed the title feat(pipeline): enable KMS key rotation for cross-region-stacks feat(pipeline): allow enabling KMS key rotation for cross-region-stacks Apr 29, 2021
@gitpod-io
Copy link

gitpod-io bot commented May 10, 2021

@mergify mergify bot dismissed skinny85’s stale review May 10, 2021 16:39

Pull request has been modified.

@hross-frae
Copy link
Author

hross-frae commented May 17, 2021

@skinny85 it's only existing unit tests that are failing now. When I try update them there are some that are deleted snapshot files that are deleted. Is that expected? I've been running full builds and tests

@skinny85
Copy link
Contributor

@hross-frae I'm not sure what you're asking, but because you implemented my comment from here: #14381 (comment) , the generated CloudFormation template will remain exactly the same as it is now.

The build currently is failing on the @aws-cdk/aws-events-targets package:

@aws-cdk/aws-events-targets: Verifying codepipeline/integ.pipeline-event-target.js against codepipeline/integ.pipeline-event-target.expected.json ... CHANGED.
@aws-cdk/aws-events-targets: Resources
@aws-cdk/aws-events-targets: [~] AWS::KMS::Key pipelinePipeline22F2A91DArtifactsBucketEncryptionKey87C796D2 
@aws-cdk/aws-events-targets:  └─ [-] EnableKeyRotation
@aws-cdk/aws-events-targets:      └─ false

If you revert the change you made to the integ.pipeline-event-target.expected.json file, the build should pass again (same comment about the other changes to the "expected" files).

@lukasbuerkle
Copy link

please merge, so that i can satisfy my security hub. thank you.

@njlynch njlynch assigned skinny85 and unassigned njlynch Jun 7, 2021
@skinny85
Copy link
Contributor

skinny85 commented Jun 7, 2021

please merge, so that i can satisfy my security hub. thank you.

Can't really merge it if the build is failing, unfortunately.

@skinny85 skinny85 removed their assignment Jun 22, 2021
@skinny85 skinny85 added effort/small Small work item – less than a day of effort p1 labels Jun 22, 2021
@ericzbeard ericzbeard modified the milestone: [GA] CDK Pipelines Jun 29, 2021
@pboeder
Copy link
Contributor

pboeder commented Sep 9, 2021

Would be awesome to merge this PR. Unfortunately, my known workarounds for enabling KeyRotation don't work anymore with the recent v2 RCs.
Do I understand it correctly, that the only missing piece is to "revert the change you made to the integ.pipeline-event-target.expected.json file" @skinny85?
Since @hross-frae doesn't seem to respond anymore, is there any strategy on how to proceed with this PR?

@hross-frae
Copy link
Author

Hi @ppuritscher, the main issue I can up against in the end was getting all the tests working...
As far as I can tell the code changes are all good, they might be a little out of date though. Also there might have to further changes added now due to the new CodePipeline construct

@pboeder
Copy link
Contributor

pboeder commented Sep 9, 2021

Hi @hross-frae, thanks for the update and your work there!
Are you sure, that there are any further changes required for now, concerning the new CodePipeline construct?

I assume that you already checked the suggestion of @skinny85 ("revert the change you made to the integ.pipeline-event-target.expected.json file")?

Would it be possible for you to give git rebase a try?

@skinny85
Copy link
Contributor

@ppuritscher you should be able to take this PR over if you want to (it's just a matter of getting the code from https://github.com/hross-frae/aws-cdk, the master branch, and you can then edit locally, and either push directly to @hross-frae's fork, or open a new PR).

@renner-daniel
Copy link

renner-daniel commented Sep 10, 2021

I created a PR hross-frae#1
@hross-frae can you pleas accept the PR? I checked the tests in @aws-cdk/aws-events-targets and reverted one change there. Tests ran green afterwards. I also checked the pipeline tests, but I did not check every single test (I takes too much time to be honest :D ), so lets see if CodeBuild runs green this time.

@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

  • CodeBuild project: AutoBuildProject89A8053A-LhjRyN9kxr8o
  • Commit ID: 8746ac0
  • Result: FAILED
  • Build Logs (available for 30 days)

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

@renner-daniel
Copy link

Ok, the other tests fail as well.
@skinny85 its not clear to me why the key is not published in the tests? I mean I can remove the added property in the json testfiles, but shouldn't the key be propagated?

@renner-daniel
Copy link

renner-daniel commented Sep 10, 2021

Ah ok, I think I found the "problem":

 const resource = new CfnKey(this, 'Resource', {
      description: props.description,
      enableKeyRotation: props.enableKeyRotation,
      enabled: props.enabled,
      keySpec: props.keySpec,
      keyUsage: props.keyUsage,
      keyPolicy: this.policy,
      pendingWindowInDays: pendingWindowInDays,
});

this.keyArn = resource.attrArn;

You build now a keyArn with all necessary information (as far as I understand). That means we cant search for enableKeyRotation in the resulting json.
I'm going to create a new PR and remove all the enableKeyRotation to fix the tests.

@pboeder
Copy link
Contributor

pboeder commented Sep 13, 2021

Hey @hross-frae, @renner-daniel and @skinny85!
I just created a new PR as successor. The tests run through.

@hross-frae
Copy link
Author

Hey @hross-frae, @renner-daniel and @skinny85!
I just created a new PR as successor. The tests run through.

Thanks @ppuritscher for picking this up and following it through. I'll close this PR as it's no longer needed

@hross-frae hross-frae closed this Sep 16, 2021
mergify bot pushed a commit that referenced this pull request Sep 20, 2021
…ks (#16468)

As suggested by @skinny85 I created an updated PR as successor of #14381

How does it work for v2. Do I need to create another PR for `v2-main`?

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@aws-cdk/aws-codepipeline Related to AWS CodePipeline @aws-cdk/aws-kms Related to AWS Key Management effort/small Small work item – less than a day of effort p1
Projects
None yet
Development

Successfully merging this pull request may close these issues.