learning-it by example

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

1. Why does giving every agent its own signed token answer the question of which agent overwrote a file, when a shared API key does not?
2. In a delegated agent token (a JWT), which claim holds the person and which claim holds the agent?
3. In the PyJWT tool-gateway demo, how did the gateway stop a token whose scope was edited by hand to add a delete scope?
4. In the PyJWT tool-gateway demo, a token with the algorithm set to none was refused. What is the reason?
5. For signed, scoped agent tokens, which statement about what a good token does and does not do is correct?

Practice only: nothing is saved and no score counts towards anything. Each answer comes with the reason.

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

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

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

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

All Enterprise architecture and AI agents videos

Related videos