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(stepfunctions-tasks): in-flight stepfunction executions fail on update of versioned lambdas #21233

Conversation

mrgrain
Copy link
Contributor

@mrgrain mrgrain commented Jul 19, 2022

When the Step Function task is invoking a Lambda Version, we used to only grant invoke permissions for the specific Version. This can cause in-flight executions of the Step Function to fail due to missing permissions, since changing the referenced Version would cause the Policy to remove permissions for the previous Version - which is currently in-flight.

The fix here is to add invokeFunction permissions for all qualifiers of the Lambda Function whenever a Version is provided. While this is not ideal, it enables users to safely update Lambda Versions with LambdaInvoke. I believe this is a common enough use case to warrant this fix.

However, it's worth noting that the same issue will still occur if e.g. the Function is updated to a completely different one or an Alias is changed.

fixes #17515


All Submissions:

Adding new Unconventional Dependencies:

  • This PR adds new unconventional dependencies following the process described here

New Features

  • Have you added the new feature to an integration test?
    • Did you use yarn integ to deploy the infrastructure and generate the snapshot (i.e. yarn integ without --dry-run)?

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

@gitpod-io
Copy link

gitpod-io bot commented Jul 19, 2022

@github-actions github-actions bot added bug This issue is a bug. effort/small Small work item – less than a day of effort p1 labels Jul 19, 2022
@aws-cdk-automation aws-cdk-automation requested a review from a team July 19, 2022 15:13
@mergify mergify bot added the contribution/core This is a PR that came from AWS. label Jul 19, 2022
@mrgrain mrgrain force-pushed the fix/stepfunctions-tasks/lambda-versions-permissions branch from e2c5a4c to 2038466 Compare July 19, 2022 16:57
@mrgrain mrgrain changed the title fix(stepfunction-tasks): grant step functions task permissions to invoke all versions of a lambda function fix(stepfunctions-tasks): grant step functions task permissions to invoke all versions of a lambda function Jul 19, 2022
…g lambda functions via qualifiers

To establish the current functionality before makes changes to this feature.
…tion should grant permissions for all qualifiers
@mrgrain mrgrain force-pushed the fix/stepfunctions-tasks/lambda-versions-permissions branch from 2038466 to 83459a7 Compare July 19, 2022 16:57
@mrgrain mrgrain marked this pull request as ready for review July 19, 2022 16:58
@@ -0,0 +1,80 @@
import { Code, Function, Runtime } from '@aws-cdk/aws-lambda';
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This file is copied from integ.invoke.ts and adjusted to use a Version and an Alias.

…g lambda qualifiers

The issue has been fixed, now the integration tests need to be updated. As
expected, the PolicyDocument now lists and additional resource for the Version.
@mrgrain mrgrain force-pushed the fix/stepfunctions-tasks/lambda-versions-permissions branch from 83459a7 to 5263ffb Compare July 19, 2022 17:05
@aws aws deleted a comment from aws-cdk-automation Jul 19, 2022
@mrgrain mrgrain changed the title fix(stepfunctions-tasks): grant step functions task permissions to invoke all versions of a lambda function fix(stepfunctions-tasks): prevent in-flight step function executions from failing with missing permissions, when the invoked lambda version is updated Jul 19, 2022
@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

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

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

*/
private determineResourceArnsForGrantInvoke(lambdaFunction: IFunction): string[] {
if (isVersion(lambdaFunction)) {
return lambdaFunction.lambda.resourceArnsForGrantInvoke;
Copy link
Contributor

Choose a reason for hiding this comment

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

Is version.resourceArnsForGrantInvoke ever correct, in the face of changing versions?

Isn't it easier to just update the behavior of Version?

Copy link
Contributor Author

@mrgrain mrgrain Jul 20, 2022

Choose a reason for hiding this comment

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

Semantically, I'd expect lambdaVersion.grantInvoke(role) to grant permissions for the specified version and not all qualifiers. Otherwise I would do lambdaVersion.grantInvoke(role). That's a far reaching change to make.

The idiomatic way to solve this problem in AWS is to use an Alias. I'm on the fence, but because of this I'm more inclined to argue this "works as intended", than to change the behavior of Version.


Maybe we're going about this the wrong way and we need to solve the undeniably bad customer experience differently.

Copy link
Contributor Author

@mrgrain mrgrain Jul 21, 2022

Choose a reason for hiding this comment

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

@rix0rrr @madeline-k #20177 seems to be of a similar nature. Specifically @kaizencc made the point that if users want to "[..] grant less permissible policies, grant them on the version or alias you've created, not the function itself.". Changing Version to also grant permissions to all versions, would contradict this.

You've all clearly thought about this in-depth, so I'm very happy to follow your lead.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think Kaizen is right. Users should have created an alias, and invoked that. Invoking by currentVersion seems always incorrect, given the code that CDK generates.

In fact we should probably discourage it in the docs?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@rix0rrr So close this PR, update the docs, and then close the related issue with explanation?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@rix0rrr Can you quickly confirm if I understood you correctly regarding this PR and issue?

So close this PR, update the docs, and then close the related issue with explanation?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Agreed with @rix0rrr that this PR does not address the root cause of the issue.

Copy link
Contributor

@rix0rrr rix0rrr left a comment

Choose a reason for hiding this comment

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

Please make sure that your PR title confirms to the conventional commit standard (fix, feat, chore) and that it is written in a style that will reflect correctly in the change log (See Contributing Guide, Pull Requests)

@mrgrain mrgrain changed the title fix(stepfunctions-tasks): prevent in-flight step function executions from failing with missing permissions, when the invoked lambda version is updated fix(stepfunctions-tasks): in-flight stepfunction executions fail on update of versioned lambdas Jul 21, 2022
@mrgrain mrgrain requested a review from rix0rrr July 21, 2022 10:02
@mrgrain
Copy link
Contributor Author

mrgrain commented Aug 8, 2022

This change doesn't address the root cause. See comments above. Further discussions continue on #17515

@mrgrain mrgrain closed this Aug 8, 2022
@mrgrain mrgrain deleted the fix/stepfunctions-tasks/lambda-versions-permissions branch July 26, 2023 10:50
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. contribution/core This is a PR that came from AWS. effort/small Small work item – less than a day of effort p1
Projects
None yet
3 participants