Skip to content

fix(aws-lambda): fetch ecs environment variable failure caused by the phase change #9460

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

Merged
merged 5 commits into from
Sep 27, 2022

Conversation

windmgc
Copy link
Member

@windmgc windmgc commented Sep 22, 2022

Summary

This PR fixes a bug that the aws-lambda plugin failed to get environment variables in ECS which leads to unable to fetch ECS task role credentials.

This bug is introduced since #8900, in which the moment of the step require "kong.plugins.aws-lambda.iam-ecs-credentials" is changed from happening in package load(init phase) to only in function call(access phase). Since in the Nginx process environment, only those environment variables exposed through the env Nginx config directory can be fetched by os.getenv in Lua code(with an exception that env vars can all be fetched in the init phase, and most of the Kong code that using os.getenv relies on this). So after #8900, fetching ECS environment variables will fail.

Sorry for bringing this bug in, and this also shows that a full integration test with the AWS environment is really needed for this plugin.

Full changelog

  • Fix fetch ECS environment variable failure caused by the phase change

Issue reference

Fix FTI-4340

@windmgc windmgc force-pushed the fix-lambda-ecs-env-var-fetch branch from 5793134 to 213a496 Compare September 22, 2022 09:28
@windmgc
Copy link
Member Author

windmgc commented Sep 22, 2022

Manually tested in the following cases:

  • EC2 environment, same account lambda invoke
  • ECS environment, same account lambda invoke
  • EC2 environment, cross account lambda invoke
  • ECS environment, cross account lambda invoke

I will try to add another test case to test ECS environment variable fetching

@windmgc windmgc force-pushed the fix-lambda-ecs-env-var-fetch branch from 1a4dc3b to f0e7525 Compare September 23, 2022 07:17
@windmgc windmgc force-pushed the fix-lambda-ecs-env-var-fetch branch from 0a5a5bf to 517b356 Compare September 26, 2022 05:20
@windmgc
Copy link
Member Author

windmgc commented Sep 26, 2022

Test added.

@windmgc windmgc added this to the 2.8.2 milestone Sep 26, 2022
Co-authored-by: Datong Sun <[email protected]>
@dndx dndx merged commit 1beb38b into Kong:master Sep 27, 2022
@chan-vince
Copy link

Sorry for the ignorance here, but I think I need this fix but in Kong Konnect.
I've installed the lambda plugin but I cannot see what version of the plugin it uses? Or when a fix to a plugin like this is pushed to master, when it gets added to Konnect?
Thanks

@windmgc
Copy link
Member Author

windmgc commented Oct 10, 2022

@chan-vince I'm not sure about it, maybe you can reach out the Konnect help for an answer :)

@rosskukulinski
Copy link

Hi @chan-vince - I'm the overall product lead for Konnect. Once you update your runtimes (Gateway dataplanes) to a version that has this fix included, you should be good-to-go.

@chan-vince
Copy link

chan-vince commented Oct 11, 2022

Hi @chan-vince - I'm the overall product lead for Konnect. Once you update your runtimes (Gateway dataplanes) to a version that has this fix included, you should be good-to-go.

Thanks for jumping in @rosskukulinski 😀
That is good to know, I sort of thought that might be the case.

My dataplanes are using the kong/kong-gateway:3.0.0.0 Docker image which I believe is the latest at this moment. I'm guessing that is the same as the 3.0.0 version?

I don't see this PR number in the release notes for any version up and including 3.0.0, so I assume I have to wait a bit.

P.S. I have a fair amount of technical feedback on Konnect in general; off topic here but let me know if you're interested.

@rosskukulinski
Copy link

@chan-vince Since this was just merged 15 days ago, it'll go out in the next gateway release which should be 3.1. It's also been backported to the 2.8.x release branch so it'll go out in the next 2.8 patch release

On the Konnect feedback - would love to hear that. You can reach me at firstname -at- konghq dot com.

@windmgc windmgc deleted the fix-lambda-ecs-env-var-fetch branch October 19, 2022 03:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants