How can I set API Key Security Globally on API Gateway using Swagger

Jonathan Cowling

I'm trying to import an openapi/swagger file into api gateway, but I'm not able to get the security set as expected. I want to have an api key required for all paths.

Setting it api key required in the console after import works, but this solution is undesirable, what also works is setting the security field in each path individually, but I'm looking for a global solution.

When I'm trying to import the file I get the following warning:

Your API was not imported due to errors in the Swagger file.

    Method 'GET' on resource '/' specified security,
    but no custom authorizers were created and the extension
    x-amazon-apigateway-auth was not set.
    This method will be not be secured. 

By the looks of this, I either need a lambda as a custom authorizer just for the api key (I'm not familiar with authorizers but this doesn't seem to make sense if I don't need one when setting api key required in the console); or I need to do something with this mysterious x-amazon-apigateway-auth which I can't find docs for (all the other openapi extensions amazon have documented here).

A miniamal example is below:

openapi: 3.0.1
info:
  title: test
  version: 0
servers:
- url: "/"
security:
  - ApiKey: []
paths:
  "/":
    get:
      # if I copy the security part into here things work 
      responses:
        '204':
          description: no content
      x-amazon-apigateway-integration:
        httpMethod: GET
        type: http
        uri: https://httpstat.us/204
components:
  securitySchemes:
    ApiKey:
      type: apiKey
      name: x-api-key
      in: header
x-amazon-apigateway-api-key-source: HEADER

since api key security is set at the root level, this suggests to me that all paths should use an api key (unless overwritten by individual paths), what actually occurs is the above warning and no api key required when imported.

pawelb

At the time of me writing this answer, according to their documentation, AWS API gateway does not support setting security at the root level.

API Gateway doesn't use root level security defined in the OpenAPI specification. Hence security needs to be defined at an operation level to be appropriately applied.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Using an API Key & Secret for Swagger Security Scheme

How can I configure an API gateway endpoint to require an API key?

How can I set a value for the key "homepage" without using the API?

Using aws-api-gateway models, how can I require an object contains AT LEAST 1 valid key

How can I send multiple Set-Cookie headers from API Gateway using a proxied Lambda

How do I set up my API to require an API key with amazon API Gateway?

How to set "Use Lambda Proxy integration" in swagger for API-Gateway?

Using Java API TransmissionWithRecipientArray object, how can I set an element like a key value array ( Sparkpost )

How can I dynamic hide swagger api?

How can I set an API key once and save it within a function?

AWS API Gateway Swagger using swashbuckle

how can i implement api gateway in asp.net web api (not .net core) using c#

How to apply Security Policy on AWS API Gateway using AWS CloudFormation?

Using an api key in amazon api gateway

How can I get an item by a string key using web api?

How can I set an AWS Lambda to be invoked asynchronously through HTTP/API Gateway?

How can I set the AWS API Gateway timeout higher than 30 seconds?

swift: How can I set the body in the PUT request in the generated iOS sdk for aws-api-gateway?

Can I use an Interface with a Foreign Key in EF Core and set it as a foreign key using Fluent API?

Can I create a API gateway in a F# class lib with type providers and use that in a C# solution to get intellisense on external Web Api using swagger?

Importing Swagger API to AWS API Gateway using command line tool

How can I set Google API Key programmatically? I'm getting "The request is missing a valid API key." Error (403)

How can I set RenderingHints globally?

How can i set cascade mode Globally?

Security of AWS API Gateway

How do i architect microservices and an API globally?

How can I pass my API key through header while making request to Stackoverflow API using python

How can I view origin configuration for API gateway in AWS console?

How can I use api gateway stages via cloudformation or sam?