[agenticwork]
← blog

Credential Isolation for AI Agents: Architecture Patterns That Prevent Breaches

When an AI agent needs to query a database, call a SaaS API, and post to a messaging platform in the same workflow, how does it authenticate to each service? In most agent frameworks, the answer is disturbingly simple: all credentials are available as environment variables or in a shared configuration file, and every tool in the agent's toolkit can access all of them.

This means a tool designed to query Salesforce also has access to the database credentials, the Slack bot token, the AWS IAM keys, and anything else in the environment. A malicious or compromised tool does not need to escalate privileges — it already has access to everything. A hallucinating agent that calls the wrong tool with the wrong parameters does so with full credentials available.

This is the shared-secrets anti-pattern, and it is the default in most agent frameworks today. It works in development. In production, it is a breach waiting to happen.

The Shared Secrets Problem

The shared-secrets pattern exists because it is easy to implement. You set environment variables for all the services your agent needs to access, and every tool reads whatever credentials it needs from the environment. This is the same pattern used in traditional application deployment, and for monolithic applications where all code runs in a single trust domain, it is acceptable.

AI agents are not monolithic applications. They execute tools that may come from different sources, have different trust levels, and serve different purposes. An MCP server for PostgreSQL is fundamentally different from an MCP server for a web search API. They have different security requirements, different blast radii if compromised, and different legitimate credential needs. Treating them as equivalent — giving both the same access to the same credential set — violates the principle of least privilege.

The principle of least privilege states that every component should have only the minimum permissions necessary to perform its function. For AI agent tools, this means: a Salesforce query tool gets Salesforce credentials and nothing else. A database read tool gets read-only database credentials scoped to specific tables. A Slack posting tool gets a token scoped to specific channels with specific actions. No tool sees credentials it does not need.

Credential Isolation: Our Platform Architecture

Our platform enforces strict credential isolation through multiple integrated capabilities. The OBO (On-Behalf-Of) Authentication system ensures that agents always act with the requesting user's identity — not shared service accounts — creating clear attribution for every action. RBAC with per-tool granularity defines which agents can access which tools with which credential scopes. And the PlatformCredentialInjector manages the credential lifecycle for each tool invocation:

Step 1: Task-Scoped Token Generation

When the HITL gate approves a tool invocation, the PlatformCredentialInjector generates a scoped credential specific to that invocation. It does not pass through the raw secret (API key, OAuth token, database password) stored in the organization's credential vault. Instead, it generates a derivative credential with the minimum permissions necessary for the specific operation.

For an OAuth-based service like Salesforce, this means requesting a scoped access token with permissions limited to the specific objects and operations required — read-only access to the Account and Contact objects, for example, with no access to Opportunity or Case. For a database, this means creating a short-lived role with SELECT-only permissions on specific tables. For cloud services, this means generating a pre-signed URL or temporary credential with a narrow IAM policy.

Step 2: Environment Variable Injection

The scoped credential is injected into the tool's isolated execution environment as an environment variable. The tool reads the credential from its environment in the standard way — there is no special SDK or credential-fetching protocol required. The tool sees a database connection string, an API token, or a pre-signed URL. It does not know or care that the credential is scoped and temporary.

Critically, the tool's execution environment contains only the credentials for its target service. There are no other credentials in the environment. A tool that queries Salesforce has a Salesforce credential and nothing else. It cannot access database credentials because they do not exist in its execution context.

Step 3: Time-Limited Expiration

Every injected credential has a time-to-live tied to the task duration. When the task completes — whether successfully or due to an error — the credential expires. If the task takes longer than expected and exceeds its TTL, the credential expires and the task fails safely rather than continuing with an expired credential that gets silently renewed.

The TTL is configured per tool type and per risk level. A read-only query against a non-sensitive API might get a 30-minute TTL. A write operation against a production database might get a 60-second TTL. The principle is that credentials live only as long as the operation they support, with a hard upper bound to prevent runaway tasks from holding credentials indefinitely.

Step 4: Post-Task Cleanup

After the task completes, the execution environment is torn down. Environment variables are scrubbed. Temporary credentials are explicitly revoked, not just allowed to expire. The credential vault records that the scoped token was issued, used, and revoked, with timestamps for each phase. No residual credential material remains in memory, on disk, or in the environment.

Shared Secrets vs. Scoped Injection: A Comparison

The practical difference between the shared-secrets pattern and scoped credential injection becomes clear when you consider failure modes:

  • Compromised tool (shared secrets): A compromised MCP server has access to all credentials in the environment. It can exfiltrate database passwords, API keys for every connected service, cloud provider credentials, and any other secrets present. The blast radius is the entire credential set.
  • Compromised tool (scoped injection): A compromised MCP server has access to a single, scoped, time-limited credential for its target service. It cannot access credentials for other services because they do not exist in its environment. The blast radius is one scoped credential that expires within minutes.
  • Agent hallucination (shared secrets): An agent that mistakenly calls a destructive tool has access to whatever credentials are in the environment. If it calls a database tool intending to read but the tool has write credentials available, the destructive operation can succeed.
  • Agent hallucination (scoped injection): An agent that mistakenly calls a destructive tool is limited by the credential scope. If the approved operation was a read, the injected credential only permits reads. The destructive operation fails at the credential level, not the application level.

Auto-Rotation and Auto-Revocation

Credential isolation is one layer of the defense. Credential hygiene — regular rotation and prompt revocation — is another. Our platform implements both automatically, complemented by the DLP Scanner's real-time monitoring of data flows to catch any credential material that might appear in agent outputs:

  • Auto-rotation: Long-lived credentials stored in the organization's vault (OAuth refresh tokens, API keys, service account credentials) are rotated on a configurable schedule. Rotation generates new credentials, validates they work, updates the vault, and revokes the old credentials. This happens without operator intervention and without interrupting agent workflows.
  • Auto-revocation: When an agent workflow completes, all scoped credentials generated for that workflow are explicitly revoked. When a tool is removed from an agent's configuration, any persistent credentials associated with that tool are revoked. When an agent is decommissioned, all associated credentials are revoked. No credential outlives its purpose.
  • Anomaly-triggered revocation: If the platform's Audit System detects unusual credential usage patterns — a tool making requests outside its normal scope, credentials being used from unexpected IP addresses, or tool calls failing authentication at higher than normal rates — the affected credentials are revoked immediately. The DLP Scanner simultaneously checks whether any sensitive data was exposed during the anomalous activity, and the incident is flagged for review with full context in the tamper-evident audit log.

Implementation Without Friction

Credential isolation can sound like it adds significant complexity to agent development. In practice, the complexity is in the infrastructure, not the developer experience. Tool developers write tools that read credentials from environment variables — the standard pattern. The scoping, injection, time-limiting, and cleanup happen in the platform's execution layer, invisible to the tool implementation.

For operations teams, credential policies are defined declaratively. A policy might specify: "Database tools get read-only access to the analytics schema with a 5-minute TTL. Salesforce tools get read access to Account and Contact objects with a 10-minute TTL. Slack tools get post-message permission to the #engineering channel with a 2-minute TTL." These policies are version-controlled, auditable, and enforceable without modifying tool code.

Credentials Are the Blast Radius

In any security incident involving an AI agent, the damage is bounded by the credentials the agent had access to. If a compromised tool has access to every credential in the environment, the blast radius is every service those credentials can access. If a compromised tool has access to a single scoped credential that expires in 60 seconds, the blast radius is whatever that credential can access in that window.

Credential isolation is not a nice-to-have security enhancement. It is the primary architectural control that determines the maximum damage any single failure — whether from hallucination, compromise, or misconfiguration — can cause. In a world where AI agents act autonomously with real credentials against real systems, controlling the credentials is controlling the risk.

The shared-secrets model was tolerable when humans were the ones using the credentials — they exercise judgment, understand context, and notice when something is wrong. AI agents do not have that judgment. They will use whatever credentials they have access to, for whatever purpose the model determines is appropriate. The only reliable safeguard is ensuring they never have access to credentials they do not need.

Resources