Skip to main content
INS // Insights

AI Agent Authentication and Authorization

Updated October 2026 · 7 min read

ai agent authentication and authorization are two checks, and they fail differently. Authentication answers which runtime is calling. Authorization answers which tool that runtime may invoke, on which resource, and whether a user's own authority is required for the data. A prompt that says the agent is allowed to read a bucket does not affect either check. The model proposes a tool name. A gateway in front of the tool performs both checks, and the AWS API performs them again on the role session the gateway actually uses.

Rutagon builds that gateway for agents that touch production APIs and customer records. The agent has an identity of its own, which is the subject of AI agent identity. The narrowness of the role is the subject of AI agent least privilege. This article is the moment of the call: prove the runtime, then allow or deny the tool. How short the resulting credential lives is a third control. We do not collapse the three into one setting named "agent security."

How ai agent authentication and authorization are decided

Authentication of the runtime is workload identity. On AWS the agent process runs as a role: a Lambda role, an ECS task role, or an EKS pod role through Pod Identity or IRSA. The process obtains a session from the platform. There is no access key in the system prompt, the tool schema, or the environment file checked into the repo. The gateway accepts a call only when it can see that session. A shared API key named AGENT_TOKEN in the configuration is the credential we remove, because every copy of the agent presents the same secret and none of them can be disabled alone.

The role session name includes the agent id. CloudTrail then shows which agent assumed the role, not only which role was assumed. One role shared by several agents, with a session name that is just the hostname, makes the trail show a role and hides the agent. We use one role per agent when the agents have different tool sets. We use one role and distinct session names only when the permission policy is truly identical and the session name is mandatory in the gateway's check.

Authorization is an allowlist keyed by agent id. The list names tools, not English descriptions of tools. get_invoice is on the list or it is not. Arguments are checked against the tool's schema before the allowlist decision is applied, so a tool that is allowed cannot be called with a resource parameter the schema does not define. The IAM policy on the role is the ceiling. The gateway's allowlist is the per-call narrowing. If those two disagree, the call fails. Widening the IAM policy because the gateway already "checks it" removes the ceiling the cloud provider enforces when the gateway is bypassed.

{
  "agent_id": "invoice-reader",
  "caller_role": "arn:aws:iam::111122223333:role/agent-invoice-reader",
  "tool": "get_invoice",
  "user_sub": "directory-user-id",
  "resource": "invoice/18422",
  "decision": "allow"
}

That object is a log line, not a token the model can edit. The gateway builds it after both checks. decision is allow only when the caller role matches the agent id registered for invoice-reader, the tool is on that agent's allowlist, and, for this tool, the user subject is present and scoped to the invoice. A missing user subject is a deny for tools that read customer data. It is irrelevant for a tool that only reads the agent's own status page. The tool definition says which of those it is. The model does not.

On-behalf-of is the case people flatten by mistake. The agent is authenticated as itself. The user is authenticated as themselves, on a token the gateway validates, with an issuer and an audience the gateway expects. The allow decision is the intersection. The agent may call get_invoice. The user may see this invoice. Both have to be true. Giving the agent a standing ability to read every invoice, and trusting the prompt to pass the right customer id, is an authorization bug. The user's token never enters the model context. The gateway holds it for the call. A refresh token copied into a tool argument will show up in logs and in the next training export someone assembles from those logs.

AWS calls the gateway makes use the agent role, optionally with a session policy that names the one action and the one resource for that tool. The model's text is not an IAM policy. A second path, where the agent process holds the user token and calls AWS directly, skips the allowlist. We close that path by not giving the agent process a role that can reach the data APIs. The process can call the gateway. The gateway can call the APIs. AI agent permission practices go further on how those permission policies are reviewed. The split in this article is what makes that review mean something at runtime.

Deny, audit, and the two logs

Authentication failure and authorization failure are different responses. An authentication failure means the runtime did not present a session the gateway recognizes. Retrying with the same broken credentials will not become a success, and the alert is "unknown caller." An authorization failure means the caller is a known agent and the tool or the resource is outside its allowlist, or the user scope does not cover the resource. The alert is "known agent, denied tool." Mixing them into one 403 makes the on-call page useless and trains the agent loop to retry denies as if they were expired tokens.

The audit record is two logs joined by a request id. CloudTrail shows the role, the session name, the API, and the resource. The gateway log shows the agent id, the tool, the user subject when there was one, the decision, and the reason. An examiner who asks who read a customer's invoice needs both. CloudTrail alone shows a role. The gateway log alone shows an intent that might never have reached AWS. We retain both for the same window the rest of the production audit logs use. A trace that lives only in the model provider's console is not this record, because you do not control the retention and it does not contain the IAM principal.

Registration of a new agent is an allowlist change and a role change, reviewed together. An agent id that appears in the gateway config with no role, or a role that appears in IAM with no allowlist entry, is incomplete. Disable is the reverse: remove the allowlist entry and detach the role from the runtime. Deleting the prompt is not a disable. The runtime will keep calling with whatever prompt is loaded next.

Rutagon implements the gateway as a small service with a boring policy table, not as instructions in the system prompt. We have put that pattern in front of agents that read production data, including agents beside a production SaaS platform whose customer records are the resource in the intersection check. The platform's human users keep their own sessions. The agent gets a role. The gateway requires both when the tool says so. This is security automation for the agent you are already shipping. The model vendor does not perform the IAM check. The account does.

Frequently Asked Questions

Can the system prompt authorize a tool?

No. The prompt can propose a tool name. The gateway allows the call only when the authenticated agent id has that tool on its allowlist and the arguments match the schema. For customer data, the user's own scope has to cover the resource as well. Text in the prompt that declares an exception is not an exception the gateway reads.

Should every agent have its own IAM role?

Use a separate role when the tools differ. A shared role is acceptable only when the permission policy is the same and the session name carries the agent id into CloudTrail and into the gateway check. A shared role with a generic session name makes several agents indistinguishable in the audit log. That is the outcome we avoid.

Where does the user token belong?

On the gateway, validated for issuer and audience, and applied to the intersection decision. It does not belong in the model context, in a tool argument, or in the agent's long-term memory. The agent role is what calls AWS. The user token is what limits which of the user's records that call may name.

What do you retain for an examiner?

The gateway decision log and the CloudTrail events for the role session, joined by a request id. The decision log has agent id, tool, user subject, resource, and allow or deny. CloudTrail has the API and the principal. One of those without the other leaves either the intent or the effect unproven. Retention matches the rest of the production audit logs.

Discuss securing your AI agent build. Contact Rutagon at rutagon.com/contact, 907-841-8407, or contact@rutagon.com.