Description
Restrict the lambda:InvokeFunction grant for API Gateway to the API ID, stage, method and path that use the function.
Potential impact
A broad source_arn can allow another route to run the function if it uses the same integration, increasing load and cost.
Remediation
Configure client authentication and authorization on the API. Check the alias policy for obsolete broad grants and verify which routes can invoke the function.
Examples
With current Ansible, add the installed amazon.aws collection to the play’s collections for the short name shown, or use amazon.aws.lambda_policy. Supply the actual Region, account and API ID and point the integration to the Dev alias.
Before
- name: Configure Lambda invocation permission
lambda_policy:
state: present
function_name: functionName
alias: Dev
statement_id: api-gateway-invoke
action: lambda:InvokeFunction
principal: apigateway.amazonaws.com
source_arn: arn:aws:execute-api:eu-central-1:123456789012:api-id/*/*
After
- name: Configure Lambda invocation permission
lambda_policy:
state: present
function_name: functionName
alias: Dev
statement_id: api-gateway-invoke
action: lambda:InvokeFunction
principal: apigateway.amazonaws.com
source_arn: arn:aws:execute-api:eu-central-1:123456789012:api-id/prod/GET/orders
The second task allows just GET /orders on the prod stage to invoke Dev.