Part D – Traffic Control and Security Plugins
Exam-style hands-on labs with Kong Manager (UI) steps, Admin API / decK / CLI commands, verification and gotchas.
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 28 – Rate limiting: 5 requests per minute
Task: Limit callers of orders-route to 5 requests/minute and return headers showing the quota.
UI: Route → Plugins → Rate Limiting → Minute 5, Policy local → Create.
curl -s -X POST $ADMIN/routes/orders-route/plugins --data name=rate-limiting \
--data config.minute=5 --data config.policy=local
for i in $(seq 1 7); do curl -s -o /dev/null -w "%{http_code}\n" $PROXY/anything/x; done
curl -i $PROXY/anything/x | grep -i ratelimit
Verify: first 5 → 200, then 429 API rate limit exceeded. Headers X-RateLimit-Limit-Minute: 5, X-RateLimit-Remaining-Minute.
Keep in mind: policy: local (per node, in memory), cluster (DB, accurate but slower; not in hybrid DP), redis (shared across nodes). limit_by: consumer (default), credential, ip, service, header, path. If limit_by=consumer but no consumer is identified, Kong falls back to IP.
Lab 29 – Different limits per consumer
Task: alice 10/min, dave 2/min on the same route.
curl -s -X POST $ADMIN/consumers/alice/plugins --data name=rate-limiting --data config.minute=10 --data config.policy=local
curl -s -X POST $ADMIN/consumers/dave/plugins --data name=rate-limiting --data config.minute=2 --data config.policy=local
Verify: hit the route with each key; dave gets 429 on the 3rd call. The route-level plugin from Lab 28 is overridden for these consumers because a consumer-scoped plugin is more specific.
Keep in mind: the consumer must be authenticated (key-auth/basic/jwt enabled) for consumer-scoped plugins to apply.
Lab 30 – Request size limit
Task: Reject request bodies larger than 1 MB (413).
curl -s -X POST $ADMIN/services/orders-svc/plugins --data name=request-size-limiting \
--data config.allowed_payload_size=1 --data config.size_unit=megabytes
head -c 2000000 /dev/zero > big.bin
curl -i -X POST $PROXY/anything/x --data-binary @big.bin # 413 Request size limit exceeded
Keep in mind: default unit is megabytes with size 128. require_content_length=true rejects chunked uploads without a length.
Lab 31 – Response caching with proxy-cache
Task: Cache GET responses for 30 s in memory.
curl -s -X POST $ADMIN/routes/orders-route/plugins --data name=proxy-cache \
--data config.strategy=memory --data config.content_type[]=application/json \
--data config.cache_ttl=30 --data 'config.request_method[]=GET'
curl -si $PROXY/anything/cache | grep -i x-cache # X-Cache-Status: Miss
curl -si $PROXY/anything/cache | grep -i x-cache # X-Cache-Status: Hit
Keep in mind: statuses: Miss, Hit, Refresh, Bypass. Default content_type is text/plain, application/json. Purge: DELETE $ADMIN/proxy-cache or /proxy-cache/<plugin-id>/<cache-key>. Cache key includes consumer/route/method/path/query.
Lab 32 – CORS
Task: Allow browser calls from https://app.example.com with methods GET/POST and credentials.
curl -s -X POST $ADMIN/routes/orders-route/plugins --data name=cors \
--data 'config.origins[]=https://app.example.com' \
--data 'config.methods[]=GET' --data 'config.methods[]=POST' \
--data 'config.headers[]=Authorization' --data 'config.headers[]=Content-Type' \
--data config.credentials=true --data config.max_age=3600
curl -i -X OPTIONS $PROXY/anything/x \
-H 'Origin: https://app.example.com' -H 'Access-Control-Request-Method: POST'
Verify: Access-Control-Allow-Origin: https://app.example.com and Access-Control-Allow-Methods in the pre-flight response.
Keep in mind: with credentials=true you must not use * for origins. Pre-flight OPTIONS is answered by Kong; ensure auth plugins do not block OPTIONS (the CORS plugin runs first).
Lab 33 – IP restriction
Task: Allow only 192.168.0.0/16 and 127.0.0.1.
curl -s -X POST $ADMIN/services/orders-svc/plugins --data name=ip-restriction \
--data 'config.allow[]=127.0.0.1' --data 'config.allow[]=192.168.0.0/16'
curl -i $PROXY/anything/x # from allowed IP -> 200
curl -i $PROXY/anything/x -H 'X-Forwarded-For: 8.8.8.8' # depends on trusted_ips
Keep in mind: behind a load balancer set trusted_ips and real_ip_header in kong.conf or Kong sees the LB IP. Denied → 403 Your IP address is not allowed.
Lab 34 – Maintenance mode with request-termination
Task: Return 503 with a message for a route without touching the upstream.
curl -s -X POST $ADMIN/routes/orders-route/plugins --data name=request-termination \
--data config.status_code=503 --data config.message='Down for maintenance'
curl -i $PROXY/anything/x
Verify: 503 {"message":"Down for maintenance"}. Disable with PATCH /plugins/<id> --data enabled=false.
Keep in mind: this plugin can also be attached to a consumer to block a single client (status_code=403).
Lab 35 – Consumer groups and tiered limits [EE]
Task: Gold consumers 100 req/min, Silver 10 req/min using Consumer Groups.
UI (Kong Manager EE): Consumer Groups → New group gold → add consumer alice; Plugins → Rate Limiting Advanced → scope to Consumer Group gold.
curl -s -X POST $ADMIN/consumer_groups --data name=gold
curl -s -X POST $ADMIN/consumer_groups/gold/consumers --data consumer=alice
curl -s -X PUT $ADMIN/consumer_groups/gold/overrides/plugins/rate-limiting-advanced \
--data config.limit=100 --data config.window_size=60
Keep in mind: a consumer group is not an ACL group. Consumer-group overrides require rate-limiting-advanced enabled on the route/service/global first.