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(integ-tests): apply correct IAM policy to waiterProvider #28424

Merged
merged 8 commits into from Dec 20, 2023

Conversation

sakurai-ryo
Copy link
Contributor

@sakurai-ryo sakurai-ryo commented Dec 19, 2023

Description

The following issue describes a bug where the IAM Policy is not correctly set to the calling Lambda when using invokeFunction and waitForAssertions.

Normally, when the waitForAssertions method is invoked, the necessary Policy is granted to the waiterProvider using the adPolicyStatementFromSdkCall method.

waiter.isCompleteProvider.addPolicyStatementFromSdkCall(this.service, this.api);

In the case of a Lambda function call, the API name and the Action name of the Policy are different (invoke => invokeFunction), so the addPolicyStatementFromSdkCall method cannot grant the correct Policy.
The LambdaInvokeFunction is doing the correct Policy assignment to deal with this in the constructor.

this.provider.addPolicyStatementFromSdkCall('Lambda', 'invokeFunction', [stack.formatArn({

However, this is not done for the waiterProvider, resulting in an access denied error.
This PR has been modified so that the correct Policy is granted to waiterProvider.

fixes #27865


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 19, 2023 12:26
@github-actions github-actions bot added bug This issue is a bug. effort/medium Medium work item – several days of effort p1 valued-contributor [Pilot] contributed between 6-12 PRs to the CDK labels Dec 19, 2023
@@ -250,6 +250,19 @@ export class LambdaInvokeFunction extends AwsApiCall {
arnFormat: ArnFormat.COLON_RESOURCE_NAME,
resourceName: props.functionName,
})]);

// If using `waitForAssertions`, do the same for `waiterProvider` as above.
Aspects.of(this).add({
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The Resource-based policy for Lambda is created in the part shown in the link, but it is not created here because invoking Lambda from Lambda is possible if the appropriate Policy is granted to the execution role of the invoking Lambda.

new CfnResource(this, 'Invoke', {

If you have any concerns, I would really appreciate it if you could let me know.

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm fine with this but -- can you document why you've used an Aspect so that others who stumble on your code will understand the decision please

@sakurai-ryo sakurai-ryo marked this pull request as ready for review December 19, 2023 13:10
@aws-cdk-automation aws-cdk-automation added the pr/needs-maintainer-review This PR needs a review from a Core Team Member label Dec 19, 2023
Copy link
Contributor

@kaizencc kaizencc left a comment

Choose a reason for hiding this comment

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

Thanks @sakurai-ryo! Some really minor comments but this looks good!

@@ -250,6 +250,19 @@ export class LambdaInvokeFunction extends AwsApiCall {
arnFormat: ArnFormat.COLON_RESOURCE_NAME,
resourceName: props.functionName,
})]);

// If using `waitForAssertions`, do the same for `waiterProvider` as above.
Aspects.of(this).add({
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm fine with this but -- can you document why you've used an Aspect so that others who stumble on your code will understand the decision please

Copy link
Contributor

Choose a reason for hiding this comment

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

Lets document here that what we are trying to verify is that Lambda.InvokeFunction exists in the integ assertions stack, not in the actual stack that is getting "tested"

@aws-cdk-automation aws-cdk-automation removed the pr/needs-maintainer-review This PR needs a review from a Core Team Member label Dec 19, 2023
@mergify mergify bot dismissed kaizencc’s stale review December 20, 2023 11:15

Pull request has been modified.

@sakurai-ryo
Copy link
Contributor Author

@kaizencc
Thanks again for your review!
As for the comments on the integ-tests part, I'm sorry if I misunderstood what you were saying, but I've added docs to sdk.ts and the integ-test file.

@aws-cdk-automation aws-cdk-automation added the pr/needs-maintainer-review This PR needs a review from a Core Team Member label Dec 20, 2023
Copy link
Contributor

@kaizencc kaizencc left a comment

Choose a reason for hiding this comment

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

Perfect, thanks @sakurai-ryo

Copy link
Contributor

mergify bot commented Dec 20, 2023

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 aws-cdk-automation removed the pr/needs-maintainer-review This PR needs a review from a Core Team Member label Dec 20, 2023
@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

  • CodeBuild project: AutoBuildv2Project1C6BFA3F-wQm2hXv2jqQv
  • Commit ID: 1844e3c
  • 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 c488035 into aws:main Dec 20, 2023
12 checks passed
Copy link
Contributor

mergify bot commented Dec 20, 2023

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

paulhcsun pushed a commit to paulhcsun/aws-cdk that referenced this pull request Jan 5, 2024
### Description
The following issue describes a bug where the IAM Policy is not correctly set to the calling Lambda when using `invokeFunction` and `waitForAssertions`.

Normally, when the `waitForAssertions` method is invoked, the necessary Policy is granted to the `waiterProvider` using the `adPolicyStatementFromSdkCall` method.
https://github.com/aws/aws-cdk/blob/52a5579aa52c88bb289a7a9677c35385763c8fff/packages/%40aws-cdk/integ-tests-alpha/lib/assertions/sdk.ts#L136

In the case of a Lambda function call, the API name and the Action name of the Policy are different (invoke => invokeFunction), so the `addPolicyStatementFromSdkCall` method cannot grant the correct Policy.
The `LambdaInvokeFunction` is doing the correct Policy assignment to deal with this in the constructor.
https://github.com/aws/aws-cdk/blob/52a5579aa52c88bb289a7a9677c35385763c8fff/packages/%40aws-cdk/integ-tests-alpha/lib/assertions/sdk.ts#L247

However, this is not done for the `waiterProvider`, resulting in an access denied error.
This PR has been modified so that the correct Policy is granted to `waiterProvider`.

fixes aws#27865

----

*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
bug This issue is a bug. effort/medium Medium work item – several days of effort p1 valued-contributor [Pilot] contributed between 6-12 PRs to the CDK
Projects
None yet
Development

Successfully merging this pull request may close these issues.

@aws-cdk/integ-tests-alpha: (Integ-test's does not have the proper role permission)
3 participants