Skip to content

Bug: RequestContextV2AuthorizerJwt requires scopes #2953

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

Closed
smittnacht opened this issue Aug 14, 2023 · 5 comments · Fixed by #2961
Closed

Bug: RequestContextV2AuthorizerJwt requires scopes #2953

smittnacht opened this issue Aug 14, 2023 · 5 comments · Fixed by #2961
Assignees
Labels
bug Something isn't working parser Parser (Pydantic) utility

Comments

@smittnacht
Copy link

Expected Behaviour

I'm using the RequestContextV2 Model for parsing the event payload within a AWS Lambda function called by an AWS API Gateway. The API Gateway is configured to allow only authenticated requests with a valid JWT Token. The token is generated by our self-hosted GitLab instance with the help of the https://docs.gitlab.com/ee/ci/yaml/#id_tokens keyword.

The token itself has no scopes and it's not possible to configure any. The API Gateway is configured without any scope requirements which is a valid configuration according to AWS docs.

Current Behaviour

Right now this configuration is not supported by the RequestContextV2AuthorizerJwt Model as it requires that a scopes field is present in the object. The validation fails and an exception is thrown

[ERROR] ValidationError: 1 validation error for APIGatewayProxyEventV2Model
requestContext.authorizer.jwt.scopes
Input should be a valid list [type=list_type, input_value=None, input_type=NoneType]
For further information visit https://errors.pydantic.dev/2.1/v/list_type
Traceback (most recent call last):
  File "/opt/python/lib/python3.10/site-packages/aws_lambda_powertools/middleware_factory/factory.py", line 135, in wrapper
    response = middleware()
  File "/opt/python/lib/python3.10/site-packages/aws_lambda_powertools/utilities/parser/parser.py", line 83, in event_parser
    parsed_event = parse(event=event, model=model, envelope=envelope) if envelope else parse(event=event, model=model)
  File "/opt/python/lib/python3.10/site-packages/aws_lambda_powertools/utilities/parser/parser.py", line 155, in parse
    return envelope().parse(data=event, model=model)
  File "/opt/python/lib/python3.10/site-packages/aws_lambda_powertools/utilities/parser/envelopes/apigwv2.py", line 30, in parse
    parsed_envelope: APIGatewayProxyEventV2Model = APIGatewayProxyEventV2Model.parse_obj(data)
  File "/opt/python/lib/python3.10/site-packages/typing_extensions.py", line 2562, in wrapper
    return __arg(*args, **kwargs)
  File "/opt/python/lib/python3.10/site-packages/pydantic/main.py", line 961, in parse_obj
    return cls.model_validate(obj)
  File "/opt/python/lib/python3.10/site-packages/pydantic/main.py", line 496, in model_validate
    return cls.pydantic_validator.validate_python(

Code snippet

@event_parser(model=Pipeline, envelope=envelopes.ApiGatewayV2Envelope)
def lambda_handler(event: Pipeline, context: LambdaContext):
  pass

Possible Solution

develop...smittnacht:powertools-lambda-python:jwt-scopes-as-optional

Steps to Reproduce

Create an AWS API Gateway with JWT Authorizer and with a Lambda Function integration. Don't configure any required scopes. Send an authenticated request to the endpoint without any scopes defined.

Powertools for AWS Lambda (Python) version

latest

AWS Lambda function runtime

3.10

Packaging format used

Lambda Layers

Debugging logs

No response

@smittnacht smittnacht added bug Something isn't working triage Pending triage from maintainers labels Aug 14, 2023
@boring-cyborg
Copy link

boring-cyborg bot commented Aug 14, 2023

Thanks for opening your first issue here! We'll come back to you as soon as we can.
In the meantime, check out the #python channel on our Powertools for AWS Lambda Discord: Invite link

@leandrodamascena
Copy link
Contributor

leandrodamascena commented Aug 14, 2023

Hi @smittnacht! Thank you for opening this issue; I can confirm it is a bug. Scope field should not be mandatory in this case.

We plan to release a version on Thursday/Friday, but here in Powertools we strive to fix bugs ASAP! Please let me know if you can wait until Friday to fix this OR we can release a patch tomorrow.

@leandrodamascena leandrodamascena added parser Parser (Pydantic) utility and removed triage Pending triage from maintainers labels Aug 14, 2023
@smittnacht
Copy link
Author

Hi @leandrodamascena
Thank you for confirming this bug. A fix within this week will be absolutely fine. I've created a fork in order to continue my work.

@github-actions
Copy link
Contributor

⚠️COMMENT VISIBILITY WARNING⚠️

This issue is now closed. Please be mindful that future comments are hard for our team to see.

If you need more assistance, please either tag a team member or open a new issue that references this one.

If you wish to keep having a conversation with other community members under this issue feel free to do so.

@github-actions github-actions bot added the pending-release Fix or implementation already in dev waiting to be released label Aug 15, 2023
@github-actions
Copy link
Contributor

This is now released under 2.23.0 version!

@github-actions github-actions bot removed the pending-release Fix or implementation already in dev waiting to be released label Aug 18, 2023
@leandrodamascena leandrodamascena moved this from Coming soon to Shipped in Powertools for AWS Lambda (Python) Aug 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working parser Parser (Pydantic) utility
Projects
Status: Shipped
2 participants