Agent Identity Crisis: Why Service Accounts, Not Users, Hold Agentic AI's Real Keys

Agent Identity Crisis: Why Service Accounts, Not Users, Hold Agentic AI’s Real Keys

📋 Key Takeaways
  • Autonomous agents act through non-human identities.
  • Traditional application security has a well-established identity story: user logs in, MFA challenge, session token, done.
  • The scale of the problem is well documented.
  • Not all agent credentials are equal. Know what you're holding
11 min read · 2,166 words
Educational & Ethical Use Only — This article is provided for educational and ethical cybersecurity research purposes only. The techniques described should only be used on systems you own or have explicit permission to test. Always follow responsible disclosure and the laws applicable to you. Mitigations are included so engineers can harden real systems.
Security· 11 min read

🔎 Last updated · Editorial policy · Report an error

{
“@context”: “https://schema.org”,
“@type”: “Article”,
“headline”: “Agent Identity Crisis: Why Service Accounts, Not Users, Hold Agentic AI’s Real Keys”,
“description”: “A hands-on deep dive into non-human identity for agentic AI: why service accounts carry the real risk, and how token scoping and least privilege keep autonomous agents in check.”,
“publisher”: {“@type”: “Organization”, “name”: “Hmmnm – Cybersecurity Tutorials”, “url”: “https://hmmnm.com”}
}

When your autonomous agent writes to a database, deletes cloud storage, or emails a customer, it isn’t your user doing it—it’s a service account. Agentic AI service accounts, tokens, and workload credentials are the real keys to your environment; secure those first, because the agent framework itself is just the puppet.

TL;DR: Agentic AI Runs on Service Accounts, Not User Logins

Autonomous agents act through non-human identities. A user may consent to an OAuth flow once, but everything the agent does afterward—tool calls, API requests, infrastructure changes—executes under a service account, a machine token, or a workload identity. That means your identity program, built for humans with MFA and SSO, is blind to the credentials that actually move data and mutate state. Inventory non-human identity, scope tokens tightly, rotate aggressively, assign ownership. That’s the whole ballgame.

How Agents Actually Authenticate: From User Sessions to Workload Identity

Traditional application security has a well-established identity story: user logs in, MFA challenge, session token, done. Agentic AI throws most of that out the window.

Follow the chain in a typical deployment:

  • Step 1 — User consent: A human authorizes the agent platform via OAuth 2.0 or delegates permissions through an enterprise IdP (Entra ID, Okta).
  • Step 2 — Platform service account: The agent runtime itself authenticates to your infrastructure with its own credentials—a Kubernetes service account, a GCP service account, an AWS IAM role, or a plain static API key someone pasted into a config.
  • Step 3 — Tool credentials: Each tool the agent calls (database connector, ticketing API, email integration) carries its own credential, often provisioned independently of the platform identity.
  • Step 4 — Workload identity: In mature setups, the agent’s compute (a pod, a Lambda function, a CI job) federates to short-lived tokens via OIDC—no stored secrets at all.

The user’s session may expire in eight hours. The service account key provisioning the agent’s tools may have been valid since 2023. You’re not securing a user—you’re securing a workload that never logs off.

The Service Account Problem: Sprawl, Stale Secrets, and Ownerless Accounts

The scale of the problem is well documented. In its 2024 report on securing machine identities, CyberArk noted that non-human identities outnumber human identities by roughly 45:1 in enterprise environments; even conservative industry estimates put the ratio above 10:1. The Cloud Security Alliance and CISA have both flagged non-human identity as a top maturity gap—CISA’s identity guidance consistently emphasizes that machine credentials lack the lifecycle controls humans take for granted.

For agentic AI specifically, this compounds badly:

  • Sprawl: Every new agent, every new tool integration, every proof-of-concept spawns credentials. Nobody inventories them because there’s no onboarding workflow for “the sales-forecasting agent.”
  • Stale secrets: Static API keys embedded in agent configs don’t expire. A key leaked in a repo in 2024 is still valid in 2026.
  • Ownerless accounts: When the engineer who built the agent leaves, the service account remains—fully privileged, fully forgotten. That’s your attack path.

Over-privileged, ownerless service accounts are the single largest risk in agent deployments: they turn a prompt-injection bug in one tool into an environment-wide compromise. The OWASP Top 10 for LLM Applications highlights excessive agency—agents with too many permissions and too little constraint—as a first-class failure mode, and excessive agency maps almost entirely onto non-human identity misuse.

Anatomy of an Agent Credential: Keys, Tokens, and Federated Identity

Not all agent credentials are equal. Know what you’re holding:

  • Static API keys: Long-lived, unscoped or loosely scoped, no expiry. Easiest to deploy, easiest to leak, hardest to rotate safely. Acceptable only as a last resort.
  • OAuth 2.0 access tokens: Shorter-lived (minutes to hours), can carry granular scopes, often paired with refresh tokens—the refresh token becomes your new long-lived secret.
  • OIDC / workload identity federation: The compute platform exchanges a signed attestation (a service account JWT from GKE, a Kubernetes projected token, a GitHub OIDC token) for cloud credentials. No stored secret exists to steal. This is the target architecture.

The trade-off is operational complexity: federation requires your runtime to support token exchange, and every tool vendor must accept it. Most can’t yet—which is why hybrid patterns dominate real deployments.

Token Scoping in Practice: Least Privilege for Autonomous Agents

Scoping is where least privilege becomes real. Principles, then commands:

  • Scope per action, not per agent. If the agent reads calendars and writes tickets, it needs two identities or two distinct token exchanges—not one token with read-write on everything.
  • Minimize scope strings. Prefer https://www.googleapis.com/auth/calendar.events.readonly over the full calendar scope. On AWS, a scoped-down policy is worth ten reviews.
  • Short TTLs. Fifteen to sixty minutes for access tokens. An attacker who steals a 20-minute token has a 20-minute problem.
  • Audience restriction. Bind JWTs to a specific aud claim so a token minted for the ticketing API can’t be replayed against the storage API.

A least-privilege AWS policy for a document-summarizing agent:

{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Effect": "Allow",
      "Action": ["s3:GetObject"],
      "Resource": "arn:aws:s3:::docs-inbox/*"
    },
    {
      "Effect": "Allow",
      "Action": ["sqs:SendMessage"],
      "Resource": "arn:aws:sqs:us-east-1:123456789012:summary-jobs"
    }
  ]
}

No list, no delete, no cross-bucket wildcards. The agent can read documents and enqueue results—nothing else.

Per-Task vs Shared Identity: Segmenting Agent Permissions

Three design patterns, in ascending order of maturity:

  1. One identity per agent. Each agent gets its own service account. Compromise of one agent doesn’t yield another’s credentials. This is the floor.
  2. One identity per task. Multi-step agents mint or assume narrow credentials per step—read identity for retrieval, write identity for publishing. This is the target for anything touching production data.
  3. Brokered access via secret manager. No credentials live in agent configs. The agent requests short-lived secrets from HashiCorp Vault, AWS Secrets Manager, or Azure Key Vault at runtime, with audit logging on every issuance and TTLs measured in minutes. Vault’s dynamic secrets exist precisely for this.

Just-in-time credentials—assuming a role only while a task runs, then dropping it—shrink your steady-state attack surface to near zero.

Blast Radius: What a Compromised Agent Can Actually Do

Walk the abuse path. An attacker injects instructions into a document your research agent ingests—a classic indirect prompt injection. The agent, now following attacker logic:

  1. Exfiltrates: Uses its over-scoped API token (it has s3:* because “read” and “delete” were one checkbox during setup) to copy customer data to an attacker-controlled bucket.
  2. Pivots: Reads a chained tool credential—a GitHub token stored in the same secret scope—and opens a PR with a backdoor.
  3. Persists: Modifies its own tool configuration, since the agent’s service account had write access to the config store that defines its permissions.

Every step was authorized. Every call used a valid, legitimate credential. That’s the terrifying part—your logs show nothing anomalous at the authentication layer. Blast radius is a direct function of scope width and credential lifetime, which is why those two controls matter more than any agent-framework hardening.

Hands-On Lab: Auditing and Hardening an Agent’s Service Account

Enumerate what you have. On GCP:

gcloud iam service-accounts list
gcloud iam service-accounts keys list 
  --iam-account=agent-prod@project.iam.gserviceaccount.com

Any key older than 90 days is a finding. Delete stale keys:

gcloud iam service-accounts keys delete KEY_ID 
  --iam-account=agent-prod@project.iam.gserviceaccount.com

On AWS, find unused roles:

aws iam generate-service-last-accessed-details 
  --arn arn:aws:iam::123456789012:role/agent-runtime
aws iam list-roles --query "Roles[?starts_with(RoleName, 'agent')]"

Replace static keys with OIDC federation. For a CI-deployed agent, GitHub’s OIDC provider eliminates stored AWS keys entirely:

aws iam create-role --role-name agent-ci-role 
  --assume-role-policy-document file://trust-github-oidc.json

Where static keys are unavoidable, enforce rotation in CI:

# .gitlab-ci.yml fragment
rotate_agent_key:
  script:
    - NEW_KEY=$(gcloud iam service-accounts keys create - 
        --iam-account=agent-prod@project.iam.gserviceaccount.com 
        --key-file-type=json)
    - vault kv put secret/agent/gcp key=@new-key.json
    - gcloud iam service-accounts keys delete $OLD_KEY_ID 
        --iam-account=agent-prod@project.iam.gserviceaccount.com
  rules:
    - if: '$CI_PIPELINE_SOURCE == "schedule"'

Then set an organizational policy blocking long-lived keys where federation exists—GCP’s organization policy constraints and AWS SCPs both support this.

Detection and Monitoring: Blue-Team Signals for Rogue Agent Behavior

You can’t MFA a service account, so detection carries more weight. High-value log sources and signals:

  • Token issuance anomalies: Spikes in STS AssumeRole calls or GCP GenerateAccessToken events from a single workload identity.
  • Scope escalation: An agent suddenly requesting scopes or permissions it has never used—compare token scp/scope claims against a 30-day baseline.
  • New key creation: Alert on every CreateServiceAccountKey / CreateAccessKey event; key creation should be rare, automated, and predictable.
  • Cross-audience replay: A JWT’s aud claim doesn’t match the receiving API—the signature of token replay.
  • Volume and time-of-day: Agents run on schedules. An agent making API calls at 03:14 on a Saturday, outside its schedule, deserves a page.

Ship cloud audit logs and IdP sign-in logs (filtered to non-human principals) into your SIEM, and build detections keyed on service-account fields, not user fields. GCP’s Policy Intelligence and AWS IAM Access Analyzer both surface over-privilege automatically—use them.

CTF and Practice Angles: Attacking Non-Human Identity

Want to build the muscle? Common challenge patterns you’ll encounter in cloud-security CTFs (tryHackme, HackTheBox, and vendor labs like GCP’s own capture-the-flag scenarios):

  • Leaked service-account keys: Find a key file committed to a repo or baked into a container image, then enumerate its permissions. Practice: audit your own repos with gitleaks.
  • Scope confusion: A token minted for one API accepted by another because audience validation was skipped. Build a deliberately broken JWT validator and attack it.
  • Token replay: Capture a token in one context and reuse it where TTL and revocation checks are missing.
  • Metadata endpoint abuse: SSRF against 169.254.169.254 to steal workload credentials—the classic GCP/AWS challenge. This is exactly what an agent exposed to untrusted input risks.

Practice only against environments you own or that explicitly authorize testing.

A Least-Privilege Checklist for Agentic AI Deployments

  • Inventory: Enumerate every non-human identity your agents use—service accounts, API keys, workload roles, OAuth grants. Nothing else works without this.
  • Scope: Right-size every permission to the narrowest set of actions the task requires; split read and write into separate identities.
  • Rotate: Prefer federated short-lived tokens (minutes-to-hours TTLs); automate rotation for any unavoidable long-lived secret.
  • Restrict audience: Bind every token to a single intended API via aud claims.
  • Broker secrets: No credentials in agent configs—issue from Vault or a cloud secret manager with audit logging.
  • Assign ownership: Every agent identity has a named human owner and a documented offboarding procedure.
  • Monitor: Alert on key creation, scope escalation, issuance anomalies, and off-schedule activity for non-human principals.
  • Review quarterly: Re-run least-privilege analysis (Access Analyzer, Policy Intelligence) and delete what’s unused.

Your agents are only as trustworthy as the identities they borrow. Lock those down, and the prompt-injection headline of the week becomes a footnote instead of an incident report.

Frequently Asked Questions

Why do autonomous agents need their own identities?

Agents act independently of users—at all hours, across multiple systems, sometimes in parallel. Attributing their actions to a human login breaks audit trails and violates least privilege: the human never needed write access to the database the agent mutates. A dedicated per-agent identity makes actions attributable, scoped, and revocable without touching the user.

Are static API keys safe for agentic AI?

Generally, no. They don’t expire, they’re trivially copied into repos and configs, and rotating them without downtime is painful—so nobody does. Prefer short-lived, federated tokens via OIDC workload identity. Where static keys are unavoidable, scope them tightly, store them in a secret manager, and automate rotation on a fixed schedule.

How often should agent service-account credentials be rotated?

Tie rotation to token lifetime policy. Access tokens should live minutes to hours. For genuinely long-lived secrets (API keys you can’t replace yet), automate rotation every 30–90 days—and treat anything older as an open finding. Federation where possible beats rotation everywhere else.

How is securing agent identity different from securing user identity?

Volume (non-human identities outnumber humans 10:1 or more), no MFA, no human in the loop to notice odd behavior, and pervasive ownership gaps. Users forget passwords; service accounts outlive their creators. Inventory and monitoring—things humans do for themselves—are exactly what machine identities can’t do, so you must do it for them.

What’s the first step to harden an existing agent deployment?

Inventory every non-human identity and its effective permissions, then right-size scopes before adding anything else. Monitoring over a sprawl of ownerless, over-privileged accounts just generates noise. Shrink the blast radius first, then build detections on top of identities you actually understand.

Hmmnm
Published by Hmmnm

Hands-on cybersecurity tutorials, CVE breakdowns, and guided learning paths — written and lab-tested by the Hmmnm team.

Keep going — the structured way
This post is one step. The learning paths chain the next ones for you, with progress tracking and no account needed.
Follow a learning path →

Prabhu Kalyan Samal

Application Security Consultant and founder of Hmmnm. Certified Red Team Operator, Burp Suite Certified Practitioner, eWPTX, CompTIA SecurityX and Azure Security Engineer. Writes hands-on labs and threat analysis on web, cloud and AI-agent security.