Skip to content

chore(kms): cross-stack usage detection depends on NPM tree#15580

Merged
mergify[bot] merged 4 commits intomasterfrom
huijbers/fix-xstack-kms
Jul 16, 2021
Merged

chore(kms): cross-stack usage detection depends on NPM tree#15580
mergify[bot] merged 4 commits intomasterfrom
huijbers/fix-xstack-kms

Conversation

@rix0rrr
Copy link
Copy Markdown
Contributor

@rix0rrr rix0rrr commented Jul 15, 2021

KMS keys try to be smart about not generating impossible dependencies
between multiple stacks, which CodePipeline takes advantage of for
its support stacks.

However, because the logic that tests for this case has an instanceof Construct in its code path, if there are ever multiple copies of the
constructs library in the NPM tree the test will fail, and the
resulting error will be very confusing.

This situation can arise when people flip back and forth between
CDK v1 and v2, because package-lock.json will contain half-baked
dependency trees; people will be looking at their code but the issue
will be in invisible state.

Be more liberal in detecting that a construct is, in fact, a construct
to get around this.


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

KMS keys try to be smart about not generating impossible dependencies
between multiple stacks, which CodePipeline takes advantage of for
its support stacks.

However, because the logic that tests for this case has an `instanceof
Construct` in its code path, if there are ever multiple copies of the
`constructs` library in the NPM tree the test will fail, and the
resulting error will be very confusing.

This situation can arise when people flip back and forth between
CDK v1 and v2, because `package-lock.json` will contain half-baked
dependency trees; people will be looking at their code but the issue
will be in invisible state.

Be more liberal in detecting that a construct is, in fact, a construct
to get around this.
@rix0rrr rix0rrr requested a review from a team July 15, 2021 16:59
@rix0rrr rix0rrr self-assigned this Jul 15, 2021
@gitpod-io
Copy link
Copy Markdown

gitpod-io bot commented Jul 15, 2021

@mergify mergify bot added the contribution/core This is a PR that came from AWS. label Jul 15, 2021
* multiple copies of the `constructs` library on disk. This can happen
* when upgrading and downgrading between v2 and v1, and in the use of CDK
* Pipelines is going to an error that says "Can't use Pipeline/Pipeline/Role in
* a cross-environment fahsion", which is very confusing.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

fashion

Comment on lines +688 to +694
function isConstruct(x: any): x is Construct {
const sym = Symbol.for('constructs.Construct.node');
return (typeof x === 'object' && x &&
(x instanceof Construct // happy fast case
|| !!(x as Construct).node // constructs v10
|| !!(x as any)[sym])); // constructs v3
} No newline at end of file
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This is how production software looks like!

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Should we move this to the constructs library? Feels like it might be a better place to put this code, no?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

For sure. Don't forget to add it to both versions :)

@mergify
Copy link
Copy Markdown
Contributor

mergify bot commented Jul 16, 2021

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).

@aws-cdk-automation
Copy link
Copy Markdown
Collaborator

AWS CodeBuild CI Report

  • CodeBuild project: AutoBuildProject89A8053A-LhjRyN9kxr8o
  • Commit ID: 85f54f2
  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

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

@mergify mergify bot merged commit a0f00e8 into master Jul 16, 2021
@mergify mergify bot deleted the huijbers/fix-xstack-kms branch July 16, 2021 08:53
@mergify
Copy link
Copy Markdown
Contributor

mergify bot commented Jul 16, 2021

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).

TikiTDO pushed a commit to TikiTDO/aws-cdk that referenced this pull request Aug 3, 2021
KMS keys try to be smart about not generating impossible dependencies
between multiple stacks, which CodePipeline takes advantage of for
its support stacks.

However, because the logic that tests for this case has an `instanceof
Construct` in its code path, if there are ever multiple copies of the
`constructs` library in the NPM tree the test will fail, and the
resulting error will be very confusing.

This situation can arise when people flip back and forth between
CDK v1 and v2, because `package-lock.json` will contain half-baked
dependency trees; people will be looking at their code but the issue
will be in invisible state.

Be more liberal in detecting that a construct is, in fact, a construct
to get around this.


----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
hollanddd pushed a commit to hollanddd/aws-cdk that referenced this pull request Aug 26, 2021
KMS keys try to be smart about not generating impossible dependencies
between multiple stacks, which CodePipeline takes advantage of for
its support stacks.

However, because the logic that tests for this case has an `instanceof
Construct` in its code path, if there are ever multiple copies of the
`constructs` library in the NPM tree the test will fail, and the
resulting error will be very confusing.

This situation can arise when people flip back and forth between
CDK v1 and v2, because `package-lock.json` will contain half-baked
dependency trees; people will be looking at their code but the issue
will be in invisible state.

Be more liberal in detecting that a construct is, in fact, a construct
to get around this.


----

*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

contribution/core This is a PR that came from AWS.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants