Kong Gateway Certified Associate – Practical Lab Scenarios – Part C

Exam-style hands-on labs with Kong Manager (UI) steps, Admin API / decK / CLI commands, verification and gotchas.

Part 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)

  1. Config exists: curl -s $ADMIN/services | jq , /routes, /plugins, /consumers, /upstreams/<name>/targets.
  2. Traffic test with headers visible: curl -i ... (never plain curl – status line and headers are your evidence).
  3. 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)

  1. 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.
  2. Logs: default prefix /usr/local/kong/logs/ → error.log, access.log. In Docker: docker logs <kong>.
  3. Declarative / DB-less mode is read-only through the Admin API (POST/PUT/PATCH/DELETE return 405). Change kong.yml and reload.
  4. 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:

  1. Gateway Services → orders-svc → Plugins → New Plugin → Key Authentication → Create.
  2. Consumers → New Consumer alice → open → Credentials → New Key Auth Credential → Key alice-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

401 No API key found in request

Key missing / wrong header name

config.key_names, curl -v

401 Invalid authentication credentials

Key unknown or credential expired

GET /consumers/<c>/key-auth

403 You cannot consume this service

ACL deny or group not in allow list

GET /consumers/<c>/acls, plugin config.allow

403 Your IP address is not allowed

ip-restriction

Plugin config, X-Forwarded-For / real_ip settings

401 while Authorization header is hidden

Another auth plugin (basic/jwt) also active, AND logic

GET /routes/<r>/plugins + service/global plugins

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.

Leave a Reply

Your email address will not be published. Required fields are marked *