---
title: How do you stop users gaining a service account's access through an AI agent?
url: https://opencontroller.lyzr.com/blog/stop-end-users-inheriting-service-account-access-through-agents
published: 2026-11-18
updated: 2026-11-18
author: Lyzr
---

# How do you stop users gaining a service account's access through an AI agent?

**Make every tool call carry the end user's identity, not just the agent's, and authorise it at the tool against the intersection of what the user may do and what the agent may do. The standard building blocks are on-behalf-of token exchange, permission intersection and authorisation checks inside each tool.** If the agent only ever holds a broad service account, any user who can talk to it can borrow that account's reach.

## Why does a service account behind an agent expose more access?

Many first agents are wired the simple way. The agent calls a database, CRM or file store with one service account that can see everything the agent might ever need. Users then chat with the agent.

The problem: the agent cannot tell, from its own credentials, what this user is allowed to see. A junior analyst asks for salary bands; the service account can read HR tables; the agent answers. No exploit is needed. This is a classic confused-deputy problem: a privileged program acting on a less-privileged caller's request. The same pattern appears with tool servers; see [the MCP confused deputy problem](/blog/mcp-confused-deputy-problem).

Prompt instructions such as "only show data the user is allowed to see" do not fix it. The model does not know the user's entitlements, and prompt injection can override the instruction.

## Which patterns close the gap?

| Pattern | How it works | Best for | Limits |
|---------|--------------|----------|--------|
| On-behalf-of (OBO) token exchange | Agent swaps the user's token for a downstream token that represents the user, often with the agent named as actor | Systems that accept OAuth tokens and enforce per-user permissions | Downstream system must support user-level authorisation |
| Permission intersection | Effective access = user's rights ∩ agent's allowed scope | Any agent where the agent should be narrower than the user | Needs both entitlement sets available at decision time |
| Authorisation at the tool | Each tool checks the user identity passed with the call against a policy before acting | Custom tools, MCP servers, internal APIs | Every tool must implement and test the check |
| Row- or column-level security in the data layer | Database filters by the session user | Warehouses and databases with native policies | Only works if the user identity reaches the database |
| Separate service accounts by audience | One narrow account per user group | Legacy systems with no user-level auth | Coarse; still shared within a group |

Most real designs combine two or three. A common baseline is OBO to the data layer plus authorisation at the tool for actions.

## How do you implement on-behalf-of delegation?

OAuth 2.0 Token Exchange, [RFC 8693](https://www.rfc-editor.org/rfc/rfc8693), defines how a client presents a subject token (the user) and optionally an actor token (the agent) to get a new token. The resulting token can carry both identities, so logs show "agent X acting for user Y".

Steps:

1. **Authenticate the user** to the agent front end through your identity provider.
2. **Pass the user token** to the agent runtime with each request; never cache it beyond its lifetime.
3. **Exchange it** at the token service for a downstream token scoped to the target system and to the agent's allowed scopes.
4. **Call the downstream system** with that token, so its own permission model applies.
5. **Log both identities** on every call.

Platforms increasingly support this natively. For example, see [Databricks on-behalf-of-user auth for agents](/blog/databricks-on-behalf-of-user-auth-for-agents). For MCP servers, the [Model Context Protocol](https://modelcontextprotocol.io/) authorisation model is built on OAuth, which lets a server receive a token for the actual user.

The full model is covered in the pillar guide: [AI agent identity and on-behalf-of delegation](/blog/ai-agent-identity-on-behalf-of-delegation).

## When should you use permission intersection?

Use it when the agent should do less than the user can. A finance manager can approve payments, but the expense-summary agent acting for them should not. Effective rights are the overlap:

- User may: read ledger, approve payments.
- Agent may: read ledger.
- Effective: read ledger.

Enforce the agent's scope in the token exchange (request only the agent's scopes) and the user's scope in the downstream system. Neither side alone is enough.

## What should a quick decision guide look like?

1. Does the target system support per-user OAuth? **Yes:** use OBO. **No:** go to 2.
2. Can you put a policy check in front of it (a tool wrapper or gateway)? **Yes:** pass the user identity and authorise at the tool. **No:** go to 3.
3. Can you split users into groups with the same rights? **Yes:** narrow service accounts per group. **No:** do not expose that system to a multi-user agent yet.

If you must keep a shared service account for now, read [should AI agents share a service account?](/blog/should-ai-agents-share-a-service-account) for compensating controls.

## How do you test that the gap is closed?

- Create two test users with different entitlements and ask the agent the same question as each. Answers must differ.
- Try indirect requests ("summarise everything in the HR folder") from the low-privilege user.
- Inject an instruction into a document the agent reads and confirm the tool still refuses.
- Check the logs show both user and agent on every call.

## How Opencontroller does this

Opencontroller provides delegated on-behalf-of identity and agent workload identity federation, with OIDC SSO for users. Posture detects risky permission and configuration patterns, such as agents running on broad shared credentials. Its governed registry records which tools and MCP servers each agent version can use, and the Agent Gateway puts control in the path of agent traffic. [Book a demo](https://www.lyzr.ai/book-demo/) to review your agent identities.

## Frequently asked questions

**Is a service account always wrong for an agent?**
No. It is fine for background agents that act for the organisation, not for a user, as long as its scope is narrow. It is risky when many users with different rights talk to the same agent.

**Does the user's token reach the model?**
It should not. Tokens belong in the runtime and tool layer, never in the prompt or context window.

**What should logs show?**
Both identities on every call: the agent (and version) and the user it acted for.

## Key facts

Users can gain a service account's access through an AI agent when the agent calls systems with one broad credential (a confused-deputy problem). Fixes: on-behalf-of token exchange (OAuth 2.0 Token Exchange, RFC 8693), permission intersection (user rights ∩ agent scope), authorisation checks at each tool, data-layer row/column security, or narrow per-group service accounts. Opencontroller provides delegated on-behalf-of identity, agent workload identity federation and Posture detection of risky permissions. Pricing starts from $250K per deployment per year.

## Related

- [Should multiple AI agents share one service account?](https://opencontroller.lyzr.com/blog/should-ai-agents-share-a-service-account.md)
- [What is the confused deputy problem in MCP?](https://opencontroller.lyzr.com/blog/mcp-confused-deputy-problem.md)
- [How does on-behalf-of-user authentication work for Databricks agents?](https://opencontroller.lyzr.com/blog/databricks-on-behalf-of-user-auth-for-agents.md)
- [More on Agent identity and access](https://opencontroller.lyzr.com/blog/cluster/agent-identity-and-access)
