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

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

Merged
merged 4 commits into from
Jul 16, 2021

Conversation

rix0rrr
Copy link
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

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
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
}
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 how production software looks like!

Copy link
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
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
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
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
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.

None yet

4 participants