Skip to content

M3-S2 — Operate the gateway: errors, the shared key and triage

Section titled “M3-S2 — Operate the gateway: errors, the shared key and triage”
ModuleM3 — Addresses and the gateway
After this session you canTell 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.
TimeFacilitated: 47 min · On your own: 47 min
Before you startM3-S1: customs.localhost routed to the release.
Go deeperGateway 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”

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.

AnswerMeansLook first at
404, HTML bodyThe ingress does not route this hostingress.hosts (M3-S1)
404 SPACE_ERRORThe host belongs to no spaceThe administrator’s space records; the space list in Redis
400 DOMAIN_ERRORThe host belongs to no domainThe administrator’s domain Host list
500 REDIS_ERRORThe gateway cannot read RedisRedis health and the redis.* values
401 AUTHENTICATION_ERRORThe token is missing, expired or not activeThe caller: sign in again, or a fresh application token
500 AUTHENTICATION_ERRORChecking the token failed for a technical reasonRedis, then the identity server
503 IDENTITY_SERVICE_UNAVAILABLEThe identity server cannot be reachedIdentity pods and their Service
403 SPACE_FORBIDDENThe person is not a member of this space; the body lists the spaces they can useThe administrator: space membership
403 INVALID_ACCESS with a reasonAccess to a view or route was refusedThe administrator: access levels (ACSA M2)
403 DELEGATION_EXPIREDThe person acted for a colleague outside the delegation’s datesThe administrator: delegation (ACSA M2-S4)
502 or 504The gateway reached no healthy application, or it was too slowThe 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.

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 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:

  1. Generate the new key and put it in nw-secrets.yaml.
  2. Write it into the Secret yourself.
  3. helm upgrade, which gives the gateway the new key.
  4. Restart every workload of the release, so the services read the new Secret.
  5. 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

  1. Stop Redis: kubectl -n datastores scale deploy/redis --replicas=0.
  2. Call the API: curl -s http://localhost/api/v1/version. Note the code and the trace id.
  3. 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.
  4. 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

  1. 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.
  2. Stop the identity server: kubectl -n northwind scale deploy/nw-osos-identity --replicas=0.
  3. Repeat step 5. Note the new code.
  4. Restore it: kubectl -n northwind scale deploy/nw-osos-identity --replicas=1 and wait until it is ready.

Fault 3: an unknown address

  1. 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

  1. Generate a new key and replace the sharedKey line in nw-secrets.yaml with it: NEWKEY=$(openssl rand -hex 24), then edit the file.

  2. Write it into the kept Secret:

    Terminal window
    kubectl -n northwind patch secret nw-osos-shared \
    -p "{\"stringData\":{\"SHARED_KEY\":\"$NEWKEY\"}}"
  3. Give the gateway the new key: helm upgrade nw ./osos -n northwind $values --wait --timeout 15m.

  4. Restart every workload so the services read the new Secret: kubectl -n northwind rollout restart deployment then kubectl -n northwind rollout status deployment --timeout=15m.

  5. Run the product part of your smoke test: sign in as nwoperator and open Administration.

  6. 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, then 503 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.yaml and nw-osos-shared hold 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 seeWhat to do
Fault 1 returns 502 insteadThe ingress may not reach the gateway because the gateway pod restarted; wait and call again.
The trace id is not in the logWiden the window (--since=15m), or check you copied the whole id.
After the rotation, lists fail with 401-style errors from servicesA 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 keyStep 11 did not apply. Run it again, then repeat step 13.
Identity does not become ready in step 8kubectl -n northwind describe pod on it; a helm upgrade with your values also restores it.
Model answer

Gateway triage notes

FaultAnswerLayerDependencyWho acts
Redis stopped500 REDIS_ERRORGatewayRedisYou: restore Redis
Fake token401 AUTHENTICATION_ERRORGatewayThe caller’s tokenThe caller: sign in again
Identity stopped503 IDENTITY_SERVICE_UNAVAILABLEGatewayIdentity serverYou: restore identity
Unknown address404 SPACE_ERRORGatewayThe space recordsThe 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”
PracticeChoose one answer.

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?

  1. Explanation for A

    ✗ Incorrect

    Not this one: the gateway is answering correctly; the person is not a member of that space. See What each answer means.

  2. Explanation for B

    ✓ Correct

    Correct: space membership is the administrator’s record; adding someone clears their cached spaces at once. See What each answer means.

  3. Explanation for C

    ✗ Incorrect

    Not this one: the request reached the gateway and the space was found; membership failed. See What each answer means.

Check your answer

The correct answer is B. Open the explanation under each option to see why.

PracticeChoose one answer.

The whole API returns 500 REDIS_ERROR, but the portal’s pages still load. Why do the pages work?

  1. Explanation for A

    ✓ Correct

    Correct: only /api goes through the gateway, which cannot route without Redis. See What the gateway remembers.

  2. Explanation for B

    ✗ Incorrect

    Not this one: they load fresh; they simply do not need the gateway. See What the gateway remembers.

  3. Explanation for C

    ✗ Incorrect

    Not this one: the web portal uses no Redis at all. See What the gateway remembers.

Check your answer

The correct answer is A. Open the explanation under each option to see why.

PracticeChoose one answer.

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?

  1. Explanation for A

    ✗ Incorrect

    Not this one: an install would not help either; the kept Secret survives. See The shared key.

  2. Explanation for B

    ✗ Incorrect

    Not this one: the gateway already holds the new key; the services do not. See The shared key.

  3. Explanation for C

    ✓ Correct

    Correct: the chart writes that Secret only on install, so a rotation updates it by hand and then restarts the workloads. See The shared key.

Check your answer

The correct answer is C. Open the explanation under each option to see why.

PracticeChoose one answer.

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?

  1. Explanation for A

    ✗ Incorrect

    Not this one: the change applies by itself when the cached decision expires. See What the gateway remembers.

  2. Explanation for B

    ✓ Correct

    Correct: access decisions are cached for 300 seconds by default. See What the gateway remembers.

  3. Explanation for C

    ✗ Incorrect

    Not this one: the change is saved; only the cached decision is older. See What the gateway remembers.

Check your answer

The correct answer is B. Open the explanation under each option to see why.

PracticeChoose one answer.

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?

  1. Explanation for A

    ✗ Incorrect

    Not this one: it is the other way round; each replica counts on its own, so the total is higher, not lower. See What the gateway remembers.

  2. Explanation for B

    ✓ Correct

    Correct: with local counting, two replicas allow about twice the configured rate. See What the gateway remembers.

  3. Explanation for C

    ✗ Incorrect

    Not this one: the gateway’s rate limit counts in each pod’s memory, not in Redis. See What the gateway remembers.

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.