Skip to content
TrustHappens
Cybersecurity & Identity

How to Secure AI Agents in Enterprise Environments

A practical control set for AI agents: per-agent identities, scoped tool entitlements, audience-bound tokens for MCP servers, action gates and logs you can attribute.

TrustHappens Editorial TeamPublished 6 min read
Illustration for Cybersecurity & Identity
On this page

An AI agent is software that decides which actions to take, then takes them with whatever access it has been given. That second half is where enterprise risk lives. A chat assistant that only answers questions can embarrass you; an agent that can merge pull requests, issue refunds, query production databases or send email can change things.

Securing agents is therefore mostly an identity and authorisation problem, with one unusual property: the decision-maker can be steered by text it reads, including text written by an attacker. This article sets out a threat model you can explain in one meeting and a control set you can roll out incrementally.

Why agents are an identity problem first

Every agent action ends as an API call made with a credential. Ask three questions about any agent in your environment:

  1. Whose identity does it act as? Its own, the requesting user's, or a shared integration account?
  2. What can that identity reach? Not just the agent's tools, but everything the credentials behind those tools allow.
  3. Who decides, at the moment of the call, whether this action should happen? The model alone, a policy, or a person?

If the honest answers are "a developer's token", "most of the org" and "the model", the agent has what OWASP calls excessive agency. LLM06:2025 in the OWASP Top 10 for LLM Applications describes it as damaging actions performed in response to unexpected, ambiguous or manipulated model outputs, and traces it to excessive functionality, excessive permissions and excessive autonomy. Those three causes map neatly onto controls.

The threat model in one page

ThreatWhat it looks likePrimary control
Prompt injection (direct or indirect)A ticket, web page or document contains instructions the agent followsLimit what the agent can do, not just what it reads
Excessive permissionsThe agent's token can delete repositories when it only needs to commentPer-agent identity and least privilege
Excessive functionalityA "read files" tool that also runs shell commandsNarrow, purpose-built tools
Excessive autonomyIrreversible actions with no checkpointApproval gates for consequential actions
Confused deputyAn MCP proxy uses its own broad credentials on behalf of any callerPer-client consent and audience-bound tokens
Token passthroughAn MCP server forwards a client's token to a downstream APIAccept only tokens issued for the server
Compromised MCP server or toolA third-party or local server exfiltrates data or misreports its toolsInventory, provenance and isolation
Unattributed actionsLogs show a shared service account, not which agent or userDistinct identities and structured audit logs

The OWASP GenAI Security Project's Agentic AI Threats and Mitigations guidance covers agent-specific threats in more depth and is worth reading alongside this table.

Seven controls for enterprise agents

1. Give every agent its own identity

Register each agent as a first-class non-human identity with a name, owner, purpose and environment. Do not let agents run on personal access tokens or a shared "automation" key. A distinct identity is what lets you scope, review, rotate and attribute.

Where the agent acts on behalf of a user, prefer delegation over impersonation. OAuth 2.0 Token Exchange (RFC 8693) defines how a service can exchange a user's token for a new token that represents the delegation, including an act (actor) claim that records who is acting. Downstream systems then see both the user and the agent, and can apply rules to each.

2. Scope tools, not just credentials

An agent's effective permission set is the union of its tools and the credentials behind them. Record both as an entitlement: which tools, which operations, which resources, in which environment. An illustrative entitlement record might look like this (the format is ours, not a standard):

agent-entitlements.yaml
agent: support-triage-agent
owner: team-support-platform
environment: production
tools:
  - server: ticketing-mcp
    allow: [tickets.read, tickets.comment]
    deny: [tickets.delete, users.*]
  - server: kb-search-mcp
    allow: [search]
requires_approval:
  - tickets.close
  - refunds.create
credential: federated
max_token_lifetime: 15m

Prefer many narrow tools over one powerful tool. A run_sql tool with a read-write connection is excessive functionality; a get_order_status tool backed by a read-only view is not.

3. Make MCP servers validate tokens properly

The Model Context Protocol authorization specification treats a protected MCP server as an OAuth 2.1 resource server. Several requirements in it are worth checking in every server you run or adopt:

  • MCP clients must use Resource Indicators (RFC 8707) to name the server a token is for.
  • MCP servers must validate that access tokens were issued specifically for them as the intended audience.
  • Clients must not send, and servers must not accept or transit, tokens issued for anything else.
  • Access tokens must not be placed in URI query strings.

The MCP security best practices document calls out token passthrough as an explicitly forbidden anti-pattern, describes the confused deputy problem for MCP proxy servers, and states that MCP servers must not use sessions for authentication. If a server you are evaluating forwards your users' tokens straight to a downstream API, that is a design problem, not a configuration detail.

4. Gate consequential actions

Classify tool operations by consequence: read, reversible write, irreversible or external-facing write. Then decide what happens at each level:

  • Read: allow, log.
  • Reversible write: allow within scope, log, alert on volume anomalies.
  • Irreversible or external: require a human approval or a policy decision outside the model, such as payments, deletions, permission changes, outbound email to customers, production deploys.

The gate must sit outside the model's control. A system prompt saying "always ask before deleting" is guidance; a gate in the agent runtime or the tool server that refuses the call without an approval token is a control.

5. Treat MCP servers and tools as third-party software

Maintain an inventory of every MCP server in use: who runs it, where it runs, which version, which credentials it holds and which agents connect to it. Apply the same intake you use for libraries and SaaS integrations: provenance, maintainer, permissions requested, and a review when the tool list changes. Local MCP servers that run on developer machines deserve particular care; the MCP security guidance covers local server compromise as its own attack class.

6. Isolate execution

Run agents and any code they generate in sandboxes with restricted network egress, no ambient cloud credentials and separate identities per environment. An agent in staging should not be able to obtain production tokens, and an agent that browses the web should not share a network segment with internal admin interfaces.

7. Log for attribution, then review

Each log record for an agent action should capture the agent identity, the delegating user if any, the tool and operation, the target resource, the decision (allowed, challenged, denied) and a correlation ID that ties back to the prompt or task. Review agent entitlements on the same cadence as other privileged non-human identities, and remove tools the agent has not used.

For teams that want this registry and gate without building it, TrustIvan offers an agent registry with tool entitlements, an MCP server and tool inventory, and a runtime gate that allows, challenges or denies agent actions where the agent's runtime asks it to.

A phased rollout

Phase 1: Discover. List every agent and MCP server in use, including developer-run ones. Record identity, owner, tools and credentials. Disable agents with no owner.

Phase 2: Contain. Move agents onto their own identities, replace static credentials with federated or short-lived ones, and narrow tool scopes based on observed use.

Phase 3: Gate. Classify operations by consequence and put approval or policy gates in front of irreversible actions. Start with a small list and expand.

Phase 4: Operate. Add agent entitlements to access reviews, alert on new tools or servers, and rehearse revoking an agent's access quickly.

Pitfalls to avoid

  • Relying on prompt instructions as policy. Instructions can be overridden by injected content; enforcement belongs in code.
  • One integration account for all agents. It makes attribution and least privilege impossible.
  • Treating read-only as harmless. Read access to email, tickets or documents is how sensitive data reaches an attacker-controlled output.
  • Approving everything. If every action needs approval, reviewers click through. Reserve gates for consequential operations.
  • Forgetting the downstream credential. Audit what each MCP server can reach, not only who can reach it.

Frequently asked questions

Should AI agents use the requesting user's permissions?

Usually the agent should act with the intersection of its own scoped permissions and the user's, using delegation such as OAuth token exchange so both identities are visible downstream. Using the user's full token gives the agent everything the user can do.

Can prompt injection be fully prevented?

No reliable technique fully prevents it today. Treat it as likely and limit the blast radius through narrow tools, least-privilege credentials and gates on consequential actions.

Do internal MCP servers need OAuth?

The MCP authorization specification defines OAuth-based authorization for HTTP transports. Whatever mechanism you use, the server should verify that tokens were issued for it and should not pass client tokens through to downstream APIs.

How often should agent permissions be reviewed?

Review them on the same cadence as other privileged non-human identities, and also whenever an agent gains a new tool or connects to a new MCP server.

References

  1. OWASP Top 10 for LLM Applications 2025: LLM06 Excessive Agency
  2. OWASP GenAI Security Project: Agentic AI Threats and Mitigations
  3. Model Context Protocol: Authorization (2025-06-18)
  4. Model Context Protocol: Security Best Practices
  5. IETF RFC 8693: OAuth 2.0 Token Exchange

Share this article

Stay Ahead of What Matters.

Practical guides on cybersecurity & identity and more, delivered to your inbox.