{"id":"TIE-AGT-014","title":"Short-lived, task-scoped credentials instead of standing secrets","maturity":"reference-build","collection":"Agent identity","category":"Credentials","complexity":"Medium","intent":"Remove long-lived secrets from AI agents: let each agent prove who it is with a federated identity or a key it never shares, and give it short-lived tokens limited to one audience and the scopes one task needs.","summary":"A standing API key works for anyone, for anything, until rotated. Replace it with secretless agent authentication and short-lived tokens limited to one audience and one task, with vaulted check-out only for systems that need it.","problems":["Agents using human or shared credentials","Long-lived API keys","Secret sprawl","Over-privileged agents","Credential theft by prompt injection","Lateral movement by agents"],"standards":["OAuth 2.0 Token Exchange (RFC 8693)","Resource Indicators for OAuth 2.0 (RFC 8707)","JWT Profile for OAuth 2.0 Client Authentication (RFC 7523)","OAuth 2.0 Demonstrating Proof of Possession (DPoP, RFC 9449)","OAuth 2.0 Mutual-TLS Client Authentication (RFC 8705)","OAuth 2.0 Security Best Current Practice (RFC 9700)","SPIFFE"],"tags":["short-lived credentials","secretless","workload identity federation","managed identity","federated identity credential","private_key_jwt","token exchange","downscoping","audience binding","DPoP","mTLS","vault","just-in-time","API keys","rotation"],"roles":["IAM architect","Identity engineer","Security leader","Platform engineering","AI engineering"],"industries":["Cross-industry","Financial services","Healthcare","Retail","Public sector"],"builds_on":["TIE-AGT-001","TIE-AGT-002"],"related":["TIE-AGT-005","TIE-AGT-013","TIE-AGT-016"],"authors":"Trevonix Innovation","reviewers":"Trevonix IAM architecture","version":"1.0","last_reviewed":"2026-11-24","published":"2026-11-24","og_image":"og-tie-agt-014.png","sections":{"summary":[{"type":"bullets","content":"**Authenticate without a shared secret.** The agent proves who it is with workload federation (managed identity, CI/CD OIDC, SPIFFE) or a private key that never leaves it, not with a client secret or API key.\n**Access with short-lived, narrow tokens.** For each task the agent gets tokens for **one audience**, with **only the scopes that task needs**, valid for **minutes**, ideally bound to the agent's key.\n**Vault what cannot change.** Systems that only accept static credentials get them through a broker that checks them out just in time and rotates them; the agent never stores them."}],"problem":[{"type":"paragraph","content":"Agents are often wired up the quickest way: a model-provider API key, a client secret or a service account password in an environment variable, and a broad scope so nothing fails during the demo. Those credentials outlive the project, are copied into notebooks, logs and tickets, and grant everything they were ever given to whoever holds them.\n\nAgents make this worse than for ordinary services. They read untrusted content that can instruct them to reveal or misuse what they hold, they call many tools, and they are frequently cloned and re-deployed. A leaked standing credential gives an attacker the agent's full reach with no time limit, and stopping it means finding and rotating every copy."},{"type":"note","content":"OWASP's agentic risk list includes identity and privilege abuse, where agents reuse, escalate or leak inherited credentials. Short-lived, narrowly scoped credentials limit what any single leak can do.","title":"Why this matters"}],"use_when":[{"type":"bullets","content":"Any agent that calls APIs, tools or MCP servers with its own or delegated authority.\nAgents that process external content and could be manipulated into leaking or misusing a credential.\nAgents that run in many copies, environments or tenants.\nYou are replacing personal API keys or shared service accounts found during discovery (see TIE-AGT-012)."}],"avoid_when":[{"type":"bullets","content":"Never as a reason to keep a static secret. Where a target system only supports static credentials, use the vaulted check-out in this pattern rather than skipping it."}],"forces":[{"type":"bullets","content":"**Security against friction.** Shorter tokens mean more token requests and more moving parts.\n**Narrow scopes against task variety.** Agents decide their next step at run time, so the exact scopes a task needs are not always known up front.\n**Proof of possession against compatibility.** DPoP and mutual TLS stop stolen tokens being replayed, but not every API supports them.\n**Platform features against portability.** Managed identities and federated credentials are platform-specific; the pattern must work across clouds and SaaS."}],"solution":[{"type":"paragraph","content":"Separate **how the agent proves who it is** from **what it is allowed to do now**. The first layer uses a credential the agent cannot leak by copy-paste: a platform-issued workload token exchanged through a federated trust, or a private key held in a key store. The second layer issues, for each task step, an access token for a single audience with the minimum scopes, a lifetime set by the agent's risk tier, and where possible a binding to the agent's key. Systems that only accept static credentials sit behind a broker that holds and rotates them."},{"type":"image","content":"Secretless authentication, then short-lived per-audience tokens; static credentials only through a just-in-time broker.","title":"Solution overview","media":"tie-agt-014-solution.png","alt":"Diagram in two layers. Layer 1, prove who you are: the agent runtime obtains a platform workload token (managed identity, CI/CD OIDC token or SPIFFE SVID) and presents it, or a JWT signed with its private key, to the authorisation server. No client secret or API key is stored. Layer 2, get only what"},{"type":"table","content":"Credential | Leak risk | Use for agents\nAPI key or client secret in configuration | Anyone who reads it can use it until rotation | Avoid; development only, and remove before go-live\nCertificate or private key (private_key_jwt) | Key must be stolen from its store | Good where federation is not available\nWorkload federation (managed identity, CI/CD OIDC, SPIFFE) | No stored secret; trust is bound to the workload | Preferred for agent authentication\nShort-lived access token, one audience | Useful only to that API, only for minutes | Every call the agent makes\nSender-constrained token (DPoP or mTLS) | Useless without the agent's private key | Tier 3 and 4 agents where APIs support it\nVaulted credential, checked out just in time | Exposed briefly, rotated after use | Legacy systems only","title":"Credential ladder"},{"type":"numbered","content":"**Federate the agent's own authentication.** Configure the identity provider to trust the runtime's workload identity (managed identity, the CI/CD platform's OIDC tokens or a SPIFFE trust domain), or register a public key for the agent. Remove client secrets.\n**Request per audience.** For each downstream API or MCP server, request a token with the `resource` (or audience) of that API only.\n**Request per task.** Ask for the scopes the current step needs. Where the agent acts for a user, exchange the user's token (see TIE-AGT-002) so the result is limited by both the user's and the agent's rights.\n**Keep tokens short.** Set access token lifetimes by risk tier (see TIE-AGT-013). Avoid refresh tokens for autonomous agents; re-authenticate instead.\n**Bind where you can.** Use DPoP or mutual TLS so a stolen token cannot be replayed from elsewhere.\n**Broker what is left.** For systems that only accept passwords or keys, put a vault or gateway in front that injects the credential per request or checks it out for minutes, and rotates it.\n**Watch for regressions.** Alert on new client secrets on agent identities, long token lifetimes and static keys found in code.","title":"How it works"},{"type":"code","content":"POST /oauth2/token\ngrant_type=urn:ietf:params:oauth:grant-type:token-exchange\n&subject_token=<user token for the agent>\n&subject_token_type=urn:ietf:params:oauth:token-type:access_token\n&client_assertion_type=urn:ietf:params:oauth:client-assertion-type:jwt-bearer\n&client_assertion=<JWT signed with the agent's private key, or a federated workload token>\n&resource=https://orders.api.example.com\n&scope=orders.read\n\n# Response: access token for the orders API only, scope orders.read, expires_in 300","title":"Example: per-audience, per-task token request","language":"http"}],"design_rules":[{"type":"numbered","content":"**No standing secrets in agents.** Not in configuration, prompts, tool definitions or memory.\n**Federate first, keys second, secrets never in production.**\n**One audience per token.** A token that works on every API is a master key.\n**Scopes follow the task, not the agent's maximum.**\n**Lifetimes follow the risk tier.** Minutes, not hours, for consequential agents.\n**Bind tokens to keys where APIs allow it.**\n**Separate credentials per environment.** A development compromise must not reach production.\n**Never pass a token through to another audience.** Exchange it (see TIE-AGT-005)."}],"anti_patterns":[{"type":"table","content":"Anti-pattern | What goes wrong\nModel-provider or SaaS API key in an environment variable | Copied into logs and tickets; valid until someone notices\nOne token for every downstream API | A leak or confused deputy reaches everything\nRefresh tokens that live for weeks on autonomous agents | A stolen refresh token is a standing credential\nSame credential for dev, test and prod | A laptop compromise becomes a production incident\nAgent asks the user to paste a password | Human credentials in an agent's memory and logs\n\"Temporary\" broad scopes for the pilot | Become permanent at go-live"}],"benefits":[{"type":"bullets","content":"A leaked token is useful only to one API, for minutes.\nNo secrets to rotate, store or chase across copies of the agent.\nPrompt injection has much less to steal or misuse.\nFaster, more reliable containment when an agent misbehaves (see TIE-AGT-016)."}],"costs":[{"type":"bullets","content":"Runtime platforms must support workload federation, or keys must be managed in a key store.\nMore token requests, and caching logic that respects audience and expiry.\nSome APIs do not support audience restriction or proof of possession yet.\nA broker or vault for legacy systems."}],"tests":[{"type":"table","content":"Test | Expected result\nSearch agent configuration, code and logs for secrets | None found for production agents\nUse an agent's token against a second API | Rejected (wrong audience)\nUse a token after its lifetime | Rejected\nReplay a DPoP-bound token without the private key | Rejected\nAdd a client secret to a production agent identity | Alert raised; policy blocks or flags it\nAgent calls a legacy system | Credential injected by the broker; agent never receives it; credential rotated\nDevelopment agent identity tries to reach production | Fails: no trust in that environment"}],"maturity_notes":[{"type":"paragraph","content":"**Reference build.** Trevonix has built short-lived, audience-specific delegated tokens through token exchange on Ping Identity (PingOne Advanced Identity Cloud with PingGateway), and federated short-lived deployment credentials for an agent-driven pipeline, in lab tenants (November 2026). The Microsoft Entra, Okta and Saviynt recipes are written from vendor documentation and have not yet been lab-tested by Trevonix for this pattern."}],"faq":[{"type":"faq","content":"Five to fifteen minutes for agents that take consequential actions, up to an hour for low-risk read-only agents. Tie the limit to the agent's risk tier and make sure APIs actually check expiry.","title":"How short is short?"},{"type":"faq","content":"Usually not for autonomous agents: the agent can re-authenticate with its federated identity or key whenever it needs a new token. For agents acting for a user over a long task, use refresh token rotation with a short absolute lifetime.","title":"Do agents need refresh tokens?"},{"type":"faq","content":"Put a broker in front of them: a vault that checks out the credential for minutes, or a gateway that injects it per request and rotates it after use. The agent asks the broker; it never sees or stores the secret.","title":"What about systems that only accept API keys or passwords?"},{"type":"faq","content":"No. Short-lived tokens limit how long a stolen or misused credential works and how far it reaches. You still need authorisation at the resource (TIE-AGT-005) because a hijacked agent can misuse a valid token during its lifetime.","title":"Does this stop prompt injection?"}],"references":[{"type":"bullets","content":"[RFC 8693: OAuth 2.0 Token Exchange](https://www.rfc-editor.org/rfc/rfc8693)\n[RFC 9449: OAuth 2.0 Demonstrating Proof of Possession (DPoP)](https://www.rfc-editor.org/rfc/rfc9449)\n[RFC 9700: Best Current Practice for OAuth 2.0 Security](https://www.rfc-editor.org/rfc/rfc9700)\n[Microsoft Learn: Best practices for Microsoft Entra Agent ID](https://learn.microsoft.com/entra/agent-id/best-practices-agent-id)\n[Okta Help: Add AI agents manually](https://help.okta.com/oie/en-us/content/topics/ai-agents/ai-agent-add-manually.htm)\n[Okta Developer: Set up AI agent token exchange](https://developer.okta.com/docs/guides/ai-agent-token-exchange/main/)\n[SPIFFE: Secure Production Identity Framework for Everyone](https://spiffe.io/)"}]},"recipes":{"ping":{"status":"reference-build","product_name":"PingOne Advanced Identity Cloud AI agents with token exchange and PingGateway","summary":"Agents authenticate with their own client identity and receive downscoped, audience-specific, short-lived tokens through token exchange, enforced per route at PingGateway. Built by Trevonix in a lab tenant.","last_verified":"2026-11","blocks":[{"type":"table","content":"Component | Role in this pattern\nAI agent identity (Advanced Identity Cloud or PingOne) | OAuth client for the agent; use key-based client authentication\nOAuth 2.0 token exchange | Issues downscoped, audience-specific tokens for each call\nPingGateway | Exchanges and checks tokens per route so each API receives only its own token\nPingOne Privilege | Secretless and short-lived access for privileged agent use","title":"Components"},{"type":"numbered","content":"Register the agent as an AI agent identity and configure key-based client authentication (private key JWT) rather than a client secret.\nConfigure token exchange so the agent, or PingGateway on its behalf, obtains a separate token per downstream audience with only the scopes that route needs.\nSet access token lifetimes on the agent's OAuth settings to its risk tier limit, and avoid refresh tokens for autonomous agents.\nFor privileged targets, use PingOne Privilege so the agent receives short-lived access rather than a stored credential.","title":"Configure"}]},"okta":{"status":"documented","product_name":"Okta for AI Agents with key-based registration and resource connections","summary":"Agents authenticate with a registered public key or CIMD and receive short-lived tokens through resource connections; static credentials stay vaulted. Written from Okta documentation; not lab-tested by Trevonix for this pattern.","last_verified":"2026-11","blocks":[{"type":"table","content":"Component | Role in this pattern\nAI agent registration with a public key or CIMD | The agent authenticates with private_key_jwt instead of a secret\nResource connections | Define how the agent gets each downstream credential: authorization server, vaulted secret, service account or MCP server\nCustom authorization servers | Issue short-lived, scoped access tokens per resource\nOkta Privileged Access | Vaults static service account credentials that a connection uses","title":"Components"},{"type":"numbered","content":"In **Directory > AI agents**, register the agent and choose **public/private key** client registration (or a Client ID Metadata Document URL where your agents publish one). Generate or paste the public key; keep the private key in the agent's key store.\nAdd a resource connection for each downstream resource. Prefer the **authorization server** type, which issues tokens through the identity assertion (ID-JAG) token exchange, over vaulted secrets.\nOn each custom authorization server, set short access token lifetimes and define the custom scopes each connection may grant.\nUse the **service account** or vaulted secret connection types only for systems that cannot accept tokens, so the credential stays in Okta's vault.","title":"Configure"}]},"entra":{"status":"documented","product_name":"Microsoft Entra Agent ID with federated identity credentials","summary":"Blueprint credentials use a managed identity as a federated credential, or certificates, instead of client secrets; agent identities hold no credentials of their own. Written from Microsoft documentation; not lab-tested by Trevonix for this pattern.","last_verified":"2026-11","blocks":[{"type":"table","content":"Component | Role in this pattern\nAgent identity blueprint credentials | Where the agent's authentication credential lives; agent identities have none of their own\nFederated identity credential with a managed identity | Secretless blueprint authentication for agents running on Azure\nCertificates | The alternative where managed identity is not available\nConditional Access and ID Protection for agents | Block risky agents; tokens stop being issued","title":"Components"},{"type":"numbered","content":"On the agent identity blueprint, open **Credentials** under developer settings and add a **federated credential** that trusts the managed identity of the runtime (or the OIDC issuer of your CI/CD platform for build agents).\nWhere the runtime is not on Azure and cannot federate, add a certificate and keep its private key in a key vault or HSM.\nDelete any client secrets from production blueprints. Use separate blueprints, or environment-specific federated credentials, for development, test and production.\nGrant each agent identity only the API permissions it needs, and have the agent request tokens per resource rather than broad `.default` tokens for many APIs where your APIs allow narrower scopes.\nUse the Microsoft Entra SDK for Agent ID or Microsoft.Identity.Web to acquire agent tokens instead of hand-building the federated flows.","title":"Configure"},{"type":"bullets","content":"Credentials sit on the blueprint, so every agent identity from that blueprint shares its authentication strength. Do not reuse one credential across unrelated blueprints.\nYour tenant policy may cap client secret lifetimes, but a capped secret is still a standing secret; use federation.","title":"Gotchas"}]},"saviynt":{"status":"documented","product_name":"Saviynt Identity Security for AI and privileged access","summary":"Finds agents with long-lived credentials and governs remediation; vaults static credentials that must remain. Written from Saviynt's published material; not lab-tested by Trevonix.","last_verified":"2026-11","blocks":[{"type":"table","content":"Capability | Role in this pattern\nPosture management for AI | Finds long-lived keys, unrotated credentials and over-privileged agents\nIdentity lifecycle management | Ties each agent credential to an owner and purpose\nPrivileged access management | Vaults and rotates static credentials that agents must still use","title":"Capabilities used"},{"type":"numbered","content":"Use posture findings to list agents that rely on long-lived or unrotated credentials.\nAssign each to an owner with a remediation date: move to federation or key-based authentication.\nWhere a static credential must remain, vault it and grant time-bound access instead of storing it with the agent.","title":"Configure"}]},"misc":{"status":"documented","product_name":"CI/CD OIDC federation and SPIFFE/SPIRE","summary":"Platform-issued workload identities replace stored secrets for agents in pipelines and Kubernetes.","last_verified":"2026-11","blocks":[{"type":"paragraph","content":"For agents that run in CI/CD or Kubernetes, use the platform's federation: GitHub Actions and similar platforms issue OIDC tokens that cloud providers and identity providers can trust, and SPIFFE/SPIRE issues short-lived workload identities (SVIDs) that can be exchanged for access tokens."}]}},"slug":"tie-agt-014-short-lived-task-scoped-credentials-instead-of-standing-secrets","updated_at":"2026-11-24T17:50:31.476Z","url":"https://exchange.trevonix.com/patterns/tie-agt-014-short-lived-task-scoped-credentials-instead-of-standing-secrets","markdown_url":"https://exchange.trevonix.com/patterns/tie-agt-014-short-lived-task-scoped-credentials-instead-of-standing-secrets.md","publisher":"Trevonix","license":{"name":"CC BY 4.0","url":"https://creativecommons.org/licenses/by/4.0/"}}