Skip to content

Authentication, consumers and API keys Since v0.1 ​

Authentication rules name the paths that need a credential. A JWT rule checks a signed token against a key set. An API key rule checks a key that belongs to a consumer. A consumer is a known caller that can be limited to paths, methods and networks and given its own request rate.

Before you begin ​

  • Role: operator for the application.
  • For JWTs: the issuer, the audience and the key set URL (https) or key set file of your identity provider.
  • Rules in block mode refuse requests, so start the module in detect first. For details, see Schema enforcement.

Require JWTs ​

text
1. Open Applications > All applications > the application > Request checks > API protection.
2. Open the Authentication tab. Under JWT rules, select Add JWT rule.
3. Enter Name, Paths, and the Issuers, Audiences and Key set URL of your provider.
4. Select Preview changes, add a comment and select Apply.
5. Check the key set status shown under the rules.
sh
waap api list set -app shop -list auth.jwt -f jwt.yaml -m "require tokens"
waap api auth -app shop
yaml
# jwt.yaml, or applications[].policy.api.auth.jwt
- name: customers
  paths: ["/api/*"]
  issuers: ["https://login.example.com/"]
  audiences: [shop-api]
  jwks_url: https://login.example.com/.well-known/jwks.json
  required_claims: {scope: orders}

Check the key set after adding a rule

A rule whose key set was never fetched refuses every token. waap api auth -app shop shows each rule with the fetch status of its key set.

The checks run in this order: token size, one compact signature, the algorithm against the rule's list (before any key is used, so an RS key can never verify an HS token), the key by kid, the signature, then exp (required), nbf, issuer, audience and required claims. A token signed with a key that is not yet in the set is refused until the next refresh.

Add consumers and API keys ​

Add the consumer first, then a key rule for the paths, then one key per client.

text
1. Open the API protection page, Consumers & keys tab. Select Add consumer and save.
2. On the Authentication tab, under API key rules, select Add API key rule.
3. Back on Consumers & keys, choose the Consumer, add a Comment and Expires in, and
   create the key.
4. Copy the key and hand it over. It is shown once.
sh
waap api list set -app shop -list consumers -f consumers.yaml -m "partners"
waap api list set -app shop -list auth.api_keys -f keyrules.yaml -m "partner keys"
waap api-keys add -app shop -consumer acme -comment "nightly sync" -expires 8760h
yaml
# consumers.yaml
- name: acme
  paths: ["/partner/*"]
  methods: [GET, POST]
  source_networks: ["198.51.100.0/24"]
  rate: {limit: 100, per: 1m}
# keyrules.yaml
- name: partners
  paths: ["/partner/*"]

Keys are not part of the configuration. Only a SHA-256 hash is stored, with a wk_ prefix to recognize it. Keys are replicated in a pair and loaded by every inspection service every 2 seconds.

Rotate and revoke keys ​

Add a new key, switch the client to it, then revoke the old one.

sh
waap api-keys list -app shop
waap api-keys revoke ID
text
1. Open the Consumers & keys tab and find the key in the API keys table.
2. Select Revoke. The key is refused on every node within seconds.

Removing a consumer from the configuration also stops its keys. The Authentication tab shows authentication failures of the last 24 hours by reason.

Settings reference ​

JWT rule ​

SettingWhat it doesDefaultAllowed valuesApplies in
Name (name)Identifies the rule.none (required)lowercase letters, digits, dashes, up to 63; uniqueall
Paths (paths)Paths that need a token.none (required)at least one path patternall
Token in (location)Where the token is.header:Authorization (Bearer)header:NAME, cookie:NAME, query:NAMEall
Issuers (issuers)Accepted iss values.none (any)listall
Audiences (audiences)The token's aud must contain one.none (any)listall
Algorithms (algorithms)Accepted signature algorithms.RS256, ES256RS256, RS384, RS512, PS256, PS384, PS512, ES256, ES384, ES512, EdDSA, HS256, HS384, HS512; never noneHS* needs a key file
Key set URL (jwks_url)Key set fetched by the active node.nonehttps URLexactly one of URL or file
Key set file (jwks_file)Key set stored with the version.noneJWKS file, no private keysexactly one of URL or file
Refresh (refresh)How often the URL is fetched.1h1m to 168hwith a key set URL
Required claims (required_claims)Claims that must match.noneup to 32 name: value; a space-separated scope matches if it contains the valueall
Clock skew (clock_skew)Tolerance for exp and nbf.30s0s to 5mall

API key rule ​

SettingWhat it doesDefaultAllowed valuesApplies in
Name (name)Identifies the rule.none (required)as for JWT rulesall
Paths (paths)Paths that need a key.none (required)at least one path patternall
Key in (location)Where the key is.header:X-API-Keyheader:NAME, cookie:NAME, query:NAMEall

Consumer ​

SettingWhat it doesDefaultAllowed valuesApplies in
Name (name)Identifies the consumer.none (required)lowercase letters, digits, dashes, up to 63; uniqueall
May call paths (paths)Paths the consumer may call.none (any)path patternsoutside them: 403
Methods (methods)Methods the consumer may use.none (any)uppercase HTTP methodsoutside them: 403
From networks (source_networks)Addresses the consumer may call from.none (anywhere)CIDR listoutside them: 403
JWT subjects (subjects)Tokens whose sub, client_id or azp is one of these belong to this consumer.nonelist; a subject belongs to one consumerall
Rate (rate.limit, rate.per)Requests per period, counted per consumer.nonelimit 1 to 1000000; per 1s to 24hcounted on each node

What the client receives ​

RuleStatusMeaning
api.auth.missing401no credential where a rule expects one
api.auth.invalid401not a signed JWT, oversized, or the signature does not verify
api.auth.algorithm401algorithm not in the list, or not the key's
api.auth.key_id401no key for the token in the set
api.auth.expired401expired, not yet valid, or no exp
api.auth.issuer, api.auth.audience, api.auth.claims401issuer, audience or claim not accepted
api.auth.api_key401unknown, revoked or expired key, or its consumer is gone
api.auth.forbidden403the consumer may not call this method and path from this address

Examples ​

Count a rate per consumer instead of per address, logging only while you measure. For details, see Rate limits.

yaml
- name: api-per-consumer
  when: {paths: ["/api/*"]}
  limit: 1000
  per: 1m
  by: consumer
  action: log

Limits ​

LimitValue
Authentication rules (JWT and key rules together)32
Consumers1000
Token size8 KiB
Keys loaded by inspectionevery 2 seconds

Troubleshooting ​

Every token is refused with api.auth.key_id ​

  • Cause: the key set was never fetched, or the token's key is newer than the set.
  • Check: waap api auth -app shop shows the key set status and the fetch error.
  • Fix: correct the URL (https only), or wait for the next Refresh.

A key stopped working ​

  • Cause: it expired, was revoked, or its consumer was removed from the configuration.
  • Check: waap api-keys list -app shop.
  • Fix: create a new key for the consumer.