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: prevent cyclic dependencies created by custom resource provider #32404

Closed
wants to merge 1 commit into from

Conversation

swachter
Copy link

@swachter swachter commented Dec 6, 2024

Reason for this change

If both, the isCompleteHandler and the role is set in custom resource ProviderProps then a resource dependencies cycle results.

If role is specified then that role is used for all 3 framework lambdas (i.e. onEventFunction, isCompleteFunction, and timeoutFunction). In order to grant additional required permissions to these functions, a policy is created under the hood. That policy is called DefaultPolicy.

The DefaultPolicy is attached to the given role and includes the lambda:InvokeFunction permissions for the two handler functions (onEventHandler and isCompleteHandler). In addition, the DefaultPolicy includes the states:StartExecution permission that is granted to the onEventFunction by the call `waiterStateMachine.grantStartExecution(onEventFunction);.

This results in the following dependencies cycle:

waiter state machine --(via its description)--> isCompleteFunction / timeoutFunction --(via explicits dependsOn)--> DefaultPolicy --(via resource constraint)--> waiter state machine

If the resource constraint is dropped from the states:StartExecution grant then the cyclic dependency is cut.

Description of changes

Drop the resource constraint from the states:StartExecution grant if an execution role for the framework lambdas is specified.

Description of how you validated changes

I tried the following workaround locally:

(role as any).node._children.DefaultPolicy.document.statements[1] = new PolicyStatement({
    actions: ['states:StartExecution'],
    resources: ['*']
});

This workaround applies the proposed modification to the created DefaultPolicy.

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 December 6, 2024 14:36
@github-actions github-actions bot added p2 beginning-contributor [Pilot] contributed between 0-2 PRs to the CDK labels Dec 6, 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 fails with the following errors:

❌ Fixes must contain a change to an integration test file and the resulting snapshot.

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.

✅ A exemption request has been requested. Please wait for a maintainer's review.

@swachter
Copy link
Author

swachter commented Dec 6, 2024

Clarification Request

There seems to exist no integration test for custom resource providers.

@aws-cdk-automation aws-cdk-automation added the pr/reviewer-clarification-requested The contributor has requested clarification on feedback, a failing build, or a failing PR Linter run label Dec 6, 2024
@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

  • CodeBuild project: AutoBuildv2Project1C6BFA3F-wQm2hXv2jqQv
  • Commit ID: 763b0f2
  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

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

@aws-cdk-automation aws-cdk-automation added the pr/needs-community-review This PR needs a review from a Trusted Community Member or Core Team Member. label Dec 6, 2024
@aws-cdk-automation
Copy link
Collaborator

This PR has been in the CHANGES REQUESTED state for 3 weeks, and looks abandoned. To keep this PR from being closed, please continue work on it. If not, it will automatically be closed in a week.

@swachter
Copy link
Author

Exemption Request
There seem to be no integration tests for custom resource providers.

@aws-cdk-automation aws-cdk-automation added the pr-linter/exemption-requested The contributor has requested an exemption to the PR Linter feedback. label Dec 28, 2024
@aws-cdk-automation
Copy link
Collaborator

The pull request linter fails with the following errors:

❌ Fixes must contain a change to an integration test file and the resulting snapshot.

PRs must pass status checks before we can provide a meaningful review.

If you would like to request an exemption from the status checks or clarification on feedback, please leave a comment on this PR containing Exemption Request and/or Clarification Request.

✅ A exemption request has been requested. Please wait for a maintainer's review.

Copy link
Contributor

@GavinZZ GavinZZ left a comment

Choose a reason for hiding this comment

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

Hello, thanks for drafting this PR. I'd like to understand what issue were you seeing prior to this change. Is the cyclic dependency causing the deployment to fail?

@GavinZZ GavinZZ added pr-linter/exempt-test The PR linter will not require test changes and removed pr-linter/exemption-requested The contributor has requested an exemption to the PR Linter feedback. pr/reviewer-clarification-requested The contributor has requested clarification on feedback, a failing build, or a failing PR Linter run labels Jan 22, 2025
@aws-cdk-automation aws-cdk-automation removed the pr/needs-community-review This PR needs a review from a Trusted Community Member or Core Team Member. label Jan 22, 2025
@StefanWachter1507
Copy link

Yes, the deployment fails with a cyclic dependency error.

@aws-cdk-automation
Copy link
Collaborator

This PR has been deemed to be abandoned, and will be automatically closed. Please create a new PR for these changes if you think this decision has been made in error.

@aws-cdk-automation aws-cdk-automation added the closed-for-staleness This issue was automatically closed because it hadn't received any attention in a while. label Jan 23, 2025
Copy link

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 Jan 23, 2025
@GavinZZ GavinZZ reopened this Jan 23, 2025
@aws aws unlocked this conversation Jan 23, 2025
Copy link

codecov bot commented Jan 23, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 66.63%. Comparing base (c78ef1b) to head (763b0f2).
Report is 367 commits behind head on main.

Additional details and impacted files
@@             Coverage Diff             @@
##             main   #32404       +/-   ##
===========================================
- Coverage   78.66%   66.63%   -12.03%     
===========================================
  Files         107      332      +225     
  Lines        7237    18965    +11728     
  Branches     1329     3301     +1972     
===========================================
+ Hits         5693    12638     +6945     
- Misses       1358     6001     +4643     
- Partials      186      326      +140     
Flag Coverage Δ
suite.unit 66.63% <ø> (-12.03%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Components Coverage Δ
packages/aws-cdk 79.92% <ø> (+1.25%) ⬆️

@GavinZZ
Copy link
Contributor

GavinZZ commented Jan 23, 2025

Thanks for the quick response. I think this is a great place to add an integ test to make sure now it's deployable if we supply a custom role property. The provider module doesn't have integ test directly because it's usually coupled with other modules that use the custom resource provider. I'd like to request to add an integ test if you can and feel free to ping me if you need help with the integ test.

@StefanWachter1507
Copy link

Unfortunately, I have no clue how an integration test for a custom resource provider could be set up. I would appreciate your help a lot.

@aws-cdk-automation
Copy link
Collaborator

This PR has been deemed to be abandoned, and will be automatically closed. Please create a new PR for these changes if you think this decision has been made in error.

Copy link

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 Jan 24, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
beginning-contributor [Pilot] contributed between 0-2 PRs to the CDK closed-for-staleness This issue was automatically closed because it hadn't received any attention in a while. p2 pr-linter/exempt-test The PR linter will not require test changes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants