Skip to main content

11. Security & Ethics

Access Control, Authentication and Permissions

Access control for AI agents separates authentication (who the user and services are) from authorization (what the agent may read or do on their behalf). Agents need delegated, scoped credentials β€” not a shared god-mode service account β€” plus RBAC/ABAC policies, per-tool grants, tenant isolation, and short-lived tokens. Every tool call should be attributable to a user, agent, and permission decision. Weak authZ is how helpful agents become insider threats.

What you will learn

  • Distinguish authN, authZ, and delegated agent access
  • Design scoped tokens instead of shared admin credentials
  • Apply RBAC, ABAC, and per-tool permission grants
  • Enforce tenant isolation on data and tools
  • Answer interview questions with short, solid answers
User agent authZ tools data access control
Interview staple: the agent inherits a subset of the user permission set β€” never more.

Definition

Authentication (authN) verifies identity. Authorization (authZ) decides whether that identity β€” or an agent acting for it β€” may perform an action on a resource. For agents, permissions must cover the human user, the agent runtime, tool servers (e.g. MCP), and often peer agents (A2A), with clear delegation chains.

Access control is enforced in gateways and APIs, not by asking the model to β€œbe careful.”

Introduction

This lesson (#4 in Security & Ethics) follows Data Privacy for Agents. Privacy limits what data exists in the path; access control limits who (and which agent) may touch it.

Next: Tool Execution Security β€” hardening how allowed tools actually run.

Why agents need stronger authZ

  • One session can touch many systems in seconds
  • Models may request tools the user never intended
  • Shared service accounts erase accountability
  • Multi-tenant RAG without filters leaks across customers
  • Protocol servers multiply credential surfaces

AuthN basics for agent products

  • Strong user auth - SSO, MFA where risk warrants
  • Service identity - workload identity for agent runtimes
  • Server/peer auth - MCP servers and A2A peers mutually authenticated
  • Session binding - agent actions tied to a logged-in user session
  • Step-up auth - re-verify for high-risk tool classes

Delegated access

The agent should act as the user with fewer powers, not as omnipotent infra.

User authN session scoped token API call
Mint short-lived, audience-restricted tokens per tool or per task.
  • OAuth-style delegation or equivalent scoped credentials
  • Downscope: agent token subset of user permissions
  • Per-tool or per-task tokens with TTL
  • Attribute every call to user_id + agent_id + request_id
  • Revoke on logout, suspend, or anomaly

Permissions models

Use roles for defaults; attributes and tool grants for precision.

RBAC ABAC tool grants permission models
Read vs write tool flags and HITL requirements belong in the grant table.
  • RBAC - map roles (user, support, admin) to permission sets
  • ABAC - conditions on tenant, resource owner, time, risk score
  • Tool grants - explicit allowlist of tools per agent/role
  • Data filters - row/document ACLs applied before RAG retrieval
  • Deny by default; grant explicitly

Tenant and environment isolation

  • Hard tenant_id on every query, index, and tool call
  • Separate prod credentials from staging agents
  • No cross-tenant memory or eval leakage
  • Admin break-glass paths audited and time-boxed

Failure modes

  • Single shared API key for all users in the agent backend
  • Trusting the model to choose only β€œallowed” tools without a gateway
  • RAG without document ACLs
  • Long-lived tokens in prompts or logs
  • Confusing β€œlogged in” with β€œauthorized for this write”

Program / implementation notes

Put an authZ check in the tool gateway: (user, agent, tool, args, resource) β†’ allow/deny/HITL. Propagate tenant and user claims into downstream APIs. Unit-test denied cross-tenant reads.

  • Start with role allowlists plus tenant filters on RAG
  • Next: Tool Execution Security

Advantages and limitations

  • Advantage: least privilege limits blast radius of injection
  • Advantage: attribution enables audit and abuse response
  • Advantage: step-up auth protects rare high-risk actions
  • Limitation: fine-grained ABAC is complex to operate
  • Limitation: over-tight scopes frustrate legitimate workflows
  • Limitation: third-party tools may not honor your scopes well

Key points

  • AuthN identifies; authZ authorizes; agents use delegated scopes.
  • Never give agents a shared god-mode service account.
  • Combine RBAC defaults, ABAC conditions, and per-tool grants.
  • Filter RAG and tools by tenant and resource ACLs.
  • Short-lived tokens; attribute every tool call.
  • Enforce in gateways β€” not only in prompts.

FAQs

Can the LLM enforce permissions?

No. The model can propose tool calls, but a trusted gateway must allow or deny based on policy and credentials.

User permissions vs agent permissions?

The agent should receive a subset of the user’s permissions (downscoped), optionally with extra HITL on writes the user could do manually.

RBAC or ABAC?

Start with RBAC for clarity. Add ABAC when tenant, ownership, time, or risk must refine the same role.

How do MCP servers fit?

Authenticate the server and pass user-scoped tokens into tools. Do not store end-user admin credentials inside the server process for all tenants.

Interview questions

  1. AuthN vs authZ for agents?

    Answer AuthN verifies user and service identities. AuthZ decides which tools and data the authenticated user β€” via the agent β€” may access.

  2. What is delegated access for an agent?

    Answer Issuing scoped, short-lived credentials so the agent acts on behalf of a user with least privilege, not with a global admin key.

  3. Why avoid shared service accounts?

    Answer They over-privilege every session, destroy per-user attribution, and turn any prompt injection into a full-environment compromise.

  4. How do RBAC and tool grants work together?

    Answer Roles define broad permission sets; an explicit tool allowlist (with read/write and HITL flags) further constrains what the agent can invoke.

  5. How do you protect multi-tenant RAG?

    Answer Enforce tenant and document ACLs at retrieval time so chunks from other tenants never enter the prompt.

  6. Where is authorization enforced?

    Answer In a trusted tool/API gateway using policy and credentials β€” before side effects β€” not by relying on model instructions alone.

Related topics

Practice task

Complete each numbered practice step in a notebook or doc before opening the next lesson.

  1. List roles for your product and which tools each role may call.
  2. Design a scoped-token shape: user_id, tenant_id, tool audience, TTL.
  3. Write a deny test: user A must not retrieve user B documents via RAG.
  4. Mark three tools that require step-up auth or HITL.
  5. Answer interview questions 1, 2, and 5 in two sentences each.