mirror of
https://github.com/floci-io/floci.git
synced 2026-11-24 22:37:55 -05:00
fix(lambda): enforce function policies when API Gateway invokes a function (#8786)
With IAM enforcement on, a REST API AWS_PROXY or AWS Lambda integration invoked the function whatever its function policy said. On AWS API Gateway invokes the function as apigateway.amazonaws.com and only the function policy decides the call, so a missing or mis-scoped AddPermission breaks the integration.
Before invoking, the integration now asks ServiceCallAuthorizer whether apigateway may perform lambda:InvokeFunction on the function, with aws:SourceArn set to the request's execute-api ARN, carrying the concrete request path and the function's Region, and aws:SourceAccount to the API's account. For an ANY method the ARN carries the request's verb, as a Lambda authorizer's methodArn does. A refused call answers 500 {"message": "Internal server error"} through the API_CONFIGURATION_ERROR gateway response, and the function is not invoked. A function that does not exist is refused the same way, since Lambda authorizes before it checks existence. An integration with credentials invokes as that role and is not checked.
With enforcement off nothing changes: a missing function still answers 404 Function not found.
Part of #4898
This commit is contained in:
1 parent
5b9e842cd9
commit
27de6fd46e
7 files changed
+471
-3
No files matched your search
@@ -149,6 +149,25 @@ part in authorizing calls to the function:
|
||||
authorized against the function as its name gives it, as the Service Reference lists the function
|
||||
alone for those actions.
|
||||
- A statement conditioned on `InvokedViaFunctionUrl` does not admit a direct `Invoke`.
|
||||
- An API Gateway REST API whose `AWS_PROXY` or `AWS` integration names the function invokes it on
|
||||
its own behalf. The function policy has to allow `lambda:InvokeFunction` to
|
||||
`apigateway.amazonaws.com`, as `AddPermission --principal apigateway.amazonaws.com` writes it,
|
||||
and a function with no policy refuses the call. `aws:SourceArn` is the request's execute-api ARN,
|
||||
`arn:aws:execute-api:<region>:<account>:<api-id>/<stage>/<METHOD>/<path>`, where `<path>` is the
|
||||
concrete request path such as `items/42` rather than the resource path template `items/{id}`, so
|
||||
a grant for `.../GET/items/*` covers it. `<region>` is the function's Region, not the API's, when
|
||||
the two differ, as Lambda's guide for API Gateway specifies; a function named without a Region is
|
||||
taken to be in the API's. `aws:SourceAccount` is the API's account.
|
||||
For an `ANY` method, `<METHOD>` is the request's verb, as in a Lambda authorizer's `methodArn`;
|
||||
this was not measured on AWS. A refused call is answered with `500` and
|
||||
`{"message": "Internal server error"}`; see [API Gateway](api-gateway.md#integration-settings).
|
||||
A call to a function that does not exist is refused the same way, since Lambda authorizes a call
|
||||
before it looks the function up (not measured through API Gateway); with enforcement off it is
|
||||
still answered with `404` and `Function not found`. An integration that names `credentials`
|
||||
invokes the function as that role, so the function policy does not decide it; Floci does not
|
||||
check that role's trust policy or identity policies either, so the call always goes through.
|
||||
Other services that invoke a function, such as EventBridge rules and Scheduler, event source
|
||||
mappings and Pipes, are not checked against the function policy.
|
||||
- `aws:PrincipalOrgID` is in the request context for a caller whose account is in an organization,
|
||||
so a grant added with `PrincipalOrgID` admits the callers of that organization and no others. A
|
||||
caller in no organization carries no value for the key, and such a grant then admits none.
|
||||
|
||||
Reference in new issue
Block a user