serverless / serverless/examples

Incorrect failure mechanism from aws-python-auth0-custom-authorizers-api

Open
#305 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
JavaScript
Stars
11.5k
Forks
4.4k
Avg merge
2h 55m
Merged PRs (30d)
3

Description

I used the aws-python-auth0-custom-authorizers-api example as the basis for a lambda function.

The AWS documentation says this about the expected return from an authorizer:

A Lambda authorizer function's output must include the principal identifier (principalId) and a policy document (policyDocument) containing a list of policy statements.

In the AWS example Python authorizer it details how to handle failure:

you can send a 401 Unauthorized response to the client by failing like so:
raise Exception('Unauthorized')

In a few places the example returns create_401_response(), which returns status_code, headers and body.

When debugging my custom code this seems to cause an AuthorizerConfigurationException, as seen in the HTTP response headers:

x-amzn-errortype: AuthorizerConfigurationException
x-cache: Error from cloudfront

Using the API Gateway authorizer tester I get a few more debugging messages:

Mon Oct 08 21:43:07 UTC 2018 : Execution failed due to configuration error: Invalid JSON in response: {"statusCode": 401, "headers": {"Access-Control-Allow-Origin": "*", "Access-Control-Allow-Credentials": true}, "body": "\"Unauthorized\""}
Mon Oct 08 21:43:07 UTC 2018 : AuthorizerConfigurationException

So I think the options should be:

  • For invalid authentication, raise Exception('Unauthorized')
  • For valid users with no access (e.g. RBAC), return generate_policy(None, 'Deny', event['methodArn'])
  • For valid users with permissions, return an allow policy.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with aws-python-auth0-custom-authorizers-api/lambda_handlers.py, especially the create_401_response() path, and compare its output with the AWS Lambda authorizer response requirements. Use the API Gateway authorizer tester to verify that invalid authentication, denied access, and allowed access each produce the expected authorizer behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
aws, python
Domain
api, authentication
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.