Exam-style hands-on labs with Kong Manager (UI) steps, Admin API / decK / CLI commands, verification and gotchas.
Table of Contents
TogglePart C – Consumers and Authentication
Honest note: the real exam questions are confidential, so nobody can give you the exact ones. These labs are modelled on the published exam objectives (services/routes, upstreams and health checks, consumers and authentication, plugins, traffic control, transformations, logging, workspaces/RBAC, decK/DB-less, hybrid mode, TLS, CLI and troubleshooting) and on the style of tasks you are expected to perform: configure it, then prove it works.
Lab environment and assumptions
| Item | Value |
|---|---|
| Kong Gateway | 3.x (OSS or Enterprise; Enterprise-only labs are marked [EE]) |
| Admin API | http://localhost:8001 |
| Kong Manager | http://localhost:8002 |
| Proxy | http://localhost:8000 (HTTPS :8443) |
| Upstream test app | http://httpbin.org (or a local kong/httpbin / mccutchen/go-httpbin container) |
# Handy aliases used in all labs
export ADMIN=http://localhost:8001
export PROXY=http://localhost:8000
Universal verification checklist (use this on EVERY task)
- Config exists:
curl -s $ADMIN/services | jq,/routes,/plugins,/consumers,/upstreams/<name>/targets. - Traffic test with headers visible:
curl -i ...(never plaincurl– status line and headers are your evidence). - Read the status code:
| Code | Usual Kong meaning |
|---|---|
| 200/2xx | Route matched, upstream answered |
| 400 | Bad request / invalid header / plugin validation |
| 401 | Authentication plugin: missing or invalid credentials |
| 403 | Authenticated but not authorised (ACL, ip-restriction, invalid key scope) |
404 no Route matched with those values |
No route matched (path/host/method/header) – the problem is the route |
| 413 | request-size-limiting |
| 429 | rate-limiting |
| 500 | Plugin or Kong internal error – check error.log |
| 502 | Kong reached/parsed upstream badly (connection refused, bad response) |
| 503 | No healthy target / name resolution failed / service unavailable |
| 504 | Upstream timed out (read/send/connect timeout) |
- Useful response headers:
X-Kong-Upstream-Latency,X-Kong-Proxy-Latency,Via: kong/x.y,X-RateLimit-Limit-Minute,X-RateLimit-Remaining-Minute,RateLimit-*,X-Cache-Status,X-Kong-Request-Id. - Logs: default prefix
/usr/local/kong/logs/→error.log,access.log. In Docker:docker logs <kong>. - Declarative / DB-less mode is read-only through the Admin API (POST/PUT/PATCH/DELETE return 405). Change
kong.ymland reload. - Scope matters: a plugin may exist but be attached to a different route/service/consumer than the one you test.
Plugin precedence (most specific wins – only ONE instance of a plugin runs per request)
Consumer + Route + Service → Consumer + Route → Consumer + Service → Route + Service → Consumer → Route → Service → Global.
Lab 19 – Protect a Service with key-auth
Task: Only callers presenting a valid API key may use orders-svc. Create consumer alice with key alice-secret.
UI:
- Gateway Services →
orders-svc→ Plugins → New Plugin → Key Authentication → Create. - Consumers → New Consumer
alice→ open → Credentials → New Key Auth Credential → Keyalice-secret.
curl -s -X POST $ADMIN/services/orders-svc/plugins --data name=key-auth
curl -s -X POST $ADMIN/consumers --data username=alice
curl -s -X POST $ADMIN/consumers/alice/key-auth --data key=alice-secret
curl -i $PROXY/anything/x # 401
curl -i $PROXY/anything/x -H 'apikey: alice-secret' # 200
curl -i $PROXY/anything/x -H 'apikey: wrong' # 401 (Invalid authentication credentials)
Keep in mind: the default key location is header or query apikey. Upstream receives X-Consumer-Username / X-Consumer-ID headers.
Lab 20 – key_names, key_in_query, hide_credentials
Task: Accept the key only in header X-API-Key, and do NOT forward it to the upstream.
PID=$(curl -s $ADMIN/services/orders-svc/plugins | jq -r '.data[]|select(.name=="key-auth").id')
curl -s -X PATCH $ADMIN/plugins/$PID \
--data 'config.key_names[]=X-API-Key' \
--data config.key_in_query=false \
--data config.hide_credentials=true
curl -s $PROXY/anything/h -H 'X-API-Key: alice-secret' | jq '.headers'
Verify: the echoed headers do not contain X-Api-Key; ?X-API-Key=... in the query string now returns 401.
Keep in mind: after PATCH, re-test with the new header name – apikey stops working.
Lab 21 – basic-auth
Task: Protect route orders-route with username/password credentials for consumer bob.
curl -s -X POST $ADMIN/routes/orders-route/plugins --data name=basic-auth
curl -s -X POST $ADMIN/consumers --data username=bob
curl -s -X POST $ADMIN/consumers/bob/basic-auth --data username=bob --data password=P@ssw0rd
curl -i -u bob:P@ssw0rd $PROXY/anything/x # 200
curl -i -u bob:bad $PROXY/anything/x # 401
Keep in mind: passwords are stored hashed (you cannot read them back). Credentials go in the Authorization: Basic ... header. If both key-auth (service) and basic-auth (route) are applied, both must pass unless anonymous is configured (Lab 25).
Lab 22 – JWT authentication
Task: Enable jwt on a route and call it with a token signed by the consumer’s secret (HS256).
curl -s -X POST $ADMIN/routes/orders-route/plugins --data name=jwt
curl -s -X POST $ADMIN/consumers --data username=carol
curl -s -X POST $ADMIN/consumers/carol/jwt --data algorithm=HS256 \
--data key=carol-issuer --data secret=my-very-long-secret-key
The token must carry the claim iss = carol-issuer (the credential key) and be signed with my-very-long-secret-key. Generate it at jwt.io or:
TOKEN=$(python3 - <<'EOF'
import jwt,time
print(jwt.encode({"iss":"carol-issuer","exp":int(time.time())+3600},"my-very-long-secret-key",algorithm="HS256"))
EOF
)
curl -i $PROXY/anything/x -H "Authorization: Bearer $TOKEN"
Keep in mind: config.claims_to_verify=["exp"] enforces expiry; config.key_claim_name defaults to iss; 401 No credentials found for given 'iss' means the key does not match any JWT credential.
Lab 23 – ACL (authorisation) on top of authentication
Task: alice (group admins) may call the route, dave (group guests) must get 403.
curl -s -X POST $ADMIN/routes/orders-route/plugins --data name=key-auth
curl -s -X POST $ADMIN/routes/orders-route/plugins --data name=acl --data 'config.allow[]=admins'
curl -s -X POST $ADMIN/consumers --data username=dave
curl -s -X POST $ADMIN/consumers/dave/key-auth --data key=dave-secret
curl -s -X POST $ADMIN/consumers/alice/acls --data group=admins
curl -s -X POST $ADMIN/consumers/dave/acls --data group=guests
curl -i $PROXY/anything/x -H 'apikey: alice-secret' # 200
curl -i $PROXY/anything/x -H 'apikey: dave-secret' # 403 You cannot consume this service
UI: Consumer → Groups/ACL → add group; Route → Plugins → ACL → Allow list.
Keep in mind: ACL needs an auth plugin to identify the consumer first (otherwise 401/403). Use allow or deny, not both. hide_groups_header controls X-Consumer-Groups.
Lab 24 – OAuth 2.0 client-credentials flow
Task: Enable the oauth2 plugin on a route for client-credentials grants and obtain a token.
curl -s -X POST $ADMIN/routes/orders-route/plugins --data name=oauth2 \
--data 'config.scopes[]=read' --data config.enable_client_credentials=true \
--data config.global_credentials=true --data config.mandatory_scope=false
curl -s -X POST $ADMIN/consumers --data username=app1
curl -s -X POST $ADMIN/consumers/app1/oauth2 \
--data name=app1 --data client_id=cid1 --data client_secret=csecret1
# OAuth endpoints are served on the proxy, HTTPS only by default!
curl -sk -X POST https://localhost:8443/anything/oauth2/token \
--data grant_type=client_credentials --data client_id=cid1 --data client_secret=csecret1
curl -i $PROXY/anything/x -H "Authorization: Bearer <access_token>"
Keep in mind: the token endpoint is <route-path>/oauth2/token on the proxy port and needs HTTPS unless config.accept_http_if_already_terminated=true. invalid_client = wrong id/secret.
Lab 25 – Anonymous access and multiple auth plugins (OR logic)
Task: Allow either an API key or basic auth. Unauthenticated callers should be treated as consumer anonymous (read-only).
curl -s -X POST $ADMIN/consumers --data username=anonymous
AID=$(curl -s $ADMIN/consumers/anonymous | jq -r .id)
curl -s -X POST $ADMIN/routes/orders-route/plugins --data name=key-auth --data config.anonymous=$AID
curl -s -X POST $ADMIN/routes/orders-route/plugins --data name=basic-auth --data config.anonymous=$AID
Verify: with a valid key OR valid basic creds → 200 as that consumer; with no creds → 200 as anonymous (X-Anonymous-Consumer: true); with an invalid credential → 401.
Keep in mind: config.anonymous takes the consumer UUID (use the username only in newer versions – UUID always works). Without anonymous on all of them, plugins behave as AND.
Lab 26 – Key rotation with credential TTL
Task: Issue alice a temporary key that expires in 10 minutes, then retire the old key.
curl -s -X POST $ADMIN/consumers/alice/key-auth --data key=alice-new --data ttl=600
curl -s $ADMIN/consumers/alice/key-auth | jq '.data[]|{key,ttl,created_at}'
# delete the old one
KID=$(curl -s $ADMIN/consumers/alice/key-auth | jq -r '.data[]|select(.key=="alice-secret").id')
curl -s -X DELETE $ADMIN/consumers/alice/key-auth/$KID
Keep in mind: a consumer may have several credentials of one type – that is the zero-downtime rotation pattern. You can also auto-generate keys by omitting key.
Lab 27 – Troubleshoot 401 vs 403
Task: A client gets an error calling /anything/x. Decide the cause.
|
Symptom |
Cause |
Check |
|---|---|---|
|
|
Key missing / wrong header name |
|
|
|
Key unknown or credential expired |
|
|
|
ACL deny or group not in allow list |
|
|
|
ip-restriction |
Plugin config, |
|
|
Another auth plugin (basic/jwt) also active, AND logic |
|
curl -s $ADMIN/plugins | jq '.data[]|{name,route:.route.id,service:.service.id,consumer:.consumer.id,enabled}'
Keep in mind: always list plugins at all scopes (global, service, route, consumer) before concluding.