Skip to main content
Back to all articles
AI Engineering 6 min readUpdated August 31, 2026

Agent Tool Access Is Not User Authorization

An agent may have technical access to a tool while the current user has no right to perform the requested action. A practical authorization layer for multi-tenant tool calls using explicit actor context and least privilege.

By Salman Butt · Senior Full-Stack & Generative AI Engineer
#ai-agents#authorization#rbac#multi-tenancy#least-privilege#security#typescript#python
On this page

Giving an agent a tool does not answer the most important security question about that tool.

The question is not “can the agent call it?”

The question is “may this user, in this tenant, perform this action on this resource?”

Those are different checks.

A service account often has broad backend permissions because the application needs them. If the model can invoke those permissions directly, it becomes a deputy holding more authority than the person who asked it to act. One ambiguous sentence can then turn into a cross-tenant read, an unauthorized update, or a destructive action against the wrong record.

I prefer to make authorization an explicit part of the tool boundary. The model proposes an action. Application code resolves the actor, resource, tenant, and policy before anything runs.

The example here is a multi-tenant ERP assistant that can view invoices and change invoice status.

Carry the actor through the whole run

The first requirement is simple and easy to lose: every tool call needs trusted actor context that comes from the authenticated request, not from model text.

TypeScript
type ActorContext = {  userId: string;  tenantId: string;  roles: string[];  requestId: string;};

Python:

Python
from dataclasses import dataclass​@dataclass(frozen=True)class ActorContext:    user_id: str    tenant_id: str    roles: tuple[str, ...]    request_id: str

I do not ask the model to emit tenantId or userId as trusted authorization fields. If those values appear in a tool schema for routing convenience, the server still replaces or verifies them against the authenticated context.

Anything the model generated is input. Identity comes from the session.

Authorize the object, not only the tool name

A coarse rule such as “support agents may call get_invoice” is not enough.

The invoice itself has ownership.

TypeScript
type Invoice = {  id: string;  tenantId: string;  status: "draft" | "issued" | "paid" | "void";  totalCents: number;};​async function getAuthorizedInvoice(  actor: ActorContext,  invoiceId: string,): Promise<Invoice> {  const invoice = await invoiceRepo.findById(invoiceId);​  if (!invoice || invoice.tenantId !== actor.tenantId) {    // Do not reveal whether a foreign-tenant ID exists.    throw new NotFoundError("Invoice not found");  }​  return invoice;}

That tenant comparison is intentionally inside the application boundary. It should not depend on a prompt saying “only access invoices from the current tenant.”

In SQL-backed systems I usually push this condition into the query as well:

SQL
SELECT id, tenant_id, status, total_centsFROM invoicesWHERE id = $1  AND tenant_id = $2;

Filtering at the query boundary reduces the chance of loading data that should never have been visible to this run.

Separate read permission from write permission

An agent that can display an invoice should not automatically be allowed to void it.

I like policy functions that are deterministic and easy to unit-test.

TypeScript
type InvoiceAction = "read" | "mark-paid" | "void";​function mayActOnInvoice(  actor: ActorContext,  invoice: Invoice,  action: InvoiceAction,): boolean {  if (invoice.tenantId !== actor.tenantId) return false;​  if (action === "read") {    return actor.roles.some((role) =>      ["finance", "admin", "support"].includes(role),    );  }​  if (action === "mark-paid") {    return actor.roles.some((role) => ["finance", "admin"].includes(role));  }​  if (action === "void") {    return actor.roles.includes("admin") && invoice.status !== "paid";  }​  return false;}

Python:

Python
from enum import Enum​class InvoiceAction(str, Enum):    READ = "read"    MARK_PAID = "mark-paid"    VOID = "void"​​def may_act_on_invoice(    actor: ActorContext,    invoice: Invoice,    action: InvoiceAction,) -> bool:    if invoice.tenant_id != actor.tenant_id:        return False​    roles = set(actor.roles)​    if action is InvoiceAction.READ:        return bool(roles & {"finance", "admin", "support"})    if action is InvoiceAction.MARK_PAID:        return bool(roles & {"finance", "admin"})    if action is InvoiceAction.VOID:        return "admin" in roles and invoice.status != "paid"​    return False

This can evolve into RBAC, ABAC, a policy engine, or database row-level security. The specific authorization technology matters less than one architectural rule: the model never decides whether its own action is allowed.

Wrap the tool in a reference monitor

The executor is where policy becomes mandatory rather than optional.

TypeScript
type VoidInvoiceInput = {  invoiceId: string;  reason: string;};​async function voidInvoiceTool(  actor: ActorContext,  input: VoidInvoiceInput,): Promise<{ invoiceId: string; status: "void" }> {  const invoice = await getAuthorizedInvoice(actor, input.invoiceId);​  if (!mayActOnInvoice(actor, invoice, "void")) {    throw new ForbiddenError("You are not allowed to void this invoice");  }​  const updated = await invoiceRepo.void({    invoiceId: invoice.id,    tenantId: actor.tenantId,    reason: input.reason,    actorId: actor.userId,  });​  auditLog.record({    requestId: actor.requestId,    actorId: actor.userId,    tenantId: actor.tenantId,    action: "invoice.void",    resourceId: invoice.id,  });​  return { invoiceId: updated.id, status: "void" };}

The tool does not expose a “skipAuth” flag. It does not trust a role emitted by the model. It does not accept a tenant chosen from the conversation.

Every path goes through the same gate.

Avoid master credentials when a scoped credential is possible

Suppose a tool calls another internal service. The easiest implementation is to use the agent service's broad service token.

That token often has far more authority than the current request needs.

Where the infrastructure supports it, I prefer a scoped downstream credential or signed delegation containing the narrow claims needed for this call:

TypeScript
type DelegatedClaims = {  subject: string;  tenantId: string;  action: "invoice:read" | "invoice:void";  resourceId: string;  expiresAt: number;};

The downstream service then enforces the same resource boundary independently.

This is defense in depth. If the agent service has a bug, the receiving service still sees a token that cannot suddenly become “admin over every invoice.”

Hide foreign resources without creating an enumeration oracle

There is a subtle difference between “not found” and “forbidden.”

If a user supplies a random invoice ID that belongs to another tenant and the system responds “forbidden,” they have learned that the invoice exists.

For cross-tenant object access, I often return not-found semantics until ownership has been established. For an object in the current tenant where the user lacks an action permission, forbidden can be appropriate.

That behavior is not specific to AI. It is ordinary multi-tenant API design, and agents inherit the same concerns.

Retrieved context needs authorization too

Tool execution is only half the problem.

A RAG retriever that searches every tenant and then relies on the model not to mention foreign chunks has already lost the security boundary.

The same actor context should scope retrieval:

TypeScript
const chunks = await vectorStore.search({  embedding: queryEmbedding,  filter: {    tenantId: actor.tenantId,  },  limit: 20,});

If documents also have per-team or per-user visibility, those constraints belong in the filter or backing query as well.

Authorization after generation is too late. The sensitive content already entered model context.

Tool discovery can be permission-aware

There is value in not showing the model tools it could never use for the current actor.

A read-only user may only need search_invoices and get_invoice. An admin may additionally receive void_invoice and change_payment_terms.

Reducing the visible tool set can improve selection and lowers accidental reachability.

But I treat permission-aware tool discovery as an optimization, not the security control.

Even if the model somehow proposes a hidden tool name, the executor still authorizes it. Security should not depend on the tool being absent from a prompt.

Human approval and authorization solve different problems

A manager approving an action does not automatically make an unauthorized action valid.

The order should be:

  1. authenticate the actor;
  2. verify the actor is authorized for the resource and action;
  3. if the action is high-risk, request the additional human approval your product requires;
  4. execute with the approved arguments and an idempotency boundary.

Authorization answers may this action happen?

Approval answers does this action require an explicit human decision before it happens?

Mixing the two creates strange systems where a reviewer can accidentally approve a cross-tenant request that should never have reached them.

Audit decisions, not hidden reasoning

For a side-effectful tool call I want an audit record that can be explained later:

  • authenticated actor;
  • tenant;
  • resource;
  • action;
  • authorization result;
  • policy version;
  • approval ID when applicable;
  • idempotency key;
  • final tool outcome.

I do not need to store hidden model reasoning to answer “who changed this invoice and under what permission?”

The evidence for that question should come from application state and policy decisions.

When simple RBAC is enough

It is easy to turn authorization into a policy-engine project before the product needs it.

If the system has three roles and a handful of actions, explicit functions may be clearer than adding a new policy language. As resources and relationships grow, ABAC, relationship-based authorization, row-level security, or a dedicated policy service can become justified.

The maturity path should be driven by actual policy complexity, not by the fact that an LLM is involved.

The important thing is much simpler: an AI agent should never inherit broad application authority merely because it can technically reach a tool.

A model can suggest an action. It can explain why the action seems useful. It can choose among tools. The permission decision remains ordinary, deterministic application code tied to the authenticated user and the exact resource being touched.

That is how an agent stays an assistant instead of quietly becoming your most privileged user.

KEEP READING

Related engineering notes