Lesson 65.10 · 10 of 10 · 8 min read · Reviewed 24 Nov 2026
Agent identity, delegated access and the confused deputy
By the end, you can
- Give an agent an identity of its own and decide when it acts as itself or for a user.
- Spot and prevent the confused deputy problem in agent tool calls.
The first question an enterprise security review asks about an agentAgent: A system where a model decides its own next steps, calling tools in a loop until the task is done. is simple: when it calls a system, whose authority is it using? “The agent’s API key” is usually the wrong answer. This lesson covers the identity design that gives a better one.
Two kinds of action
| The agent acts… | Example | Identity to use |
|---|---|---|
| As itself | A nightly job that tags new tickets | The agent’s own workload identity, with only the permissions that job needs |
| On behalf of a user | “Refund my last order”, “Summarise my inbox” | The user’s delegated authority, narrowed to the task, with the agent recorded as the actor |
Most assistants do the second kind. Treating them like the first, with one powerful service account, is the root of many agent data leaks.
Give every agent its own identity
An agent should not borrow a developer’s personal key or a shared team secret. Give each agent, or each agent deployment, an identity of its own:
- Workload identity from your cloud platform or a standard such as SPIFFE: short-lived credentials issued to the running service, with no secret stored in code or config.
- One identity per agent role, not one for “the AI”. The research agent and the billing agent get different permissionsPermission rule: An allow, ask or deny rule that controls which tools, commands or paths a coding agent may use. (65.5).
- Recorded in every log line, so an audit can say which agent did what (66.1).
- Revocable on its own. If one agent misbehaves, you switch it off without breaking every other service.
Act for the user with delegated, scoped tokens
When the user asks the agent to do something, the downstream system should apply the user’s permissions:
- The user signs in to the app. The app holds the user’s tokenToken: The unit a model reads and writes: a word, part of a word, a space or a symbol, mapped to an integer id..
- Before a tool call, the agent’s backend performs a token exchangeToken exchange: An OAuth flow (RFC 8693) that swaps one token for another with a different audience and narrower scope. (RFC 8693): it presents the user’s token plus its own identity and asks for a new token.
- The authorization server issues a token that is short-lived (minutes), for one audience (the billing API, say), with narrow scope (
orders.refundfor this customer), and that names both the user and the agent as the actor. - The billing API checks it exactly as it would a request from the user directly. It can’t do more than the user could.
This is the same rule as MCPModel Context Protocol (MCP): An open protocol that standardises how AI applications connect to tools, data and prompts through servers.’s ban on token passthroughToken passthrough: Forwarding a token you received to another service that it was not issued for. (36.5): each hop gets a token made for that hop.
The confused deputy
A confused deputyConfused deputy: A program with more authority than its caller that is tricked into using that authority for the caller. is a program with more authority than its caller, tricked into using that authority on the caller’s behalf. Agents are ideal deputies: they hold credentials, they take instructions in plain language, and they read untrusted text.
| How it happens | Example |
|---|---|
| The user asks for something they may not have | “Show me order 4471” when that order belongs to someone else |
| Injected text asks for it (65.2) | A web page tells the agent to fetch the admin report and paste it here |
| A malicious MCP server reuses what it was given | It receives a token and replays it against another service |
The fix is the same each time: check the end user’s rights at the system that holds the data, using the user’s delegated token, and keep the agent’s own identity for actions that genuinely belong to it.
Human approval and consent
- Ask the user to consent to the scopes an agent will use, in plain words, at the moment they are needed.
- For high-impact actions, an approval step still applies even with a valid token (64.5). A token proves permission; it doesn’t prove the user meant this particular refund.
- Let users see and revoke what each agent can do.
Common mistakes
- One service account for every user. Every user can reach everything the agent can.
- Long-lived tokens stored with the agent. A stolen token works for months. Keep them short and refresh through the identity provider.
- Checking permissions in the prompt. “Only show the user their own orders” is not access control.
- No actor in the logs. You can see that “the API” made a call, but not which agent or which user asked.
Key points
- An agent needs its own identity, separate from any user, so you can grant, limit, audit and revoke what it does.
- When an agent acts for a user, it should carry that user's delegated, narrowly scoped authority, not a shared service account.
- Token exchange swaps a user's token for a short-lived one scoped to a single downstream service, recording both the user and the agent.
- A confused deputy is a privileged agent tricked into using its power for someone who lacks it. Check the user's rights, not just the agent's.
Redesign an agent's identity and access
Find the confused deputy risks in one agent and redesign it to use its own identity for its own work and delegated user tokens for user work.
You will have: A table of the agent's tool calls with, for each, whose authority it uses today, whose it should use, the token's audience and scope, and the approval rule.
Steps
- List every tool call your agent, or a sample support agent, can make, and the credential each one uses today.
- Mark each call as acting as the agent itself or on behalf of a user.
- For user calls, write the delegated token it should carry: audience, scope, lifetime, and that both user and agent are recorded.
- For agent calls, give the agent a workload identity with only the permissions those calls need.
- Write two attack prompts, one from a user asking for someone else's data and one from injected text, and show which control in your table stops each.
Done when
- No user-facing tool call still uses a shared service account.
- Every token in the table has one audience and a lifetime in minutes.
- Both attack prompts are stopped by a control in code, not by a prompt.
Docs: RFC 8693: OAuth 2.0 Token Exchange · OWASP: Excessive Agency
Finished the chapter? Take the chapter check.