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(core): throw on intrinsics in CFN update and create policies #31578

Merged
merged 20 commits into from
Oct 3, 2024

Conversation

comcalvi
Copy link
Contributor

@comcalvi comcalvi commented Sep 26, 2024

Issue # (if applicable)

Closes #27578, Closes #30740.

Reason for this change

cfn-include only allows Intrinsics in resource update and create policies to wrap primitive values. If Intrinsics are included anywhere else, cfn-include silently drops them.

CDK's type system does not allow intrinsics in resource policies unless they define a primitive value. cfn-include adheres to this type system and drops any resource policies that use an intrinsic to define a complex value. This is an example of a forbidden use of intrinsics:

  "Resources": {
    "ResourceSignalIntrinsic": {
     // ....
      "CreationPolicy": {
        "ResourceSignal": {
          "Fn::If": [
            "UseCountParameter",
            {
              "Count": { "Ref": "CountParameter" }
            },
            5
          ]
        }
      }
    }
  }
}

This is forbidden because an intrinsic contains the Count property of this policy. CFN allows this, but CDK's type system does not permit it.

Description of changes

cfn-include will throw if any intrinsics break the type system, instead of silently dropping them.

CDK's type system is a useful constraint around these resource update / create policies because it allows constructs that modify them, like autoscaling, to not be token-aware. Tokens are not resolved at synthesis time, so it makes it impossible to modify these with simple arithmetic if they contain tokens.

The CDK will never (or at least should not) generate a token that breaks this type system.

Thus, the only use-case for allowing these tokens is cfn-include. Supporting these customers would require the CDK type system to allow these, and thus CDK L2s should handle such cases; except, for L2 customers, this use-case does not happen. Explicitly reject templates that don't conform to this.

Throwing here is a breaking change, so this is under a feature flag.

Additionally add a new property, dehydratedResources -- a list of logical IDs that cfn-include will not parse. Those resources still exist in the final template.

This does not impact L2 users.

Description of how you validated changes

Unit testing.

Manually verified that this does not impact any L2s.

Checklist


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

@aws-cdk-automation aws-cdk-automation requested a review from a team September 26, 2024 19:01
@github-actions github-actions bot added the p2 label Sep 26, 2024
@mergify mergify bot added the contribution/core This is a PR that came from AWS. label Sep 26, 2024
Copy link
Collaborator

@aws-cdk-automation aws-cdk-automation left a comment

Choose a reason for hiding this comment

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

The pull request linter has failed. See the aws-cdk-automation comment below for failure reasons. If you believe this pull request should receive an exemption, please comment and provide a justification.

A comment requesting an exemption should contain the text Exemption Request. Additionally, if clarification is needed add Clarification Request to a comment.

@comcalvi comcalvi added the pr-linter/exempt-integ-test The PR linter will not require integ test changes label Sep 26, 2024
@comcalvi comcalvi marked this pull request as ready for review September 26, 2024 20:34
@aws-cdk-automation aws-cdk-automation dismissed their stale review September 26, 2024 20:34

✅ Updated pull request passes all PRLinter validations. Dismissing previous PRLinter review.

@comcalvi comcalvi added p1 and removed pr-linter/exempt-integ-test The PR linter will not require integ test changes p2 labels Sep 26, 2024
Copy link
Collaborator

@aws-cdk-automation aws-cdk-automation left a comment

Choose a reason for hiding this comment

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

The pull request linter has failed. See the aws-cdk-automation comment below for failure reasons. If you believe this pull request should receive an exemption, please comment and provide a justification.

A comment requesting an exemption should contain the text Exemption Request. Additionally, if clarification is needed add Clarification Request to a comment.

@rix0rrr rix0rrr added the pr/do-not-merge This PR should not be merged at this time. label Sep 27, 2024
@comcalvi comcalvi added the pr-linter/exempt-integ-test The PR linter will not require integ test changes label Sep 30, 2024
@aws-cdk-automation aws-cdk-automation dismissed their stale review September 30, 2024 21:02

✅ Updated pull request passes all PRLinter validations. Dismissing previous PRLinter review.

@comcalvi comcalvi removed the pr/do-not-merge This PR should not be merged at this time. label Oct 3, 2024
@comcalvi comcalvi added the pr/do-not-merge This PR should not be merged at this time. label Oct 3, 2024
@github-actions github-actions bot added bug This issue is a bug. effort/medium Medium work item – several days of effort labels Oct 3, 2024
@comcalvi comcalvi removed the pr/do-not-merge This PR should not be merged at this time. label Oct 3, 2024
Copy link
Contributor

mergify bot commented Oct 3, 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
Copy link
Collaborator

AWS CodeBuild CI Report

  • CodeBuild project: AutoBuildv2Project1C6BFA3F-wQm2hXv2jqQv
  • Commit ID: 6545b91
  • 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 9410361 into main Oct 3, 2024
12 checks passed
Copy link
Contributor

mergify bot commented Oct 3, 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 deleted the comcalvi/cfn-include-drops-stuff branch October 3, 2024 19:09
Copy link

github-actions bot commented Oct 3, 2024

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 Oct 3, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug This issue is a bug. contribution/core This is a PR that came from AWS. effort/medium Medium work item – several days of effort p1 pr-linter/exempt-integ-test The PR linter will not require integ test changes
Projects
None yet
3 participants