#232 Enterprise architecture and AI agents 5.4 min
Give Every AI Agent Its Own Identity
Your agents all share one API key. When one overwrites a file, the log cannot say which. Here is the fix.
Read the log of the seven calls
Copy the code folder first. This needs PyJWT 2.15.1 from requirements.txt. Run python cases.py. Match each denied line in the log at the bottom to the case that caused it, using the order of the cases in cases.py. Write down which denial reasons name the agent and which show a question mark in its place, and why the question mark appears.
A hint
Look at the check function in gateway.py. The agent name is only read after the token has been decoded successfully.
A token that has not expired yet
In cases.py, change time.time() - 600 to time.time() - 120 in the expired line. Predict whether that token is still denied, using the lifetime of an issued token in gateway.py. When I ran it, the line read expired token: allowed.
A hint
The default lifetime in the issue function is the minutes argument.
Let the editor delete
In gateway.py, add "files:delete" to the scopes of agent-editor in REGISTRY. In cases.py, add "files:delete" to the editor token and add a case ('editor deletes a file', editor, 'delete_file') after the editor write. Predict the result, then run python cases.py. When I ran it, the new case was allowed, the reader's delete was still denied, and the log named agent-editor.
A hint
The registry says what each agent may ever hold. The token then carries the scope, and the gateway checks it.
Ask the issuer for too much
In shared_key.py, change the agent in the last call from agent-editor to agent-reader, so the reader tries to write report.pdf. Predict what happens before you run python shared_key.py. When I ran it, the program stopped with PermissionError: agent-reader may not hold files:write. Say in one sentence why that is better than the gateway refusing the call later.
A hint
The video tip is to make the issuer say no first, so there is nothing to steal.
These tasks are for you to try on your own machine. Nothing is checked or saved.
What this does not show
Made-up users, agents and key, and no model. One shared secret signs and checks, so any service that can check a token could also mint one. No key rotation, revocation or token exchange. The shared-key log is printed, not run. A token limits damage; it does not make a tool safe.
Up next in Enterprise architecture and AI agents
More in Enterprise architecture and AI agents
- #229 A Reference Architecture for Enterprise AI Agents, as Code
- #230 Agent Gateway: One Front Door for Models, Tools, Agents
- #231 MCP Gateway: Per-Tool Policy for Agent Tools (Python)
- #234 Authorisation for AI Agents With Policy as Code (Cedar)
- #235 An End-to-End Audit Trail for AI Agent Actions in Python
