The Borrowed Credential: How AI Agents Get Access Without Holding Secrets

Z

ZharfAI Team

August 17, 202614 min read
The Borrowed Credential: How AI Agents Get Access Without Holding Secrets

An accounts-payable agent is asked to retrieve one approved purchase order, compare it with an invoice, and place the matched invoice in an enterprise resource planning queue. The quick integration copies an ERP service-account key into the agent runtime. That key can read every purchase order, write to several queues, and remain valid for months. It may appear in a tool trace, a crash dump, a copied prompt, or a subprocess the agent starts. Even if the model performs the intended task, the credential has already crossed the wrong boundary.

The reader decision is narrower and more useful than “how should we secure an AI agent?” It is: should this agent receive a credential at all, and if it must, how do we bind that credential to the workload, human or service subject, task, tenant, audience, action, and time window? For high-consequence operations, the best answer is often that a trusted broker should perform the action while the agent receives only the result.

Separate identity, authority, and credential

Three concepts are often collapsed into “the agent's API key”:

  • Identity says which workload instance is running, which software and environment produced it, and—where relevant—which user or service initiated the task.
  • Authority says which actions that principal may perform on which resources, for which tenant and purpose, under which policy version.
  • Credential is the proof presented to a particular resource. It should carry or reference only the authority needed at that destination and for a short period.

The distinction matters because one identity can receive different authority for different tasks, and one task can require credentials for several audiences. A token accepted by the document store should not work at the payments API. A user may be allowed to approve invoices but not to grant the agent a reusable approval identity. The design should preserve this chain rather than flattening agent, user, and service into one account.

This extends the agent passport: resolve the subject and task first, then issue the smallest proof required for one downstream effect. It also complements tool permission design, where the model proposes an action but a deterministic layer decides whether the action exists, which arguments are valid, and whether confirmation is required.

Make “no credential” a real architecture option

Start every integration review with three patterns, ordered by how much reusable authority enters the agent boundary:

PatternWhat the agent receivesSuitable useMain risk
Broker-executed actionA capability handle or structured result; no resource credentialPayments, deletion, privileged administration, regulated records, irreversible writesBroker becomes a critical policy and availability dependency
Exchanged short-lived credentialAudience-bound token with narrow scope and expiryHigh-volume reads or bounded reversible writes where direct access is operationally usefulToken can still be replayed within its authority unless sender-constrained
Static or long-lived credentialGeneral API key, password, private key, or refresh tokenLegacy systems only, behind a compensating proxy and migration deadlineBroad blast radius, weak attribution, rotation burden, and leakage persistence

“No credential” does not mean “no access.” The agent submits a typed request such as read_purchase_order(tenant, po_id) to a broker. The broker authenticates the workload, validates the task envelope, checks policy and freshness, invokes the resource under its own controlled identity, filters the response, and returns a bounded result. The resource secret never enters model context, tool arguments, extension processes, or general agent memory.

ZharfAI's analysis is that broker execution should be the default when a worst-case valid call is materially worse than an extra network hop. Issue a temporary credential only when the resource enforces the same narrow audience, subject, resource, action, tenant, and expiry, and direct access has a real operational benefit.

Build the trust path before minting access

A broker must not accept “I am the purchasing agent” from a prompt or request body. It needs a verifiable workload identity rooted in the execution platform. NIST SP 800-207A, published in September 2023, describes cloud-native zero trust around application and service identities, with enforcement through components such as API gateways, sidecars, and identity infrastructure rather than network location alone.

SPIFFE's workload-identity model provides a useful concrete mechanism: a workload can obtain short-lived, automatically rotated X.509 or JWT identity documents without being provisioned with a co-deployed authentication secret. The document proves workload identity; it does not by itself grant every application permission. SPIFFE also cautions that JWT identity documents are bearer tokens and can be replayed until expiry, whereas X.509 identities require proof of the private key in a mutual TLS exchange.

On Kubernetes, the preferred primitive is a projected, rotating service-account token requested for a specific audience, not a manually created long-lived token Secret. The Kubernetes service-account guidance explicitly recommends the TokenRequest API or projected token volume and notes that long-lived Secret-based tokens are not recommended.

The resulting trust path is:

  1. the platform attests a workload instance and approved deployment;
  2. the application binds subject, tenant, purpose, action, resource, policy, and deadline into a task envelope;
  3. the broker verifies both, checks revocation and confirmation, and calculates narrower authority;
  4. it performs the call or exchanges proof for an audience-specific temporary credential;
  5. the resource enforces authority and returns an effect receipt; and
  6. evidence joins identity, task, policy, request, and effect without recording the credential.

Network position may add a signal, but it is not identity. A process on the right subnet with a copied token is still the wrong workload.

Exchange proof; do not distribute master keys

OAuth 2.0 Token Exchange, RFC 8693, standardized in January 2020, defines a security token service interaction in which one token is exchanged for another. Its subject and actor concepts can represent the distinction between the party on whose behalf work occurs and the party acting. It also distinguishes impersonation—where the actor is indistinguishable from the subject—from delegation, where the actor remains identifiable.

That distinction is especially important for agents. A downstream audit should be able to say “procurement agent build 7 acted for employee 42 under task 913,” not merely “employee 42 called the ERP.” If the downstream protocol cannot carry both subject and actor, keep the missing relationship in an integrity-protected exchange record linked by a non-secret identifier. Do not invent a claim that the target does not validate.

OAuth 2.0 Security Best Current Practice, RFC 9700, published in January 2025, recommends audience-restricted and sender-constrained access tokens to reduce misuse of leaked tokens. It also reinforces minimum-privilege scope and protections for refresh tokens, including rotation or sender constraint for public clients. The operational translation is simple:

  • exchange at the last responsible moment, after policy and user confirmation;
  • issue for one resource server and the narrowest available action set;
  • make lifetime shorter than the remaining task deadline;
  • sender-constrain the token with mutual TLS or proof-of-possession where the ecosystem supports it;
  • keep refresh tokens and long-lived signing material in the broker, never in model-visible or plugin-visible state; and
  • reject a credential whose audience, tenant, subject, actor, task, or policy version does not match the call.

Temporary credentials are established in major cloud control planes. AWS STS temporary credentials are generated dynamically, expire, and avoid embedding long-term credentials. Google Cloud workload identity federation guidance describes exchanging external workload credentials for short-lived access, recommends dedicated identities over broad pool grants, and advises regional token endpoints where available. These are building blocks, not proof that an agent policy is correct.

For user OAuth, keep consent, current resource authorization, and permission for this task separate. Store refresh tokens in a dedicated credential service; give the agent an opaque connector handle. At invocation, the broker rechecks user status, tenant, requested scope, and step-up approval, then refreshes or exchanges access. Where provider scopes are coarse, a connector proxy must narrow methods, fields, resource IDs, rate, and response data.

Bind authority to a task envelope

The broker needs an immutable request that is richer than an OAuth scope string. A practical envelope can include:

FieldRequired property
workload_id, deployment_digestAttested runtime and approved software version
subject_id, actor_id, delegation_idHuman or service subject, agent actor, and delegation chain
tenant_id, membership_versionSecurity domain and freshness of membership
task_id, purpose, expires_atBounded job, legitimate purpose, and hard deadline
audience, actions, resource_handlesExact receiver, verbs, and server-resolved objects
confirmation_receiptHuman approval for the exact consequential action, when required
policy_version, risk_tierDecision logic used and applicable control tier
nonce, parent_trace_idReplay resistance and evidence linkage

The model may fill a proposal, but it must not sign, widen, or choose the trusted fields. Resolve resource handles server-side: “invoice 811” should become the database object's immutable identifier after tenant-scoped lookup, not a model-supplied path. Every downstream exchange may narrow the envelope; none may extend its expiry, add an action, change tenant, or substitute a resource.

This is also where tenant isolation becomes non-negotiable. A token scoped to invoice:write but accepted across all customers is not narrow. Tenant identity must be derived from trusted membership state, bound into the policy decision, and enforced again at the resource—not accepted as a tool argument.

Worked example: one invoice, two effects

Consider the original accounts-payable task. Employee U-42 may submit invoices for tenant T-8 but may not release payment. The approved workflow is to read purchase order PO-91, compare it with invoice INV-811, and place a match record in a review queue.

  1. The orchestrator obtains workload identity for ap-agent@prod, hashes the approved tool plan, and creates task TASK-913 with a five-minute deadline.
  2. The broker resolves PO-91 and INV-811 inside T-8, confirms that U-42 still has the submitter role, and records policy version 31.
  3. For the read, it exchanges workload proof for a 45-second token accepted only by the purchasing API, with po:read limited to the resolved record. The token cannot call the queue or another tenant.
  4. The agent compares bounded fields and proposes a match record. It never sees the ERP's long-lived credential or a refresh token.
  5. For the write, the broker validates a strict schema, recomputes totals, and directly executes review_queue:create using idempotency key TASK-913:match. The agent receives a receipt, not a queue credential.
  6. A separate human approval would be required for payment release. No token created for this task contains that action.

Prompt injection in the invoice cannot list other vendors because the read token is bounded to one audience and record. If the token leaks, 45 seconds is not the only defense: audience, resource, action, tenant, and preferably sender constraint limit replay. If U-42 loses the role mid-task, a changed membership version makes the broker deny the write even though the earlier read was legitimate.

Design for failure, replay, and partial completion

Credential brokering fails if the happy path is narrow but recovery silently becomes broad. Test these cases:

  1. expired token during a retry, with the original task deadline already passed;
  2. token minted before user removal, tenant suspension, policy change, or model rollback;
  3. replay of the same exchange request, capability handle, or high-risk action;
  4. wrong-audience token offered to a permissive gateway;
  5. valid token copied from the approved workload into an unapproved subprocess;
  6. agent request containing a foreign tenant ID, forged resource handle, or extra action;
  7. broker unavailable after the resource committed but before the receipt was recorded;
  8. refresh-token rotation, clock skew, or an emergency path that bypasses the broker.

Use idempotency at the effect target. Bind confirmation to the normalized request hash and expire it. On policy or membership change, stop issuance and revoke authority whose remaining lifetime exceeds the accepted exposure window. Fail closed on missing audience, task, tenant, or policy. A shared-service-account fallback converts an outage into an invisible security incident.

Measure authority, not vault adoption

A dashboard showing that “100% of secrets are in a vault” does not reveal what agents can do. Measure the authority actually issued and exercised:

MeasureUseful question
Static credentials reachable by agent runtimesHow much durable authority can still leak?
Token lifetime distribution by risk tierIs access shorter than the task and response window?
Audience and resource-binding coverageCan a captured token work elsewhere?
Broker-executed share of high-risk actionsHow often does dangerous authority avoid the agent boundary?
Issued-to-used authority ratioAre scopes and resource sets broader than observed need?
Denials after membership or policy changeDoes freshness enforcement catch stale work?
Replay and idempotency conflictsAre duplicate task paths reaching real effects?
Credential material in logs and tracesAre observability paths becoming secret stores?

Do not log tokens. Record a protected fingerprint, audience, actions, subject, actor, tenant, task, issuance and expiry, policy version, decision, effect receipt, and denial reason. Protect this evidence; a trail containing usable credentials is another breach path.

The audit evidence guide offers the right standard: preserve the decision inputs and effect receipts needed to substantiate a control, not just a configuration screenshot or the agent's narrative of what it did.

The credential-broker release gate

Before enabling an agent connector, verify:

  • the resource, action, tenant, subject, actor, purpose, and maximum task duration are defined;
  • a platform-rooted workload identity is verified independently of model output;
  • broker execution was evaluated before deciding to issue a credential;
  • every issued token has a single intended audience, narrow action and resource set, and risk-appropriate lifetime;
  • sender constraint or an explicit replay-risk decision exists for bearer tokens;
  • refresh tokens, signing keys, service-account keys, and client secrets remain outside agent-readable state;
  • the resource enforces authority independently and does not trust tenant or resource scope only from tool arguments;
  • delegation preserves both subject and actor, with an integrity-protected link when the target protocol cannot carry both;
  • confirmation binds to the exact normalized high-risk request and cannot authorize a changed retry;
  • idempotency, partial-commit recovery, revocation, clock skew, and broker outage have been tested at the real effect target;
  • logs, prompts, traces, memory, and evaluation datasets are scanned for credential material; and
  • the legacy static-credential exception has an owner, compensating proxy, rotation plan, and removal date.

What to revisit

Revisit the decision when a connector adds a write method, a provider changes scopes, token exchange or proof-of-possession becomes available, task duration grows, the agent can run code or install extensions, a new tenant class arrives, or the consequence of a valid action changes. Review it after every credential exposure, replay, stale-membership denial, broker bypass, or unexplained difference between issued and used authority.

The durable principle is not “rotate secrets faster.” It is to stop treating a credential as the agent's property. Authority is borrowed for a named task, narrowed at every hop, and either exercised by a broker or represented by a short-lived proof that only the intended resource can accept. When the task ends, nothing reusable should remain inside the agent boundary.

Source notes — reviewed August 17, 2026

#AI Agents#Workload Identity#Credential Brokering#OAuth#Zero Trust

Related Posts

Name one process for a discovery call

If this note maps to a real system in your organization, start with the services page or a shipped case study.