apache / apisix

The Cloud-Native API Gateway
https://apisix.apache.org/blog/
Apache License 2.0
14.01k stars 2.46k forks source link

bug: aws-lambda plugin with IAM auth fails with URL-encoded query parameters #11097

Open deiwin opened 3 months ago

deiwin commented 3 months ago

Current Behavior

When using the the aws-lambda plugin with IAM auth, then any request that includes URL-encoded query parameters will fail with the following error returned from AWS:

HTTP/2 403
..
x-amzn-errortype: InvalidSignatureException
..

{"message":"The request signature we calculated does not match the signature you provided. Check your AWS Secret Access Key and signing method. Consult the service documentation for details."}

I believe this happens because:

Expected Behavior

No response

Error Logs

No response

Steps to Reproduce

Create a route including the aws-lambda plugin:

function_uri: <URI>
authorization:
  iam:
    accesskey: <key>
    secretkey: <key>
    aws_region: <region>
    service: <execute-api/lambda>

Then send a request to the route, including a query parameter such as ?param=with%20spaces, for example.

Environment

shreemaan-abhishek commented 3 months ago

welcome to raise a PR to fix this!

deiwin commented 3 months ago

Thanks! @shreemaan-abhishek, do you know if a PR would be accepted if it also introduced the usage of the nginxinc/nginx-aws-signature library?

I'm asking because for me to be able to actually use the aws-lambda plugin I'd need it to support IAM roles for service accounts, which it currently doesn't.

deiwin commented 3 months ago

Okay, maybe that wasn't a great library to suggest, as it's in JS and whatnot. But would the addition of https://github.com/Kong/lua-resty-aws be acceptable?

This could be used for getting the credentials (defaulting to env variables, EKS pod identity, EC2 identity, etc) and the existing code could be kept for the signing logic.

shreemaan-abhishek commented 3 months ago

I'd need it to support IAM roles for service accounts, which it currently doesn't.

If this is a separate feature, please create an issue describing this feature request, then we can move forward with whether or not we should have it. After that we can return to this issue. WDYT?

deiwin commented 3 months ago

Thanks @shreemaan-abhishek, created https://github.com/apache/apisix/issues/11137