M3-S2 — Operate the gateway: errors, the shared key and triage
Section titled “M3-S2 — Operate the gateway: errors, the shared key and triage”| Module | M3 — Addresses and the gateway |
| After this session you can | Tell from one error answer where a fault is, prove it in the logs, recover the platform from gateway-level faults, and rotate the shared key safely. |
| Time | Facilitated: 47 min · On your own: 47 min |
| Before you start | M3-S1: customs.localhost routed to the release. |
| Go deeper | Gateway operations · Gateway operations: error responses |
◆ Orientation (1 min) — The gateway tells you where to look
Section titled “◆ Orientation (1 min) — The gateway tells you where to look”When the API fails, the gateway is the first part to answer, and it answers in a fixed shape that names the problem. Read that answer well and you skip half an incident: you know whether to look at Redis, at the identity server, at the administrator’s records or at an application. In this session you cause the common faults yourself, read each answer, and recover.
▤ Concept (5 min) — Error answers, trace ids and the shared key
Section titled “▤ Concept (5 min) — Error answers, trace ids and the shared key”The error envelope
Section titled “The error envelope”Every error the gateway produces has the same JSON shape:
{ "success": false, "error": { "code": "SPACE_ERROR", "message": "Space ID not found", "serviceName": "API Gateway", "traceId": "4f1c2e9a-…", "details": {} }}The code says what failed. The traceId is the request’s correlation id: the same value appears in every log line about this request, in the gateway and in every service it reached. Ask users and integrators to send you the trace id with every report. Infrastructure detail (a Redis error, an upstream’s message) is deliberately left out of the body and written to the gateway’s log instead, so the trace id is how you get to it.
What each answer means
Section titled “What each answer means”| Answer | Means | Look first at |
|---|---|---|
404, HTML body | The ingress does not route this host | ingress.hosts (M3-S1) |
404 SPACE_ERROR | The host belongs to no space | The administrator’s space records; the space list in Redis |
400 DOMAIN_ERROR | The host belongs to no domain | The administrator’s domain Host list |
500 REDIS_ERROR | The gateway cannot read Redis | Redis health and the redis.* values |
401 AUTHENTICATION_ERROR | The token is missing, expired or not active | The caller: sign in again, or a fresh application token |
500 AUTHENTICATION_ERROR | Checking the token failed for a technical reason | Redis, then the identity server |
503 IDENTITY_SERVICE_UNAVAILABLE | The identity server cannot be reached | Identity pods and their Service |
403 SPACE_FORBIDDEN | The person is not a member of this space; the body lists the spaces they can use | The administrator: space membership |
403 INVALID_ACCESS with a reason | Access to a view or route was refused | The administrator: access levels (ACSA M2) |
403 DELEGATION_EXPIRED | The person acted for a colleague outside the delegation’s dates | The administrator: delegation (ACSA M2-S4) |
502 or 504 | The gateway reached no healthy application, or it was too slow | The application’s pod (M5, M7) |
Two thirds of these are not yours to fix: the 403s and the domain and space errors are the
administrator’s records. Your job is to recognize them in seconds and hand them over with the trace
id, instead of restarting things.
What the gateway remembers
Section titled “What the gateway remembers”To stay fast, the gateway caches its checks in Redis, by default for 300 seconds: a token’s validity, a person’s spaces, a delegation, an access decision. Two consequences:
- After the administrator adds someone to a space, the platform clears that person’s cached spaces at once. Other changes can take up to five minutes to be seen. Wait before you escalate.
- While Redis is down, nothing is cached and nothing is routed: the whole API stops at the gateway.
Rate limiting at the gateway counts per gateway pod, not across the cluster: with three gateway replicas, the effective limit is three times the configured one.
The shared key
Section titled “The shared key”The gateway adds the shared key (secrets.sharedKey) to every request it forwards; every service
checks it, and the services use it when they call each other. Gateway and services must therefore
always hold the same key. The chart puts it in two places:
- the gateway’s own configuration, re-rendered on every
helm upgrade(and the gateway restarts itself when it changes); - the Secret
nw-osos-shared, which every service reads at start-up. The chart creates this Secret only on install and keeps it afterwards, so an upgrade with a new key does not change it.
So rotating the key is a short procedure, done in a quiet window, because requests fail between the first and last step:
- Generate the new key and put it in
nw-secrets.yaml. - Write it into the Secret yourself.
helm upgrade, which gives the gateway the new key.- Restart every workload of the release, so the services read the new Secret.
- Run the smoke test.
Rotate when someone who knew the key leaves, when it may have been exposed, and on your own schedule.
⛏ Lab (34 min) — Break it, read it, fix it
Section titled “⛏ Lab (34 min) — Break it, read it, fix it”Goal. Three faults caused, read from their answers, traced in the logs and recovered; then the shared key rotated and the platform proven.
Before you start. The nw release healthy. Keep the answers you get in inventory.md under
Gateway triage: you use them in the M7 drill. kubectl scale changes here are temporary; the next
helm upgrade would also restore them.
Fault 1: Redis is gone
- Stop Redis:
kubectl -n datastores scale deploy/redis --replicas=0. - Call the API:
curl -s http://localhost/api/v1/version. Note the code and the trace id. - Find the trace id in the gateway’s log:
kubectl -n northwind logs deploy/nw-osos-apigateway --since=5m | grep <traceId>. The log line names the Redis connection error the body left out. - Bring Redis back:
kubectl -n datastores scale deploy/redis --replicas=1, wait for it to be ready, and call the API again. The error is gone, with no restart of the platform.
Fault 2: a bad token, then no identity server
- Call with a token that was never issued:
curl -s -H "Authorization: Bearer lab-fake-token" http://localhost/api/v1/spaces/my. Note the code. - Stop the identity server:
kubectl -n northwind scale deploy/nw-osos-identity --replicas=0. - Repeat step 5. Note the new code.
- Restore it:
kubectl -n northwind scale deploy/nw-osos-identity --replicas=1and wait until it is ready.
Fault 3: an unknown address
- Repeat the demo request of M3-S1:
curl -s -H "Host: customs.localhost" http://localhost/api/v1/version. Write down who must act, and what you would send them.
Rotate the shared key
-
Generate a new key and replace the
sharedKeyline innw-secrets.yamlwith it:NEWKEY=$(openssl rand -hex 24), then edit the file. -
Write it into the kept Secret:
Terminal window kubectl -n northwind patch secret nw-osos-shared \-p "{\"stringData\":{\"SHARED_KEY\":\"$NEWKEY\"}}" -
Give the gateway the new key:
helm upgrade nw ./osos -n northwind $values --wait --timeout 15m. -
Restart every workload so the services read the new Secret:
kubectl -n northwind rollout restart deploymentthenkubectl -n northwind rollout status deployment --timeout=15m. -
Run the product part of your smoke test: sign in as
nwoperatorand open Administration. -
Run
unset NEWKEY, so the key does not stay in your shell.
Check.
- Fault 1 answered
500 REDIS_ERROR, and you found its trace id in the gateway log. - Fault 2 answered
401 AUTHENTICATION_ERROR, then503 IDENTITY_SERVICE_UNAVAILABLE. - Fault 3 answered
404 SPACE_ERROR, and your note sends it to the administrator. - Redis and identity are back at one replica each, and ready.
-
nw-secrets.yamlandnw-osos-sharedhold the same new key. - After the rotation, the operator signs in and Administration opens.
Pass condition. All six checks hold, and your triage notes give, for each fault: the answer, the layer, the dependency, and who acts.
If something goes wrong
| What you see | What to do |
|---|---|
Fault 1 returns 502 instead | The ingress may not reach the gateway because the gateway pod restarted; wait and call again. |
| The trace id is not in the log | Widen the window (--since=15m), or check you copied the whole id. |
After the rotation, lists fail with 401-style errors from services | A workload still runs with the old key. kubectl -n northwind get pods and restart any pod older than the rotation. |
| After the rotation, nothing works and the Secret holds the old key | Step 11 did not apply. Run it again, then repeat step 13. |
| Identity does not become ready in step 8 | kubectl -n northwind describe pod on it; a helm upgrade with your values also restores it. |
Model answer
Gateway triage notes
| Fault | Answer | Layer | Dependency | Who acts |
|---|---|---|---|---|
| Redis stopped | 500 REDIS_ERROR | Gateway | Redis | You: restore Redis |
| Fake token | 401 AUTHENTICATION_ERROR | Gateway | The caller’s token | The caller: sign in again |
| Identity stopped | 503 IDENTITY_SERVICE_UNAVAILABLE | Gateway | Identity server | You: restore identity |
| Unknown address | 404 SPACE_ERROR | Gateway | The space records | The administrator: create or activate the space |
The note to the administrator for fault 3: “Requests to customs.localhost reach the platform but
match no space (trace id …). Please create or activate the customs space for that address; nothing
is needed on our side.”
Why the rotation needs step 11. The upgrade alone changes the gateway’s key but leaves the kept Secret, and so the services, on the old key. Between steps 12 and 13 they disagree; after step 13 every pod holds the new key.
✓ Practice (6 min) — Check your understanding
Section titled “✓ Practice (6 min) — Check your understanding”A user reports “403 everywhere in the Customs space” and sends SPACE_FORBIDDEN with a list of
available_spaces that does not include Customs. What do you do?
Check your answer
The correct answer is B. Open the explanation under each option to see why.
The whole API returns 500 REDIS_ERROR, but the portal’s pages still load. Why do the pages work?
Check your answer
The correct answer is A. Open the explanation under each option to see why.
An operator rotates the shared key by changing secrets.sharedKey and running helm upgrade. The
gateway restarts, and then every API request fails. What did they miss?
Check your answer
The correct answer is C. Open the explanation under each option to see why.
A tenant administrator removed a colleague’s access to a view three minutes ago, yet the colleague can still open it. What do you tell the administrator?
Check your answer
The correct answer is B. Open the explanation under each option to see why.
A partner says your API rejects them with 429 at half the request rate you configured. You run
two gateway replicas. Is the limit wrong?
Check your answer
The correct answer is B. Open the explanation under each option to see why.
↺ Recap (1 min) — After Module 3 you can
Section titled “↺ Recap (1 min) — After Module 3 you can”After this module you can set up an address for a space or a partner domain through both layers, read any gateway answer and say where to look, follow a request by its trace id, recover from gateway-level faults, and rotate the shared key without breaking trust.
Next. Module 4 carries out the administrator’s other hand-offs from ACSA: single sign-on and the identity server, the directory import, message delivery and the brand, then the keys and backups that protect the data.