Lesson 2 of 69 minReviewed
Agent identity and least privilege
Choose how an agent authenticates, keep the end user visible in every action, and manage agent credentials as non-human identities with narrow, short-lived scope.
Every action an agent takes is performed by some identity, and that identity decides two things: what the action is allowed to touch, and what the logs will say afterwards. Most agent deployments use one of three patterns.
| Pattern | What the logs show | Main risk |
|---|---|---|
| Shared service account or static API key | The service, never the person | Every user's request runs with the union of everyone's privileges, and a confused-deputy attack leaves no trail to the requester |
| The user's own credential handed to the agent | The user, never the agent | The agent can do everything the user can, usually with a long-lived token stored on disk |
| A delegated token issued to the agent on the user's behalf | Both the user and the agent | Needs an authorisation server and token plumbing, but scope and lifetime can match the task |
OWASP's guidance for LLM extensions points to the third pattern: run each extension in the user's context, with the minimum scope necessary, and enforce authorisation in the downstream system rather than trusting the model to do it, which OWASP calls complete mediation [1]. OAuth already has a standard for the delegation step: RFC 8693 token exchange lets a service trade one token for another that acts on behalf of a subject, and can record the acting party in an act claim so the downstream system sees who delegated to whom [2].
Agent credentials are non-human identities
API keys, OAuth clients and service accounts used by agents and MCP servers are non-human identities (NHIs), and they fail in the ways OWASP's NHI Top 10 (2025) describes [3]:
- Secret Leakage (NHI2) and Long-Lived Secrets (NHI7): a personal access token pasted into an MCP client configuration file, valid until someone remembers to revoke it.
- Overprivileged NHI (NHI5): an account-wide token used by a server that only needs one repository.
- NHI Reuse (NHI9): one key shared by several agents or servers, so a leak in one exposes all of them and logs cannot tell them apart.
- Human Use of NHI (NHI10): a developer borrowing the agent's token to debug, which erases the line between human and automated activity.
- Improper Offboarding (NHI1): the agent is retired but its credentials keep working.
Practices that hold up
- One identity per agent and per environment. Never share an identity across agents, and never let people use it.
- One credential per tool or server. The MCP project's local-server guidance recommends giving each server its own narrowly scoped token through per-server configuration instead of secrets exported globally in a shell profile, so a leak is contained and revocable [4].
- Short lifetimes. Prefer credentials issued at launch by a broker or secrets manager, and rotate whatever a server held when you remove it [4].
- Audience binding. For remote MCP servers, tokens must be issued for that specific server; servers must reject tokens issued for other resources and must not pass them on [5].
- Least privilege as a release gate. OWASP's agent cheat sheet recommends treating any change to credential scope as a trigger for review, and checking the caller's permissions at the receiving service rather than trusting that a message is well formed or signed [6].
Privilege drops to the least trusted input
Identity alone does not settle the question. An agent acting for an administrator that reads an attacker's email lets that email borrow the administrator's privileges. OWASP's agentic list names this class Identity and Privilege Abuse (ASI03) [7]. Two design responses follow: give tasks that process outside content a separate, lower-privileged identity, and make the high-privilege identity unusable without the approval steps covered later in this path.
Try it on ThreatDeck
- Give AI agents identity and least privilege The checklist for identities, scopes and credential lifetimes, with vendor questions.
- Identity and Privilege Abuse (ASI03) Recent cases where agents were used to exercise someone else's privileges.
- Detection: Entra consent granted to an AI application Find OAuth grants that give AI apps standing access to user data.
- Credentials from AI Agent Configuration (ATLAS) How attackers harvest the tokens agents and MCP clients leave in config files.
Self-check
4 questionsPick an answer to see whether it is right and why. Only your score is saved, in this browser.
-
With a shared account you cannot attribute actions to a requester, and any user can make the agent act with privileges they do not have themselves, which is the confused-deputy pattern.
-
Complete mediation puts the access decision where the resource lives. If the model is persuaded to request something it should not, the downstream check still refuses.
-
A person acting with a machine identity breaks attribution and widens where the secret lives. Give developers their own scoped credentials for debugging instead.
-
Token exchange lets the agent trade the user's token for a narrower one for a specific downstream service, and the act claim keeps both the user and the agent visible to that service.
References
- LLM06:2025 Excessive Agency. OWASP GenAI Security Project, 2024-11.
- RFC 8693: OAuth 2.0 Token Exchange. IETF, 2020-01.
- OWASP Non-Human Identities Top 10 (2025). OWASP, 2025.
- MCP Local Server Security. Model Context Protocol, 2026-07-28.
- MCP specification: Authorization (2026-07-28). Model Context Protocol, 2026-07-28.
- AI Agent Security Cheat Sheet. OWASP Cheat Sheet Series.
- OWASP Top 10 for Agentic Applications for 2026. OWASP GenAI Security Project, 2025-12.