Credential vending

The agent should act as the actual user, not as a shared account

A JWT-to-PAT exchange for Snowflake: short-lived, role-scoped, auto-rotating.

Kevin Keller ยท kevinkeller.org

Why it matters

Governance depends on who is calling

  • Row access, masking and audit all depend on the executing user
  • A shared service account makes every query look the same
  • Per-user data governance is lost
  • The goal: SQL runs as the human, who never logs into Snowflake directly

Why it's hard

No obvious method fits a headless agent

MethodProblem for agents
Username and passwordMFA, unsafe to automate
Key-pairTied to one user, doesn't scale
OAuth browser flowAgents are headless
OAuth refresh tokensRotate on every use
PATsGood fit, but how to get one without a browser?

The exchange

From identity provider to MCP in four steps

  1. The user's IdP issues a JWT
  2. Snowflake External OAuth turns the JWT into a session
  3. The session creates or rotates a one-day PAT, restricted to one role
  4. The agent sends the PAT as a Bearer token to the MCP server

The key constraint

PATs cannot mint PATs.

Every create, rotate and remove needs JWT or OAuth authentication. A leaked PAT cannot be used to issue more.

Lifecycle

One PAT per user, one standard name

  • MCP_PAT avoids the 15-PATs-per-user limit
  • No PAT yet: create with DAYS_TO_EXPIRY=1
  • PAT exists: rotate, old secret dead at once
  • Expired rotated tokens: cleaned up automatically
  • Every call to exchange_token() returns a valid secret

What you get

Ephemeral credentials from existing identity

  • Your IdP: Entra ID, Okta or whatever you already use
  • Short-lived: a leaked PAT is useless tomorrow
  • Least privilege: OAuth-derived PATs must be role-restricted
  • Auditable: every creation and rotation in QUERY_HISTORY

Which pattern when

Match the credential to the workload

PatternBest forUser interaction
OAuth + continuous refreshDashboards, ETLOnce, in a browser
JWT to PAT exchangeAgents, headless automationNever
Static PATQuick tests, devOnce, in the UI

Today's recommended path

External OAuth now works directly with MCP

External OAuth tokens work directly with Snowflake's managed MCP servers, no PAT exchange needed.

The exchange still shows the mechanics of credential vending: token exchange, scope attenuation, lifecycle and audit.

Takeaway

Derive agent credentials from the user's identity: short-lived, scoped, rotated.

Read the full article

Educational proof of technology