tho-actrecipe / serverless-whitelisting

Create a whitelist for IP addresses, CIDR for a serverless application, using serverless resource policies.
https://www.npmjs.com/package/serverless-whitelisting
2 stars 1 forks source link

publicPaths not working #4

Open loren-m-crawford opened 2 years ago

loren-m-crawford commented 2 years ago

Hey! I'm having trouble getting publicPaths to work. Perhaps this is user error, but I've added the paths that I've defined under my function events in my serverless file but they still seem to be behind the netblocks. Can you clarify how to use publicPaths?

functions:
  foo:
    handler: bin/lambda/foo
    events:
      - http:
          method: POST
          path: /v1/foo
      - http:
          method: GET
          path: /v1/foo/{id}
          request:
            parameters:
              paths:
                id: true
serverless-whitelisting:
    stage: ${self:provider.stage}
    privateStages:
      - dev
    netblocks:
      - <redacted>
    publicPaths:
      - /v1/foo
tho-actrecipe commented 2 years ago

@loren-m-crawford Please try to update /v1/foo => v1/foo

tho-actrecipe commented 2 years ago

This only works behind the API Gateway and API is called by HTTP request, if you're using Lambda invoke (https://docs.aws.amazon.com/lambda/latest/dg/API_Invoke.html) it may not work.

loren-m-crawford commented 2 years ago

Hey @tho-asterist! Thank you for getting back to me :) We're using an HTTP request, but your changes still don't work. Do you have another suggestion?

tho-actrecipe commented 2 years ago

Please make sure to include serverless-whitelisting in plugins and use the latest version (0.0.6). Below is the working setting in my project (I’m using python).

plugins:
  - serverless-python-requirements
  - serverless-wsgi
  - serverless-whitelisting
custom:
  wsgi:
    app: app.app
    packRequirements: false
  pythonRequirements:
    layer: true
  serverless-whitelisting:
    stage: ${self:provider.stage}
    privateStages:
      - production
    netblocks:
      - <redacted>
    publicPaths:
      - v1/foo
tho-actrecipe commented 2 years ago

@loren-m-crawford Does it solve your issue?