/API Key Auth

API Key Auth

15
v0.3.0

api-key-auth

This plugin allows you to protect routes with an API key specified in a header, query string param or path segment. If the user does not provide a valid key the middleware will return a 403.

Config

Static file

Add to your Traefik static configuration

yaml

experimental:
plugins:
traefik-api-key-auth:
moduleName: "github.com/Septima/traefik-api-key-auth"
version: "v0.2.3"

toml

[experimental.plugins.traefik-api-key-auth]
moduleName = "github.com/Septima/traefik-api-key-auth"
version = "v0.2.3"

CLI

Add to your startup args:

--experimental.plugins.traefik-api-key-auth.modulename=github.com/Septima/traefik-api-key-auth
--experimental.plugins.traefik-api-key-auth.version=v0.2.3

K8s CRD

apiVersion: traefik.io/v1alpha1
kind: Middleware
metadata:
name: verify-api-key
spec:
plugin:
traefik-api-key-auth:
authenticationHeader: true
authenticationHeaderName: X-API-KEY
bearerHeader: true
bearerHeaderName: Authorization
queryParam: true
queryParamName: token
pathSegment: true
permissiveMode: false
removeHeadersOnSuccess: true
internalForwardHeaderName: ''
internalErrorRoute: ''
keys:
- some-api-key

Plugin options

optiondefaulttypedescriptionoptional
authenticationHeadertrueboolUse an authentication header to pass a valid key.⚠️
authenticationHeaderName"X-API-KEY"stringThe name of the authentication header.
bearerHeadertrueboolUse an authorization header to pass a bearer token (key).⚠️
bearerHeaderName"Authorization"stringThe name of the authorization bearer header.
queryParamtrueboolUse a query string param to pass a valid key.⚠️
queryParamName"token"stringThe name of the query string param.
pathSegmenttrueboolUse match on path segment to pass a valid key.⚠️
permissiveModefalseboolDry-run option to allow the request even if no valid was provided
removeHeadersOnSuccesstrueboolIf true will remove the header on success.
internalForwardHeaderName""stringOptionally forward validated key as header to next middleware.
internalErrorRoute""stringOptionally route to backend at specified path on invalid key
keys[][]stringA list of valid keys that can be passed using the headers.

⚠️ - Is optional but at least one of authenticationHeader, bearerHeader, queryparam or pathSegment must be set to true.

❌ - Required.

✅ - Is optional and will use the default values if not set.