Snowflake Cortex OAuth: Three Patterns for Authenticating AI Agents
Your agent can query Snowflake Cortex AI. The question nobody wants to answer first: who is the agent when it asks? AWS tested three OAuth patterns end to end, and the answer decides whether your audit trail names a real human — or a shared service account that hides everyone.
The shared service account is an audit black hole
The lazy default is a broad service account. It works, right up until compliance asks who ran a query and every row in QUERY_HISTORY says the same machine name. No per-user attribution, no row-level security keyed to the actual person, no masking that respects who asked. AWS's three patterns exist precisely because that shortcut is a governance failure dressed up as simplicity.
Pattern 1: Snowflake as its own IdP — the honest proof of concept
Snowflake runs its own OAuth server, users authenticate directly, and every query runs as the real user with their real role. The audit trail works. The catch: your users need Snowflake credentials and you manage the whole flow yourself — consent screens, role scopes in uppercase, a 10-minute window to complete the token exchange. Fine for a PoC. Not a corporate identity strategy.
Pattern 2: corporate SSO — the one most enterprises should pick
Same per-user attribution, but the IdP is Okta or Entra ID, so MFA, conditional access, and session policies come free. Snowflake just validates the JWT locally against the IdP's published keys — it never calls the IdP at runtime. One wrinkle worth knowing: disable a user in the IdP and their cached tokens still work until they expire. You have to force re-authentication explicitly.
Pattern 3: the shared service user — convenient, and that's the problem
Machine-to-machine, no consent screens, no browser redirects. Also: no per-user identity at all. Every query is one service user, one role, and your row-level security collapses to that single identity. AWS is blunt about it. This is the right call for genuinely unattended batch jobs — and the wrong call the moment anyone asks "who asked for that data?"
The fourth option AWS barely mentions is the interesting one
On-behalf-of token exchange gives you per-user identity for unattended workloads — no consent prompt, no browser redirect, but QUERY_HISTORY still names the real user. If your auditors need real usernames and your workload has no human in the loop, evaluate OBO before you default to Pattern 3's shared account. It's the pattern that refuses the false choice.
Go deeper
The full article walks through the exact OAuth wiring for each pattern — security integrations, role scopes, token lifetimes, and the Entra ID claim-mapping gotchas (like mapping LOGIN_NAME to a GUID) — on Agentic Affairs: https://agentic-affairs.com/snowflake-cortex-oauth-patterns/
Originally published on Agentic Affairs (https://agentic-affairs.com)

