Appearance
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:
operatorfor the application. - For JWTs: the issuer, the audience and the key set URL (https) or key set file of your identity provider.
- Rules in
blockmode refuse requests, so start the module indetectfirst. 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 shopyaml
# 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 8760hyaml
# 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 IDtext
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
| Setting | What it does | Default | Allowed values | Applies in |
|---|---|---|---|---|
Name (name) | Identifies the rule. | none (required) | lowercase letters, digits, dashes, up to 63; unique | all |
Paths (paths) | Paths that need a token. | none (required) | at least one path pattern | all |
Token in (location) | Where the token is. | header:Authorization (Bearer) | header:NAME, cookie:NAME, query:NAME | all |
Issuers (issuers) | Accepted iss values. | none (any) | list | all |
Audiences (audiences) | The token's aud must contain one. | none (any) | list | all |
Algorithms (algorithms) | Accepted signature algorithms. | RS256, ES256 | RS256, RS384, RS512, PS256, PS384, PS512, ES256, ES384, ES512, EdDSA, HS256, HS384, HS512; never none | HS* needs a key file |
Key set URL (jwks_url) | Key set fetched by the active node. | none | https URL | exactly one of URL or file |
Key set file (jwks_file) | Key set stored with the version. | none | JWKS file, no private keys | exactly one of URL or file |
Refresh (refresh) | How often the URL is fetched. | 1h | 1m to 168h | with a key set URL |
Required claims (required_claims) | Claims that must match. | none | up to 32 name: value; a space-separated scope matches if it contains the value | all |
Clock skew (clock_skew) | Tolerance for exp and nbf. | 30s | 0s to 5m | all |
API key rule
| Setting | What it does | Default | Allowed values | Applies in |
|---|---|---|---|---|
Name (name) | Identifies the rule. | none (required) | as for JWT rules | all |
Paths (paths) | Paths that need a key. | none (required) | at least one path pattern | all |
Key in (location) | Where the key is. | header:X-API-Key | header:NAME, cookie:NAME, query:NAME | all |
Consumer
| Setting | What it does | Default | Allowed values | Applies in |
|---|---|---|---|---|
Name (name) | Identifies the consumer. | none (required) | lowercase letters, digits, dashes, up to 63; unique | all |
May call paths (paths) | Paths the consumer may call. | none (any) | path patterns | outside them: 403 |
Methods (methods) | Methods the consumer may use. | none (any) | uppercase HTTP methods | outside them: 403 |
From networks (source_networks) | Addresses the consumer may call from. | none (anywhere) | CIDR list | outside them: 403 |
JWT subjects (subjects) | Tokens whose sub, client_id or azp is one of these belong to this consumer. | none | list; a subject belongs to one consumer | all |
Rate (rate.limit, rate.per) | Requests per period, counted per consumer. | none | limit 1 to 1000000; per 1s to 24h | counted on each node |
What the client receives
| Rule | Status | Meaning |
|---|---|---|
api.auth.missing | 401 | no credential where a rule expects one |
api.auth.invalid | 401 | not a signed JWT, oversized, or the signature does not verify |
api.auth.algorithm | 401 | algorithm not in the list, or not the key's |
api.auth.key_id | 401 | no key for the token in the set |
api.auth.expired | 401 | expired, not yet valid, or no exp |
api.auth.issuer, api.auth.audience, api.auth.claims | 401 | issuer, audience or claim not accepted |
api.auth.api_key | 401 | unknown, revoked or expired key, or its consumer is gone |
api.auth.forbidden | 403 | the 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: logLimits
| Limit | Value |
|---|---|
| Authentication rules (JWT and key rules together) | 32 |
| Consumers | 1000 |
| Token size | 8 KiB |
| Keys loaded by inspection | every 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 shopshows 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.