본문으로 건너뛰기
AI NEWS JOURNAL
AWS Machine Learning BlogAI NEWS / JOURNAL

Secure OAuth patterns for Snowflake Cortex AI through Amazon Bedrock AgentCore

When an AI agent on Amazon Bedrock AgentCore calls Snowflake Cortex AI over MCP, how does it authenticate? This post walks through three OAuth patterns we tested on AgentCore Identity: Snowflake OAuth, three-legged OAuth with a corporate IdP, and two-legged OAuth, so you can match your organization's identity, audit, and compliance needs.

번역 서비스가 일시 중지되어 원문을 표시합니다.

Enterprises today need a clear way to extend their authentication and authorization controls into the agentic layer, often requiring either broad service account permissions or custom-built auth integrations that add operational overhead. When an AI agent running on Amazon Bedrock AgentCore (a platform to build, connect, and optimize agents at scale, with any framework or model) needs to call the Snowflake-managed MCP server (which exposes Snowflake Cortex Agents as one of its tool types) through the Model Context Protocol (MCP), the first question enterprises must answer is: how does the agent authenticate? In this post, we walk through three Open Authorization (OAuth) configurations we tested on Amazon Bedrock AgentCore Identity, a capability of Amazon Bedrock AgentCore: Snowflake OAuth (per-user, no external Identity Provider, or IdP), three-legged OAuth with a third-party Identity Provider (corporate single sign-on, or SSO), and two-legged OAuth with a third-party Identity Provider (shared service user). Amazon Bedrock AgentCore Identity also supports an on-behalf-of (OBO) grant (TOKEN_EXCHANGE) that delivers per-user identity for unattended workloads without a consent prompt. We focus on the three configurations we tested end-to-end, flagging where OBO fits as we go. By the end, you will be able to identify which pattern suits your enterprise scenario. Solution overview Amazon Bedrock AgentCore Gateway, a capability of Amazon Bedrock AgentCore, connects AI agents to external tool providers through MCP server targets. It targets the Snowflake-managed MCP server, which surfaces Cortex Search and Cortex Analyst as MCP tools that an MCP-aware client can discover and invoke. Rather than acting as a wrapper, the Gateway aggregates the capabilities of its configured targets into a single unified catalog, which it presents to the agent as one tools/list response. The core focus of this post is the outbound authentication for Amazon Bedrock AgentCore Gateway: how it obtains and presents OAuth tokens to the Snowflake-managed MCP server. Amazon Bedrock AgentCore Identity acts as the credential broker: the Gateway obtains a workload token by calling GetWorkloadAccessTokenForJWT (because the Gateway uses JSON Web Token (JWT) inbound authentication), then calls GetResourceOauth2Token against the configured provider. AgentCore Identity owns the token vault, the token refresh, and the user-to-token binding, and it fetches, caches, and refreshes tokens automatically. Amazon Bedrock AgentCore Identity supports three OAuth configurations spanning two grant types (authorization_code and client_credentials): Snowflake OAuth: Snowflake acts as its own OAuth authorization server. Each user authenticates directly to Snowflake through the Authorization Code grant (3LO). No external identity provider is needed. Three-legged OAuth using a third-party Identity Provider: Users authenticate through corporate SSO with the Authorization Code grant. Snowflake trusts IdP-issued JSON Web Tokens (JWTs) through its External OAuth security integration. Two-legged OAuth pattern using a third-party IdP: A shared service user authenticates through the client_credentials grant of the IdP. No user interaction or consent is required, which is ideal for machine-to-machine workloads. Amazon Bedrock AgentCore Identity also offers an API-key credential provider (which supports Snowflake Programmatic Access Tokens). We focus on OAuth here for per-user attribution and automatic token refresh. Each configuration uses a credential provider in Amazon Bedrock AgentCore Identity (CustomOauth2, OktaOauth2, or MicrosoftOauth2) and a corresponding security integration on the Snowflake side. Note: We tested these patterns with the Snowflake-managed MCP server using Okta and Microsoft Entra ID. Patterns 2 and 3 (external IdP) follow standard OAuth flows, so they can extend to other OAuth-protected MCP servers, but validate the token claims, scopes, and audience settings for your SaaS provider. Only Pattern 1 is Snowflake-specific, because it relies on Snowflake’s built-in OAuth authorization server. The Snowflake-specific elements are the OAUTH_AUTHORIZATION_SERVER issuer-lock parameter, the session:role: / session:scope: grammar, BLOCKED_ROLES_LIST, LOGIN_NAME / EMAIL_ADDRESS mapping, and QUERY_HISTORY attribution. If your SaaS exposes its own internal OAuth server, you configure outbound OAuth the same way as Snowflake OAuth. 2LO does not require a built-in vendor. CustomOauth2 with the CLIENT_CREDENTIALS grant can work with your choice of OAuth 2.0 authorization server. When Amazon Bedrock AgentCore Gateway brokers the token (the pattern in this post), Snowflake validates it through the TYPE = EXTERNAL_OAUTH security integration. Setting OAUTH_AUTHORIZATION_SERVER (with ALTER ACCOUNT, DATABASE, or SCHEMA) is what lets direct MCP clients auto-discover your IdP through the Protected Resource Metadata endpoint, and it issuer-locks the MCP endpoint to that integration. If you set OAUTH_AUTHORIZATION_SERVER to issuer-lock an MCP scope to an external IdP (Pattern 2), Snowflake OAuth tokens (Pattern 1) are rejected for MCP servers in that scope and do not fall back. If you need both patterns in one account, set this parameter per schema or database so each scope resolves to the right authorization server. Solution architecture The following diagram shows the solution we built and the components it uses: a user-facing AI application, a Strands agent on Amazon Bedrock AgentCore Runtime, a capability of Amazon Bedrock AgentCore, Amazon Bedrock for reasoning, with Amazon Bedrock Guardrails redacting personally identifiable information (PII) from prompts and responses, Amazon Bedrock Knowledge Bases, the fully managed Retrieval Augmented Generation (RAG) capability, over policy documents in Amazon Simple Storage Service (Amazon S3), Amazon Bedrock AgentCore Gateway with the Snowflake-managed MCP server as its target, and Amazon Bedrock AgentCore Identity holding the token vault. The outbound OAuth path has the same shape in all three patterns: the Gateway resolves a token through AgentCore Identity, which obtains and renews it from an authorization server, and the Gateway then presents that token to the Snowflake-managed MCP server. What changes between the patterns is which authorization server issues the token and under which grant: Snowflake’s own built-in OAuth server, or a third-party IdP. Those differences are set out in the Pattern comparison table, and each pattern’s runtime flow has its own sequence diagram later in this post. Figure 1: Solution overview: the reference agent on Amazon Bedrock AgentCore, combining Amazon Bedrock Knowledge Bases with Snowflake Cortex AI through the Snowflake-managed MCP server, and the authorization server that differs across the three OAuth patterns Pattern analysis The following sections examine each pattern in detail: the authentication flow, configuration steps, and trade-offs to help you select the right approach for your use case. Pattern 1: Snowflake OAuth (three-legged) The Snowflake OAuth pattern uses a three-legged OAuth (3LO) flow to deliver per-user authentication without requiring an external identity provider. Each user authenticates to Snowflake with their own credentials, consents to a specific Snowflake role, and Amazon Bedrock AgentCore Identity caches that user’s access and refresh tokens. Every subsequent Snowflake call executes as that user, and QUERY_HISTORY records their real username. Note that per-role consent is not the default. The Snowflake-managed MCP server advertises session:role:all and falls back to DEFAULT_ROLE, so you set OAUTH_SCOPES_SUPPORTED (an account-, database-, or schema-level parameter set with ALTER) to narrow the role scope the server advertises, and restrict ALLOWED_ROLES_LIST on the integration to enforce which roles a user can consent to (PRE_AUTHORIZED_ROLES_LIST does the opposite: it lists roles that skip the consent step). What makes this pattern appealing is its simplicity: no external identity provider is required. Snowflake acts as both the authorization server and the resource server, exposing its own built-in OAuth endpoints (/oauth/authorize and /oauth/token-request). Setup follows a specific order, because the callback URL does not exist until the credential provider is created. The administrator first creates the CustomOauth2 credential provider in Amazon Bedrock AgentCore Identity with placeholder client credentials and records the callbackUrl that AgentCore Identity returns. That callbackUrl is then registered as the redirect URI on a Snowflake security integration created with TYPE = OAUTH and OAUTH_CLIENT = CUSTOM. Finally, the administrator updates the credential provider with the real client ID and secret issued by Snowflake and configures the provider’s oauthDiscovery with explicit authorization server metadata: the issuer (the Snowflake account URL), the authorization endpoint (/oauth/authorize), and the token endpoint (/oauth/token-request). The following screenshot shows the configuration steps for credential provider vendors in Amazon Bedrock AgentCore Identity with Snowflake OAuth (3LO) settings. Figure 2: Configuring the Snowflake OAuth (3LO) credential provider vendor in Amazon Bedrock AgentCore Identity Next, the Amazon Bedrock AgentCore Gateway configuration points to the Snowflake-managed MCP server endpoint and references the custom Snowflake OAuth for outbound authentication. Figure 3: Amazon Bedrock AgentCore Gateway configuration pointing to the Snowflake-managed MCP server endpoint and Snowflake OAuth (3LO) as outbound auth The following sequence diagram shows the runtime authorization flow for the Snowflake OAuth pattern. Figure 4: Snowflake OAuth (3LO) runtime authorization flow: Amazon Bedrock AgentCore Gateway MCP server target with AUTHORIZATION_CODE grant, per-user Snowflake OAuth, and session:role:ANALYST_ROLE scope The Snowflake OAuth authorization flow works as follows: When a tool call requires a Snowflake token, Amazon Bedrock AgentCore Gateway obtains a workload token by calling GetWorkloadAccessTokenForJWT and calls GetResourceOauth2Token to check the token vault of Amazon Bedrock AgentCore Identity for the user. If no token is cached, the Gateway returns a JSON-RPC error code -32042 carrying a URL elicitation. That authorization URL belongs to AgentCore Identity and is session-URI-bound. The client opens that URL in the user’s browser, which is routed to Snowflake’s built-in authorization server (/oauth/authorize) and shown a Snowflake login screen. The user enters their Snowflake credentials and is presented with a consent screen asking them to authorize access using a specific Snowflake role (for example, ANALYST_ROLE). Role names in the requested scope must be uppercase (for example, session:role:ANALYST_ROLE). Upon consent, Snowflake’s authorization server returns an authorization code to the callback URL of Amazon Bedrock AgentCore Identity. AgentCore Identity then redirects the user’s browser to the return URL with the session URI. AgentCore Identity completes the code exchange only after the application calls CompleteResourceTokenAuth with the user identity and session URI (valid for 10 minutes). This step binds the code to the originating request and blocks authorization-URL hijacking. The return URL used here is registered by calling UpdateWorkloadIdentity. In production, the endpoint at that URL is hosted either by your web application or, for gateways with JWT inbound authentication, by the AgentCore Identity Consent Portal (/connect/callback). The agentcore dev CLI hosts it only for local development. AgentCore Identity then exchanges the code at Snowflake’s token endpoint (/oauth/token-request) for an access token and, optionally, a refresh token. When the client retries the tool call, Amazon Bedrock AgentCore Gateway retrieves the cached access token from AgentCore Identity and presents it to the Snowflake-managed MCP server. Snowflake validates the token and creates a user session scoped to the consented role. The consented scope controls the primary role only. Because secondary roles are governed by the integration, set OAUTH_USE_SECONDARY_ROLES = NONE (the default) so the session cannot carry more privilege than the consented role, which the IMPLICIT setting would allow. Access tokens are short-lived. By default, they last 600 seconds (maximum 3600). When an access token expires, Amazon Bedrock AgentCore Identity automatically uses the refresh token to obtain a new access token, with no user interaction required. If the security integration is configured to prevent refreshing tokens, the user must re-authorize through the consent screen. Refresh-token lifetime is controlled by OAUTH_REFRESH_TOKEN_VALIDITY. The reference implementation sets it to 86400 seconds (1 day), and Snowflake allows up to 90 days. OAUTH_ISSUE_REFRESH_TOKENS (default TRUE) governs whether refresh tokens are issued at all. Note: By default, Snowflake helps prevent the ACCOUNTADMIN, ORGADMIN, GLOBALORGADMIN, and SECURITYADMIN roles from being used with OAuth integrations. This is controlled by BLOCKED_ROLES_LIST for Snowflake OAuth (and EXTERNAL_OAUTH_BLOCKED_ROLES_LIST for External OAuth), applies to all three patterns, and covers the primary role only. With OAUTH_USE_SECONDARY_ROLES = IMPLICIT, secondary roles can still carry these privileged roles. Considerations The Snowflake OAuth pattern is the simplest path to per-user audit trails. It needs no external IdP configuration and no additional vendor dependency. It is best suited for scenarios where: Users already have Snowflake credentials and are comfortable signing in directly. You want per-user attribution in QUERY_HISTORY without an external identity provider. You are in a proof-of-concept phase and want to validate the per-user model quickly. Compliance requirements mandate individual accountability, so each query must be traceable to a specific user, not a shared service user. You prefer to manage user lifecycle (provisioning, deprovisioning, role grants) entirely within Snowflake. You want to avoid token claim mapping complexities. Snowflake issues tokens and knows exactly which user they represent. Pattern 2: Three-legged OAuth (3LO) using a third-party Identity Provider (IdP) This pattern combines per-user authentication with corporate single sign-on. Users sign in through the external IdP, which enforces multi-factor authentication (MFA), conditional access, and session policies. The IdP-issued JWT is presented to Snowflake, which validates it through its External OAuth security integration (optionally issuer-locked to the MCP server’s schema, database, or account with OAUTH_AUTHORIZATION_SERVER). Snowflake verifies the issuer, audience, and signature through a JSON Web Key Set (JWKS). It then maps a configurable claim, set with EXTERNAL_OAUTH_TOKEN_USER_MAPPING_CLAIM (sub for Okta, upn for Microsoft Entra ID), to a Snowflake user’s LOGIN_NAME or EMAIL_ADDRESS (with EXTERNAL_OAUTH_SNOWFLAKE_USER_MAPPING_ATTRIBUTE), and runs the query as that user. The security integration parameter values are case-sensitive. The key difference from Pattern 1: the authorization server is your corporate IdP (such as Okta, Microsoft Entra ID), not Snowflake. Snowflake remains the resource server. Users authenticate with the same credentials and policies they use for every other corporate application. No separate Snowflake passwords are required. On the Amazon Bedrock AgentCore side, Amazon Bedrock AgentCore Identity provides built-in credential provider vendors for popular identity providers (for example, OktaOauth2 and MicrosoftOauth2). These vendors accept the client ID, client secret, and IdP endpoints through includedOauth2ProviderConfig, compared to the generic CustomOauth2 provider used in Pattern 1. The Snowflake-managed MCP server uses pre-registered OAuth clients, so you register each client ID and secret in advance, which is why the create, record callbackUrl, register, update sequence is required. Figure 5: Configuring the Okta OAuth (3-legged) credential provider vendor in Amazon Bedrock AgentCore Identity Next, the Amazon Bedrock AgentCore Gateway configuration points to the Snowflake-managed MCP server endpoint and references the Okta credential provider for outbound authentication. Figure 6: Amazon Bedrock AgentCore Gateway configuration pointing to the Snowflake-managed MCP server endpoint with Okta 3-legged OAuth as outbound authentication The following sequence diagram shows the runtime authorization flow for the three-legged OAuth pattern with an external IdP. Figure 7: 3LO with external IdP runtime authorization flow: Amazon Bedrock AgentCore Gateway MCP server target with AUTHORIZATION_CODE grant and third-party IdP outbound auth Snowflake’s External OAuth security integration flow works as follows: When a tool call requires a Snowflake token, Amazon Bedrock AgentCore Gateway obtains a workload token by calling GetWorkloadAccessTokenForJWT and calls GetResourceOauth2Token to check the token vault of Amazon Bedrock AgentCore Identity for the user. If no token is cached, the Gateway returns a JSON-RPC error code -32042 carrying a URL elicitation. That authorization URL belongs to AgentCore Identity and is session-URI-bound, not the IdP’s. The client opens that URL in the user’s browser, and AgentCore Identity routes the user to the IdP. The user authenticates through the third-party IdP with corporate SSO (including MFA) and consents to the requested scopes. For Okta, the role scope takes the form session:role:ANALYST_ROLE. Microsoft Entra ID delegated flows use session:scope: instead. The IdP returns an authorization code to the callback URL of Amazon Bedrock AgentCore Identity, and AgentCore Identity redirects the user’s browser to the return URL with the session URI. Only after the application calls CompleteResourceTokenAuth to validate the user identity and session URI does AgentCore Identity exchange the code for an access token (and a refresh token, if the IdP issues one) and cache them in the per-user token vault. When the client retries the tool call (and on later calls), Amazon Bedrock AgentCore Gateway retrieves the cached IdP-issued JWT from Amazon Bedrock AgentCore Identity and presents it to the Snowflake-managed MCP server. Snowflake validates the token through its External OAuth integration: it verifies the JWKS signature and audience (aud) claim, maps the configured user claim (sub for Okta, upn for Microsoft Entra ID) to the Snowflake user, and executes the query as the authenticated user. Snowflake does not call the IdP at runtime. It validates tokens locally using the IdP’s published JWKS signing keys. When the access token expires, Amazon Bedrock AgentCore Identity automatically refreshes it using the cached refresh token, if one was issued (for Okta, request the offline_access scope). No user interaction is required until the refresh token expires. Token lifetime governance: Unlike Pattern 1 where Snowflake controls token lifetimes, access token and refresh token lifetimes are governed by the IdP, and Amazon Bedrock AgentCore Identity handles the refresh transparently. If a refresh token was issued, the user re-authenticates only when it expires, based on the IdP’s session policy. Otherwise, the user re-authenticates when the access token expires. Considerations Choose three-legged OAuth (3LO) with a third-party IdP when: Your organization or security team requires all authentication to flow through corporate SSO for centralized MFA, conditional access, and session management. You want to use existing IdP features such as group-based role mapping, session timeout policies, and geo-based conditional access rules. You need per-user audit trails in Snowflake’s QUERY_HISTORY. You want uniform security policy enforcement across all applications, including AI agents. You need centralized access control. Disabling a user in the IdP helps prevent new Snowflake authorizations, though cached tokens stay valid until they expire. To force a user to re-authorize, the application can pass forceAuthentication=true on the next request, which clears the stored refresh token and starts a new authorization flow. To revoke access outright, revoke the grant at the IdP or in Snowflake. Pattern 3: Two-legged OAuth (2LO) using a third-party Identity Provider (IdP) The two-legged OAuth pattern uses the OAuth 2.0 client_credentials grant. This is a machine-to-machine flow with no user interaction. Amazon Bedrock AgentCore Identity obtains a JWT from the IdP using the configured client ID and client secret, and Amazon Bedrock AgentCore Gateway presents it to Snowflake, which executes the requests under a shared service user, regardless of which end user initiated the query. This pattern is the most operationally direct: no consent screens, no per-user token vaults, no browser redirects. The users follow the same code path. Amazon Bedrock AgentCore Identity fetches and caches the client_credentials token automatically, and the Amazon Bedrock AgentCore Gateway presents it on every outbound call to the Snowflake-managed MCP server. The key difference from Patterns 1 and 2: there is no per-user identity propagation. Snowflake’s QUERY_HISTORY records a single service user for queries. The trade-off is operational simplicity at the cost of per-user audit granularity. On the Amazon Bedrock AgentCore side, the credential provider uses the client_credentials grant type: either a built-in vendor (OktaOauth2, MicrosoftOauth2) or the generic CustomOauth2 provider. Configuration requires the IdP’s token endpoint, client ID, and client secret. Amazon Bedrock AgentCore Identity fetches a token from the IdP on the first tool call (when the Gateway calls GetResourceOauth2Token), caches it, and, because client_credentials issues no refresh token, requests a fresh one before expiry. No agent-level code changes are required. Figure 8: Configuring the client_credentials (2-legged) credential provider vendor in Amazon Bedrock AgentCore Identity Next, the Amazon Bedrock AgentCore Gateway configuration references the Snowflake-managed MCP server endpoint and the two-legged OAuth credential provider for outbound authentication. Figure 9: Amazon Bedrock AgentCore Gateway configuration pointing to the Snowflake-managed MCP server endpoint with 2-legged OAuth (client_credentials) as outbound authentication The following sequence diagram shows the runtime authorization flow for the two-legged OAuth pattern. Figure 10: 2LO with external IdP runtime authorization flow: Amazon Bedrock AgentCore Gateway MCP server target with CLIENT_CREDENTIALS grant and third-party IdP outbound auth Snowflake’s External OAuth security integration 2LO flow works as follows: When a tool call requires a Snowflake token, Amazon Bedrock AgentCore Gateway obtains a workload token by calling GetWorkloadAccessTokenForJWT and calls GetResourceOauth2Token on the Amazon Bedrock AgentCore Identity credential provider. If a valid token is cached, Identity returns it immediately. Amazon Bedrock AgentCore Identity calls the third-party IdP’s token endpoint using the client_credentials grant with the configured client ID and client secret. For Okta, the requested scope includes the Snowflake role (for example, session:role:MCP_GATEWAY_ROLE). For Microsoft Entra ID, the client requests the api:///.default scope and the role arrives in the roles claim from an app role whose value is session:role:MCP_GATEWAY_ROLE. The IdP returns an access token (a JWT, with no refresh token) whose aud claim is the Snowflake account URL or an additional value listed in EXTERNAL_OAUTH_AUDIENCE_LIST (for Microsoft Entra ID, typically the Application ID URI). For Okta, the sub claim is the client ID. For Microsoft Entra ID, the client ID is carried in appid/azp while sub holds the service principal’s object ID (a GUID), so with Entra, LOGIN_NAME must map to that GUID. Amazon Bedrock AgentCore Gateway presents the JWT to the Snowflake-managed MCP server. Snowflake validates the token through its External OAuth integration (optionally issuer-locked with OAUTH_AUTHORIZATION_SERVER, as in Pattern 2). It verifies the signature through EXTERNAL_OAUTH_JWS_KEYS_URL (or EXTERNAL_OAUTH_RSA_PUBLIC_KEY), the issuer through EXTERNAL_OAUTH_ISSUER, and the aud claim against the Snowflake account URL plus any additional values in EXTERNAL_OAUTH_AUDIENCE_LIST (these security integration parameter values are case-sensitive). Snowflake then maps the sub claim to a Snowflake service user through LOGIN_NAME and executes the query under that service user’s role. As in Pattern 2, Snowflake validates the token locally and does not call the IdP at runtime. Amazon Bedrock AgentCore Identity caches the token in the token vault (shared across users, not per user). Subsequent calls reuse it, and Identity requests a new token with the client_credentials grant before it expires. Because the two-legged OAuth target needs no user consent, the Amazon Bedrock AgentCore Gateway connects to the Snowflake-managed MCP server at target-creation time and discovers tools through implicit sync during target creation. In the 3-legged OAuth patterns (Patterns 1 and 2), the Gateway target supports two creation methods: (1) an admin completes the authorization code flow so tools are discovered by implicit sync, or (2) the admin provides the tool schema upfront. (Discovery behavior is a ListingMode property of the target, not a property of the grant type.) Considerations The two-legged OAuth pattern is preferred for automated, unattended, and batch workloads. It is ideal when: Your workload is machine-to-machine: scheduled jobs, background pipelines, or system-level agents with no human in the loop. Per-user identity isn’t required, and a shared service user is acceptable for audit purposes. You need the most direct operational model: no consent flows, per-user token management, or browser redirects. The Gateway can connect to Snowflake and discover MCP tools by implicit sync at target-creation time, without waiting for user interaction. All users share the same data access rights under a single Snowflake role. Accept these trade-offs: Because every request runs as the shared service user, Snowflake’s row-level security and column masking policies apply that user’s permissions to requests. Policies keyed on CURRENT_USER() and CURRENT_ROLE() all resolve to that single service user and its one role, which is the strongest case for the on-behalf-of (OBO) approach. There is no user-level token revocation. To cut off access, revoke the client credentials at the IdP or disable the Snowflake security integration. If credentials are compromised, agent access is affected. Rotate client secrets regularly and restrict the service user to least-privilege access. Pattern comparison ¹ MCP protocol revision: for the three-legged patterns (Patterns 1 and 2), the gateway pins 2025-11-25 in its supported MCP revisions, which the URL-mode elicitation (-32042) handshake requires. The reference 2LO gateway (Pattern 3) does not pin it, because 2LO has no elicitation step. On accounts that are not enabled for MCP version updates, the supported set is fixed when the gateway is created. ² Works unattended: Patterns 1 and 2 run unattended only until the refresh token expires. Re-consent then requires a live browser, the same user, and completion inside the 10-minute authorization window (CompleteResourceTokenAuth), which is why 3LO is unsuitable for fully unattended scheduled jobs. Pattern 3 (2LO) has no refresh token and no consent step, so it runs unattended indefinitely. The three configurations in this post cover two grant types: authorization_code (Patterns 1 and 2) and client_credentials (Pattern 3). Amazon Bedrock AgentCore Identity also supports on-behalf-of (OBO) token exchange (TOKEN_EXCHANGE), which delivers per-user identity for unattended workloads without a consent prompt. OBO exchanges an inbound user token for a Snowflake-scoped token that preserves the real user’s identity, so QUERY_HISTORY attributes each query to the actual user, while keeping the unattended, machine-to-machine flow of Pattern 3 (no browser redirect, no consent screen). On the Snowflake side it uses the same TYPE = EXTERNAL_OAUTH integration as Patterns 2 and 3 (optionally issuer-locked with OAUTH_AUTHORIZATION_SERVER). On the AgentCore side it is configured on the OAuth credential provider through onBehalfOfTokenExchangeConfig (grant mode TOKEN_EXCHANGE for Okta/RFC 8693, or JWT_AUTHORIZATION_GRANT for Microsoft Entra). OBO uses the External OAuth path (Patterns 2 and 3). OBO is generally available on Amazon Bedrock AgentCore Identity, but it was outside the scope of the three configurations we tested for this post. Try it yourself To see these patterns in action, we built a financial-services credit-risk assessment agent as a reference workload. A single agent combines bank policy documents in Amazon S3 (through Amazon Bedrock Knowledge Bases) with customer data in Snowflake. It assesses loan eligibility, searches customer profiles, and queries account and transaction data. The demo exercises three MCP tools (Cortex Search, Cortex Analyst, and SQL Execution) across all three OAuth configurations for side-by-side comparison in your own AWS account. Though the demo is financial services, the patterns work across healthcare, supply chain, insurance, and more. All three implementations are public and deploy end-to-end through a single deploy.sh script: Snowflake OAuth (3LO): amazon-bedrock-agentcore-snowflake-mcp-gateway-3lo. 3LO with external IdP: amazon-bedrock-agentcore-snowflake-mcp-gateway-3lo-okta. 2LO with external IdP: amazon-bedrock-agentcore-snowflake-mcp-gateway. Note: For demonstration purposes, the reference implementations expose SYSTEM_EXECUTE_SQL on the same MCP server as the Cortex Agent. Snowflake recommends exposing a Cortex Agent as the only client-facing tool for governed business questions. If direct SQL is required, place it on a separate MCP server with a dedicated least-privileged role. Conclusion In this post, we walked through three OAuth configurations for authenticating AI agents to Snowflake Cortex AI over MCP through Amazon Bedrock AgentCore Gateway. Snowflake OAuth offers the simplest path to per-user audit trails with no external IdP dependency. Three-legged OAuth with an external IdP adds corporate SSO, centralized MFA, and conditional access while preserving per-user identity. Two-legged OAuth with an external IdP serves machine-to-machine through a shared service user. Across all three patterns, the agent code and the Snowflake MCP tool set stay unchanged. The OAuth wiring differs in four specific ways: The grant type flips: authorization_code for Patterns 1 and 2, client_credentials for Pattern 3. AUTHORIZATION_CODE targets need a return URL, set as defaultReturnUrl on the target and optionally overridden per request. 2LO targets need none. 3LO target creation requires implicit sync or an upfront tool schema, whereas a 2LO target syncs its tools during target creation with no user authorization step. OAUTH_AUTHORIZATION_SERVER can be set for Patterns 2 and 3 to issuer-lock an MCP scope to the external IdP and to let direct MCP clients auto-discover it. It is left unset for Pattern 1. When it is set, Patterns 1 and 2 cannot share one scope, as noted earlier. Beyond these four, only the Amazon Bedrock AgentCore Identity credential provider (CustomOauth2, OktaOauth2, or MicrosoftOauth2) and the Snowflake security integration differ. Understanding these differences in grant type, token issuance, user mapping, and audit behavior equips you to select the right OAuth configuration for your compliance, operational, and user-experience needs. To get started, explore the reference implementation in our GitHub repository. For more on Amazon Bedrock AgentCore, visit the Amazon Bedrock AgentCore service detail page or the Developer Guide. About the authors

자료 출처

원문 읽기 ↗

관련 주제

← 전체 소식 이어 읽기