What you will learn
- Recite the order of the checks a call to the main API passes before the handler runs
- Tell which check answers 401, which answers 403 and which answers 400
- Explain why the organisation in the web address is ignored
- Say what an extra permission does when you deploy to a production environment
Before you start
- Sign in to the console and call the API Not started In progress Done
On this page
A call to Agent Manager’s main API looks like one request, but it walks through a row of checks first. If you know the order, you can read an error and say which check stopped you.
This lesson covers the public API under /api/v1. The health, key-set, discovery and config routes, and the internal gateway server, skip this chain.
The chain, in order
Safety nets
The outermost layer catches a crash and turns it into a
500. Next comes CORS, the browser permission check. It answers a browser’sOPTIONSpreflight with204before any token is looked at, which is why a preflight needs no token.Correlation id and logger
The request gets a ticket number, the Correlation idA ticket number given to a request so its log lines can be found together. Agent Manager reuses the x-correlation-id header when sent, and makes one when not.See it in the glossary, and a logger tagged with it. All log lines of one request can be found together later.
Signature check, then issuer and audience
This is the token check of lesson L1.2.2. A missing header gives
401 missing header. A token that fails gives401 invalid jwt. On success AMS stores the claims and the raw token for the next steps.The route is matched and an audit wrapper may start
For changes and a short list of sensitive reads, a recorder writes an Audit trailA record of who tried to do what and whether it was allowed. Agent Manager writes an event when a state changing request ends, refused ones included.See it in the glossary event when the request ends, including refused ones. Most plain reads are not audited.
The organisation comes from the token
Most routes carry
{orgName}in their address, but AMS ignores it. On those routes it takes the organisation from the token claimsouIdandouHandle. If either is missing or empty the answer is403.The scope gate
Almost every route declares the permission it needs, for example
amp:agent:create. AMS compares it with the scopes in the token. A miss answers403 insufficient permissions. On an audited route it also writes an audit event that names the first missing scope.Path parameters, then the handler
Blank parts of the address are refused with
400. Then the handler runs, calls a service, and the service reads or writes Agent Manager’s own database.
The chain is a MiddlewareA step a request passes through before the real handler runs, such as checking a token. Steps are stacked into a chain, and any step can stop the request.Analogy:A row of checkpoints in a corridor: you reach the room only if every checkpoint lets you through.See it in the glossary chain: each step can stop the request, and a request that is stopped does not reach the steps after it. The organisation check runs before the scope gate.
Three answers to remember
| Status | Which check said it |
|---|---|
401 | The token check: no header, bad signature, wrong issuer or wrong audience |
403 | The organisation check or the scope gate |
400 | The path parameter check |
The organisation is not in the web address
Imagine a token for organisation A used on a web address that names organisation B. AMS does not read the name in the address at all. The request acts on organisation A, because that is what the token says. So the address segment is not a way to reach someone else’s data, and it is not a way to choose your organisation either.
One more floor for production
Actions that target a named environment, such as deploying, also call an environment tier check. It looks the environment up in OpenChoreo and requires amp:agent:env-non-production. When the environment is flagged as production it also requires amp:agent:env-production. Production is stacked on top of the floor, not a replacement for it.
Your turn
Under Try it, step through flow F2 and, at each step, say which status it would answer. Then open Break the token: choose a way to break the token, send the request, and note which check turns it away and with which status. Try the option that puts another organisation in the web address and see what happens. Finish with the matcher, which pairs each stage with its job.
Recap
- The chain runs: safety nets, correlation id, token check, audit wrapper, organisation from the token, scope gate, path parameters, handler.
401comes from the token check,403from the organisation or scope check,400from path parameters.- The organisation comes from
ouIdandouHandle. The name in the web address is ignored. - A browser preflight is answered with
204before authentication. - A deploy to a production environment needs
amp:agent:env-productionin addition toamp:agent:env-non-production.
Wrap up
Recap
Tick each one when you could explain it to a colleague.
Finished?
Chapter complete. Every lesson in this chapter is done.
Progress cannot be saved in this browser, so it will be forgotten when you leave this page.
Quick check
Spotted something wrong or unclear in this lesson? Report an inaccuracy (opens GitHub in a new tab)