By NHI Mgmt Group Editorial TeamPublished 2025-10-30Domain: Workload IdentitySource: Aembit

TL;DR: Choosing between 2-legged and 3-legged OAuth depends on who authorizes access, but the deeper security issue is avoiding persistent client secrets and redirect abuse across modern workloads, according to Aembit. Secretless workload identity, PKCE, short-lived tokens, and workload identity federation are now the decisive controls for reducing exposure windows and credential sprawl.


At a glance

What this is: This is an analysis of when 2-legged versus 3-legged OAuth applies, and why secretless workload identity is the real security objective.

Why it matters: It matters because IAM teams need to govern service-to-service access, user consent flows, and workload credentials with the same lifecycle discipline, not treat them as separate problems.

By the numbers:

👉 Read Aembit's analysis of OAuth flows, workload identity, and secretless access


Context

OAuth flow choice is really an identity governance decision about who authorizes access, what entity is trusted, and how long that trust should persist. In workload-heavy environments, the question is no longer just user consent versus service autonomy, but how to avoid storing credentials that outlive their purpose.

For IAM, NHI, and workload identity teams, the practical issue is that static secrets create a recursive dependency: the service needs a secret to get a secret. That is why secretless patterns, short-lived tokens, and environment attestation now sit at the center of modern access design.

The article treats 2-legged and 3-legged OAuth as different answers to different trust problems, but the broader lesson is lifecycle control. Whether the subject is a service account, a user session, or an AI-driven workload, access should be scoped, verifiable, and easy to revoke.


Key questions

Q: How should security teams replace static secrets in service-to-service OAuth flows?

A: Security teams should move from stored client secrets to workload identity federation wherever the platform supports it. The goal is to prove workload provenance at runtime using environment attestation or signed identity tokens, then exchange that proof for short-lived access. This removes the reusable secret from the trust chain and reduces the blast radius of compromise.

Q: Why do long-lived client secrets create risk in modern workload architectures?

A: Long-lived client secrets create risk because they are reusable, difficult to revoke cleanly, and often copied across code, pipelines, and environment variables. In microservice and CI/CD environments, that turns one credential into many exposure points. The result is credential sprawl, slow rotation, and a larger window for abuse when one secret leaks.

Q: What breaks when teams use 3-legged OAuth without PKCE?

A: Without PKCE, intercepted authorization codes can be replayed by an attacker who was not the intended client. That weakens delegated authorization, especially in mobile and single-page applications where redirects are exposed to interception risk. PKCE binds the request and response together so the code is only usable by the client that started the flow.

Q: Who should own revocation and lifecycle control for workload credentials?

A: Revocation and lifecycle control should sit with the team that owns the workload, but it must also be enforced by the identity platform. Administrators need clear visibility into which services still depend on secrets, which tokens are long-lived, and which integrations can be moved to ephemeral access. That ownership model is what keeps governance practical.


Technical breakdown

2-legged OAuth and service authority

Client credentials flow is designed for machine-to-machine access where no user is present. The service authenticates with a client_id and client_secret, then receives a token representing its own authority rather than delegated user permission. That design works for backend services, but it also creates a standing credential problem because the secret must exist before the service can prove itself. In practice, the risk is not OAuth itself. The risk is that long-lived secrets become the durable identity primitive for workloads that should be ephemeral.

Practical implication: replace static client secrets with workload identity federation where the workload can prove provenance without storing a reusable secret.

3-legged OAuth, PKCE, and delegated consent

Authorization code flow introduces a resource owner who explicitly approves access. PKCE strengthens that flow by binding the authorization request to the client that started it, using a code verifier and code challenge so intercepted authorization codes cannot be reused. This is essential for mobile and single-page applications, where redirect interception is a realistic attack path. The security model is still delegated access, not ownership transfer, so token storage, state validation, and refresh token rotation remain critical parts of the design.

Practical implication: require PKCE, short token lifetimes, and secure token storage wherever user-delegated access crosses browser or mobile boundaries.

Secret zero and credential sprawl in modern workloads

The secret zero problem appears when a service needs initial credentials to reach the system that holds its credentials. That recursive trust chain is why secrets managers reduce exposure but do not eliminate the underlying problem. At scale, microservices, CI/CD jobs, and serverless workloads quickly accumulate many external dependencies, multiplying the number of secrets that need storage, rotation, and audit. The architectural lesson is that credential proliferation is a design debt, not just an operations burden.

Practical implication: inventory every workload dependency that still relies on stored secrets and prioritise the highest-risk paths for secretless replacement first.


Threat narrative

Attacker objective: The attacker aims to impersonate a trusted workload or delegated user and use that authority to access downstream services without raising immediate suspicion.

  1. entry via hardcoded client secrets or exposed stored credentials in code repositories, environment variables, or CI/CD systems.
  2. credential abuse through persistent access tokens, stolen authorization codes, or unrotated workload secrets that remain valid for long periods.
  3. impact through unauthorized service-to-service access, user impersonation, or data retrieval from APIs, databases, and SaaS systems.

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


NHI Mgmt Group analysis

Static client secrets are the wrong trust primitive for modern workloads: The article shows that 2-legged OAuth still depends on stored credentials, which means identity is anchored in something reusable rather than something provable at runtime. That is exactly why workload governance keeps collapsing under secrets sprawl, rotation lag, and environment drift. The practitioner conclusion is that access models built on durable secrets are structurally misaligned with ephemeral execution.

Secret zero is a governance failure, not just a deployment inconvenience: A service that needs a secret to retrieve its secret has already inherited a recursive trust problem. Secrets managers can reduce exposure, but they do not remove the fact that the workload must begin with trust in a stored credential. The implication is that identity programmes need to treat bootstrap trust as a first-class design constraint.

PKCE and short-lived tokens protect delegation, but they do not solve workload identity: The 3-legged flow hardens user-consent scenarios by preventing authorization code interception and limiting token lifetime. That matters for human IAM and consumer identity, but it does not answer how non-human workloads should authenticate without persistent secrets. The practitioner takeaway is to separate delegated consent controls from workload authentication design.

Secretless authentication is now the decisive control boundary for machine identity: Workload identity federation changes the governance question from 'where do we store the secret?' to 'how do we verify the workload's runtime environment?' That moves control from credential custody to environmental proof and makes lifecycle management materially easier. Teams should reframe NHI programmes around verifiable runtime identity, not secret containment.

Identity governance must cover service accounts, user sessions, and autonomous workloads consistently: OAuth is often discussed as a protocol choice, but the deeper issue is lifecycle discipline across different identity types. Whether access is delegated by a user or asserted by a workload, the organisation still needs clear ownership, revocation, and auditability. The practitioner conclusion is that IAM, NHI, and workload identity cannot be governed as separate silos.

From our research:

  • 85% of organisations lack full visibility into third-party vendors connected via OAuth apps, according to The State of Non-Human Identity Security.
  • A further 47% have only partial visibility into those OAuth-connected vendors, which means the governance gap is not limited to edge cases.
  • For teams building a response, the next step is to study Ultimate Guide to NHIs , Key Challenges and Risks for the operational controls that close visibility and ownership gaps.

What this signals

Credential sprawl is becoming the real control problem: When a single service can require 5-10 external dependencies, the old assumption that each application has a manageable credential set no longer holds. That is why secretless patterns, federation, and tighter lifecycle ownership are moving from architecture preference to governance necessity. Teams should expect service inventories to become identity inventories, not just application inventories.

Secretless design is now a forward-looking access strategy, not an advanced option: The more workloads depend on short-lived tokens and environment attestation, the less value there is in managing long-lived secrets as a core security primitive. For NHI programmes, that changes the roadmap from rotation-heavy operations to trust-boundary redesign. The relevant reference point is Ultimate Guide to NHIs , Static vs Dynamic Secrets.

There is still a measurable visibility gap in OAuth-connected ecosystems: With 85% of organisations lacking full visibility into third-party vendors connected via OAuth apps, identity teams should assume that delegated access often exceeds governance reach. The practical signal is not just token age, but whether every connected app has an owner, a revoke path, and a documented purpose. That is the line between managed integration and shadow access.


For practitioners

  • Replace static client secrets with federated workload identity Map every service-to-service integration that still depends on stored credentials, then move the highest-risk ones to environment-based attestation and short-lived token exchange. Prioritise CI/CD, serverless, and microservice paths where secret reuse is most likely.
  • Enforce PKCE and strict callback validation for delegated flows Require PKCE for all mobile and browser-based applications, validate the state parameter on every callback, and keep access tokens short-lived with rotation for refresh tokens. This reduces interception and replay risk in user-consent journeys.
  • Treat secret zero as a design defect Document where workloads still need an initial credential to reach a secret store, then redesign those bootstrap paths so the workload can prove identity without holding a reusable secret. Use this review to eliminate recursive trust chains.
  • Review workload dependencies for credential sprawl Build an inventory of each service's external dependencies and the secrets they require, then align rotation and offboarding with the lifecycle of the workload rather than the lifecycle of the application release.

Key takeaways

  • OAuth flow selection is really an identity governance decision about authority, delegation, and revocation.
  • Static secrets and secret zero dependencies create the exposure conditions that modern workload identity is meant to remove.
  • Teams should prioritise federated, short-lived, and verifiable access patterns before adding more secrets management layers.

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 address the attack and risk surface, while NIST CSF 2.0 and NIST Zero Trust (SP 800-207) set the governance and control requirements practitioners need to meet.

FrameworkControl / ReferenceRelevance
OWASP Non-Human Identity Top 10NHI-03Persistent client secrets and rotation lag are core NHI credential risks.
NIST CSF 2.0PR.AC-4OAuth scopes and delegated access map to least-privilege access control.
NIST Zero Trust (SP 800-207)Workload identity federation supports continuous verification instead of implicit trust.

Replace stored workload secrets with ephemeral identity and rotate any remaining credentials aggressively.


Key terms

  • 2-legged OAuth: A service-to-service OAuth flow where a client authenticates directly to an authorization server using its own credentials. The token represents the service's authority, not a user's delegated permission, which makes it suitable for backend workloads but risky if the client secret is stored long term.
  • 3-legged OAuth: A delegated OAuth flow where a user explicitly approves what an application can access on their behalf. The authorization code flow introduces the resource owner into the trust chain, which means token handling, consent boundaries, and revocation become central governance concerns.
  • Secret Zero: The bootstrap problem where a workload needs an initial credential in order to retrieve or use other credentials. It exposes a recursive trust dependency that secrets managers can reduce but not fully remove, which is why secretless authentication patterns are increasingly preferred.
  • Workload Identity Federation: An authentication pattern that lets a workload prove who it is by presenting cryptographic evidence from a trusted runtime environment instead of a stored secret. It reduces credential sprawl and shortens the life of access by exchanging proof for temporary credentials.

Deepen your knowledge

NHI Foundation Level course, the industry's only accredited NHI security programme, covers NHI governance, agentic AI identity, machine identity security, IAM, human identity, identity lifecycle, secrets management, and workload identity. If you are responsible for identity security strategy or programme maturity, it is worth exploring.

This post draws on content published by Aembit: OAuth flow choice and secretless access for modern workloads. Read the original.

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