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

fix(bootstrap): no longer creates KMS master key by default #10365

Merged
merged 5 commits into from
Sep 17, 2020

Conversation

rix0rrr
Copy link
Contributor

@rix0rrr rix0rrr commented Sep 15, 2020

The modern bootstrap stack used to unconditionally create a KMS Customer
Master Key (CMK) for users. This incurs a $1/month charge for every user
of the CDK for every region and account they want to deploy in, which is
not acceptable if we're going to make this the default bootstrapping
experience in the future.

This PR switches off the creation of the CMK by default for new
bootstrap stacks. Bootstrap stacks that already exist can remove the
existing CMK by running:

cdk bootstrap --bootstrap-customer-key=false [aws://...]

This change is backwards compatible: updates to existing (modern)
bootstrap stacks will leave the current KMS key in place. To achieve
this, the new default is encoded into the CLI, not into the template.

Fixes #10115.


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

The modern bootstrap stack used to unconditionally create a KMS Customer
Master Key (CMK) for users. This incurs a $1/month charge for every user
of the CDK for every region and account they want to deploy in, which is
not acceptable if we're going to make this the default bootstrapping
experience in the future.

This PR switches off the creation of the CMK by default for new
bootstrap stacks. Bootstrap stacks that already exist can remove the
existing CMK by running:

```
cdk bootstrap --bootstrap-customer-key=false [aws://...]
```

This change is backwards compatible: updates to existing (modern)
bootstrap stacks will leave the current KMS key in place. To achieve
this, the new default is encoded into the CLI, not into the template.

Fixes #10115.
@rix0rrr rix0rrr requested review from skinny85, njlynch and a team September 15, 2020 13:36
@rix0rrr rix0rrr self-assigned this Sep 15, 2020
@mergify mergify bot added the contribution/core This is a PR that came from AWS. label Sep 15, 2020
@hoegertn
Copy link
Contributor

Are there any downsides of using the default S3 key? Is there any cross-account access needed or policies that are not possible with AWS managed CMKs?

@rix0rrr rix0rrr added the pr/do-not-merge This PR should not be merged at this time. label Sep 16, 2020
@rix0rrr
Copy link
Contributor Author

rix0rrr commented Sep 16, 2020

Are there any downsides of using the default S3 key? Is there any cross-account access needed or policies that are not possible with AWS managed CMKs?

Not for this key, no. For the keys that are created as part of the Pipeline, yes. I'm working on a separate PR there.

Copy link
Contributor

@njlynch njlynch left a comment

Choose a reason for hiding this comment

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

Looks good to me; two nitpicks.

/**
* Magic parameter value that will cause the bootstrap-template.yml to NOT create a CMK but use the default keyo
*/
const USE_AWS_MANAGED_KEY = '-';
Copy link
Contributor

Choose a reason for hiding this comment

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

~ Any reason not to make this a little less magical? Like

Suggested change
const USE_AWS_MANAGED_KEY = '-';
const USE_AWS_MANAGED_KEY = 'USE_AWS_MANAGED_KEY';

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 guess not!

Comment on lines 110 to 113
const kmsKeyId = params.kmsKeyId ??
(params.createCustomerMasterKey === true ? '' :
params.createCustomerMasterKey === false ? USE_AWS_MANAGED_KEY :
current.parameters.FileAssetsBucketKmsKeyId !== undefined ? undefined : USE_AWS_MANAGED_KEY);
Copy link
Contributor

Choose a reason for hiding this comment

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

~ Take or leave it, but removed a ternary, defined a new constant, and got this:

Suggested change
const kmsKeyId = params.kmsKeyId ??
(params.createCustomerMasterKey === true ? '' :
params.createCustomerMasterKey === false ? USE_AWS_MANAGED_KEY :
current.parameters.FileAssetsBucketKmsKeyId !== undefined ? undefined : USE_AWS_MANAGED_KEY);
const currentKmsKeyId = current.parameters.FileAssetsBucketKmsKeyId;
const kmsKeyId = params.kmsKeyId ??
(params.createCustomerMasterKey ? CREATE_CMK
: (params.createCustomerMasterKey === false || currentKmsKeyId === undefined)
? USE_AWS_MANAGED_KEY : undefined);

@rix0rrr rix0rrr removed the pr/do-not-merge This PR should not be merged at this time. label Sep 17, 2020
@rix0rrr
Copy link
Contributor Author

rix0rrr commented Sep 17, 2020

Tested to work with x-account and x-account/x-region pipeline

@mergify
Copy link
Contributor

mergify bot commented Sep 17, 2020

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

@mergify
Copy link
Contributor

mergify bot commented Sep 17, 2020

Thank you for contributing! Your pull request will be updated from master 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 bedd4c0 into master Sep 17, 2020
@mergify mergify bot deleted the huijbers/bootstrap-no-cmk branch September 17, 2020 10:16
@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

  • CodeBuild project: AutoBuildProject6AEA49D1-qxepHUsryhcu
  • Commit ID: 5b372bb
  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
contribution/core This is a PR that came from AWS.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

CDKToolkit stack with newStyleStackSynthesis creates CMK that costs 1USD/month
4 participants