Skip to content
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

Empty identity source support is broken #1638

Closed
frozenbonito opened this issue Jan 3, 2023 · 3 comments · Fixed by #1639
Closed

Empty identity source support is broken #1638

frozenbonito opened this issue Jan 3, 2023 · 3 comments · Fixed by #1639
Labels

Comments

@frozenbonito
Copy link
Contributor

Bug Report

Current Behavior

When an identity source setting of authorizer is empty, serverless-offline always returns 401 and logs the following message:

✖ Identity Source is null for header authorization (λ: authorizer)

Sample Code

  • file: serverless.yml
service: authorizer

plugins:
  - serverless-offline

provider:
  name: aws
  region: us-east-1
  runtime: nodejs18.x
  stage: dev

functions:
  hello:
    events:
      - http:
          authorizer:
            name: authorizer
            resultTtlInSeconds: 0
            identitySource: ""
            type: request
          method: get
          path: hello
    handler: handler.hello

  authorizer:
    handler: authorizer.authorizer
  • file: handler.js
const { stringify } = JSON;

export async function hello() {
  return {
    body: stringify({ message: "Hello" }),
    statusCode: 200,
  };
}
  • file: authorizer.js
export async function authorizer(event) {
  return {
    principalId: "user",
    policyDocument: {
      Statement: [
        {
          Action: "execute-api:Invoke",
          Effect: "Allow",
          Resource: event.methodArn,
        },
      ],
      Version: "2012-10-17",
    },
  };
}

Expected behavior/code

If the authorizer type is REQUEST and its caching is disabled, the identity source is not required.

For Authorization Caching, select or deselect the Enabled option, depending on whether you want to cache the authorization policy generated by the authorizer or not. When policy caching is enabled, you can choose to modify the TTL value from the default (300). Setting TTL=0 disables policy caching.
When caching is disabled, it is not necessary to specify an identity source.

https://docs.aws.amazon.com/apigateway/latest/developerguide/configure-api-gateway-lambda-authorization-with-console.html

IdentitySource
If you specify REQUEST for the Type property, this property is required when authorization caching is enabled.

https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-apigateway-authorizer.html

Environment

  • serverless version: v3.26.0
  • serverless-offline version: v12.0.3
  • node.js version: v18.12.1
  • OS: Debian 11.1 (WSL2, Windows 11)

Possible Solution

If type is request and resultTtlInSeconds is 0, identity source checking should be skipped.

Additional context/Screenshots

It looks like this issue was introduced in #1610.
It works correctly with v11.3.0 and earlier.

@frozenbonito
Copy link
Contributor Author

frozenbonito commented Jan 3, 2023

Related issue:
The identity source fallbacks to method.request.header.Authorization, even if authorizer type is request and its caching disabled.
Serverless v3 does not do this.
https://www.serverless.com/framework/docs/deprecations#default-identitysource-for-httpauthorizer

identitySource:
serverlessAuthorizerOptions?.identitySource ||
'method.request.header.Authorization',

@arturenault
Copy link

What's missing to get this merged?

@CaptainAchilles
Copy link

Can this be merged? The PR looks fine.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants