By NHI Mgmt Group Editorial TeamPublished 2026-06-10Domain: Agentic AI & NHIsSource: WorkOS

TL;DR: AI agents need credentials to act, but long-lived keys, shared service accounts, and user-session inheritance create overbroad access and weak auditability, according to WorkOS and GitGuardian research. The governance problem is not storage alone: identity controls built for stable, predictable software do not hold when an agent can choose tools and act at runtime.


At a glance

What this is: This is a practical guide to managing API keys, OAuth tokens, and secrets for AI agents, with the key finding that standard credential patterns fail when agents operate autonomously.

Why it matters: It matters because IAM, PAM, and NHI programmes need to account for agent behaviour, session scope, and revocation boundaries before autonomous tool use creates uncontrolled blast radius.

By the numbers:

👉 Read WorkOS's guide to managing API keys, tokens, and secrets for AI agents


Context

AI agent credential management is the problem of deciding what secrets an agent can hold, for how long, and under what scope. The article argues that environment variables, shared service accounts, and inherited user sessions all fail once the identity is an autonomous actor choosing tools at runtime.

For IAM and NHI programmes, the core issue is not whether the secret is encrypted, but whether the access model matches the agent's actual behaviour. Session-scoped access, revocation, and auditability become governance controls, not just implementation details.


Key questions

Q: How should security teams manage credentials for AI agents without creating standing access?

A: Use short-lived, task-scoped credentials, keep downstream secrets server-side, and require approval before each session begins. The agent should never hold raw long-lived tokens if the task can be completed with a temporary access grant. This reduces blast radius and makes revocation meaningful when behaviour changes.

Q: Why do shared service accounts create problems for AI agent governance?

A: Shared service accounts collapse attribution, so you can see which account acted but not which agent or user caused the action. They also make revocation coarse-grained, because disabling one behaviour can break every agent using the same identity. That is a governance failure, not just an audit inconvenience.

Q: What breaks when AI agents inherit a user's active session?

A: The agent inherits permissions the task may never require, which expands access beyond the approved intent and weakens separation between human action and machine action. If the session is compromised or overused, the attacker gets the user's broader access profile rather than a bounded agent identity. That turns delegation into overexposure.

Q: Who is accountable when an AI agent performs an unauthorised action?

A: Accountability should be traceable to the delegating user, the agent identity, and the session that authorised the action. If any of those three are missing from logs, incident response becomes ambiguous and revocation becomes incomplete. Governance teams should treat that triad as a minimum control requirement.


Technical breakdown

Why long-lived API keys break agentic access models

Long-lived API keys assume the caller behaves predictably and always deserves the same access. In agentic systems, that assumption collapses because the agent may switch tasks, tools, and data targets within one workflow. A key stored in a .env file or injected at deploy time typically has no expiration, no environment isolation, and no task boundary. That means compromise of the agent often becomes compromise of everything the key can reach.

Practical implication: move away from persistent keys for agents and treat scope, environment, and expiry as mandatory controls.

OAuth connection management for AI agents

OAuth is a better fit than raw API keys because it scopes access and supports revocation, but the human-first browser consent model still leaves risk when an autonomous agent holds the resulting token. The safer pattern is to keep the downstream credential server-side and let the agent request a fresh access token only when needed. That reduces raw token exposure and lets revocation cut off the next use cleanly.

Practical implication: centralise token handling behind the backend and prevent agents from persisting raw downstream credentials.

Session-scoped authorization and MCP tool access

Session-scoped authorization limits an agent's access to the duration of a single approved task. In the MCP pattern, tools are discoverable at runtime, but access checks must still happen on every invocation rather than only at session start. This matters because autonomous behaviour can otherwise outlive the user's intent. When the session ends, the agent should lose access without relying on manual cleanup.

Practical implication: enforce approval-gated sessions with per-invocation checks and hard expiry for agent tool access.


Threat narrative

Attacker objective: The attacker wants durable, overbroad access to the systems and data that the agent can reach, plus the ability to act without clean revocation or attribution.

  1. Entry occurs when an agent is provisioned with a long-lived API key, shared service account, or inherited user session that can reach more systems than the task requires.
  2. Escalation follows when that credential is reused across tools or environments, letting a compromise of the agent translate into broader downstream access and weak attribution.
  3. Impact is realised when the attacker uses the exposed credential to query data, alter records, or move into production systems with no clear session boundary to contain the abuse.

Read our 52 NHI Breaches Analysis report for a comprehensive view of breaches impacting Non-Human Identities including AI Agents.


NHI Mgmt Group analysis

Long-lived credentials are a poor fit for autonomous agents because the access window outlives the task window. Traditional IAM assumes credentials persist long enough to be reviewed, rotated, or revoked after use. That assumption fails when the actor can decide and execute within the same session, because the control cycle lags the behaviour cycle. The implication is that identity programmes must stop treating agent access like ordinary server-side access.

Ephemeral credential trust debt is the hidden risk in agentic systems. Teams often accept temporary tokens and short-lived sessions as safer by default, but the debt appears when the surrounding controls still allow over-scoped access, shared accounts, or unmanaged refresh. In that state, the short lifetime reduces exposure but does not remove the governance problem. Practitioners should read this as a boundary problem, not a storage problem.

Session-scoped authorization is now a governance baseline, not an implementation preference. The article's model aligns with OWASP Non-Human Identity Top 10 thinking and zero standing privilege principles, because agents should not retain access beyond the approved task. That matters for NHI, IAM, and PAM teams alike, since the same lifecycle logic must now govern both machine and agent identities.

Identity blast radius must be measured by what the agent can reach, not by what the human intended. A shared service account or inherited user session collapses attribution and expands impact at the same time. That is a governance failure across NHI and human identity programmes, because the delegation chain has become the real security boundary. Practitioners need to reframe privilege design around containment, not convenience.

Authorization has to be tied to a named user, a named agent, and a named session. Without that triad, audit logs cannot answer who approved the action, which identity executed it, or what should be revoked after the task completes. That creates compliance and incident-response ambiguity even before any breach occurs. The practical conclusion is that identity governance for agents must be auditable at the session layer.

From our research:

  • 64% of valid secrets leaked in 2022 are still valid and exploitable today, proving that detection alone is not enough without automated revocation, according to The State of Secrets Sprawl 2026.
  • AI-related credential leaks surged 81.5% year-over-year in 2025, with the surrounding AI infrastructure leaking 5x faster than core LLM providers.
  • For deeper context, see Guide to the Secret Sprawl Challenge for remediation patterns that reduce persistent credential exposure.

What this signals

Agentic access is pushing identity teams toward session-level governance, because standing credentials make too many assumptions about how long access will remain safe. The practical shift is to treat each approved task as a bounded entitlement event, not as a durable relationship between identity and system.

Identity blast radius: the useful unit of measurement is no longer the account alone, but the combination of identity, session, and downstream systems it can touch. That is why the security boundary for AI agents needs to be mapped before the first production deployment, not after the first incident.

With 28.65 million new hardcoded secrets detected in public GitHub commits in 2025 alone, according to The State of Secrets Sprawl 2026, credential hygiene around agents is already operating at internet scale rather than pilot scale. Teams that delay scope controls will inherit the same exposure dynamics in their own agent estates.


For practitioners

  • Audit every agent-held credential path Map whether each agent currently uses environment variables, config files, shared service accounts, inherited user sessions, or managed OAuth flows, then classify the blast radius of each path.
  • Move raw secrets out of agent reach Keep downstream credentials server-side and let the application or MCP layer retrieve them on demand, so the agent only receives a scoped token for the current task.
  • Require approval-gated task sessions Make agent access expire at session end and require a fresh human approval before a new session can begin, especially where the agent can invoke external tools.
  • Separate encryption keys by organisation and context Use per-tenant or per-context encryption boundaries so a compromise in one agent workflow does not expose other customers, environments, or business units.
  • Log agent identity and delegating user identity together Record which agent acted, which user authorised the session, what session it used, and which systems it touched, so revocation and forensics are precise.

Key takeaways

  • AI agents expose a governance gap that traditional credential patterns were never designed to handle, especially when access is persistent or shared.
  • The scale of secret exposure is already high enough that detection without revocation leaves exploitable credentials in circulation.
  • Practical control now means session scope, server-side token handling, and audit trails that bind the agent to the approving user.

Standards & Framework Alignment

This section maps relevant standards and security frameworks to the operational risks and controls described in this guidance.

OWASP Non-Human Identity Top 10 and OWASP Agentic AI Top 10 address the attack and risk surface, while NIST Zero Trust (SP 800-207) set the governance and control requirements practitioners need to meet.

FrameworkControl / ReferenceRelevance
OWASP Non-Human Identity Top 10NHI-01Agent-held secrets and token exposure map to NHI identity misuse and overbroad access.
OWASP Agentic AI Top 10A1Agent tool access and session scope align with identity and privilege abuse in agentic systems.
NIST Zero Trust (SP 800-207)PR.AC-4Least-privilege access and continuous verification are central to scoped agent authorization.

Treat agent sessions as bounded entitlements and require per-invocation authorization checks.


Key terms

  • Agent Credential: A credential used by an AI agent to authenticate to tools, data sources, or downstream services. In practice, it should be scoped to a single task or session and never carry more authority than the agent actually needs to complete the approved action.
  • Session-Scoped Authorization: An access model where permissions exist only for the duration of a specific approved session. For autonomous agents, this matters because it limits how far a task can drift before access expires and prevents persistent credentials from becoming standing privilege.
  • Secret Segmentation: The practice of separating credentials by tenant, context, environment, or user so one compromise does not expose everything. For AI systems, segmentation reduces blast radius and helps align access with the exact workflow the agent is executing.

Deepen your knowledge

NHI governance, agentic AI identity, and machine identity security are core topics in our NHI Foundation Level course, the industry's only accredited NHI security programme. If you are responsible for identity security strategy or identity lifecycle management in your organisation, it is worth exploring.

This post draws on content published by WorkOS: How to manage API keys, tokens, and secrets for AI agents. Read the original.

NHIMG Editorial Note
Published by the NHIMG editorial team on 2026-06-10.
NHI Mgmt Group — the independent authority on Non-Human Identity, IAM, and Agentic AI security. nhimg.org