Skip to main content

API Key Authentication

The API Key authentication middleware allows you to secure an API by requiring a secret key, base64 encoded or not, to be given, via an HTTP header, a cookie or a query parameter.


Configuration Example

---
apiVersion: traefik.io/v1alpha1
kind: Middleware
metadata:
name: test-apikey
namespace: apps
spec:
plugin:
apiKey:
keySource:
headerAuthScheme: Bearer
header: Authorization
secretNonBase64Encoded: true
secretValues:
- "urn:k8s:secret:apikey:secret"
- "urn:k8s:secret:apikey:othersecret"

Configuration Options

FieldDescriptionDefaultRequired
keySource.headerDefines the header name containing the secret sent by the client.
Either keySource.header or keySource.header or keySource.header must be set.
""No
keySource.headerAuthSchemeDefines the scheme when using Authorization as header name.
Check out the Authorization header documentation.
""No
keySource.queryDefines the query parameter name containing the secret sent by the client..
Either keySource.header or keySource.header or keySource.header must be set.
""No
keySource.cookieDefines the cookie name containing the secret sent by the client..
Either keySource.header or keySource.header or keySource.header must be set.
""No
secretNonBase64EncodedDefines whether the secret sent by the client is base64 encoded.falseNo
secretValuesContain the hash of the API keys.
Supported hashing algorithms are Bcrypt, SHA1 and MD5.
The hash should be generated using htpasswd.
Can reference a Kubernetes Secret using the URN format: urn:k8s:secret:[name]:[valueKey]
[]Yes