Repository navigation
Support Workload Identity Federation in Snowflake REST API authentication - #75810
Merged
Merged
Conversation
omar-massfih
marked this pull request as ready for review
October 27, 2026 17:58
omar-massfih
force-pushed
the
snowflake-rest-wif
branch
from
October 27, 2026 17:59
7e1cc2d to
1dc4fba
Compare
kaxil
reviewed
Oct 27, 2026
kaxil
reviewed
Oct 28, 2026
kaxil
reviewed
Nov 1, 2026
kaxil
approved these changes
Nov 1, 2026
kaxil
enabled auto-merge (squash)
November 4, 2026 12:06
kaxil
reviewed
Nov 4, 2026
auto-merge was automatically disabled
November 4, 2026 18:35
Head branch was pushed to by a user without write access
kaxil
approved these changes
Nov 4, 2026
kaxil
enabled auto-merge (squash)
November 4, 2026 21:11
…tion SnowflakeSqlApiHook, SnowflakeCortexAgentHook and the pydanticai_snowflake connection type rejected connections that use Workload Identity Federation, even though SnowflakeHook supports them. Authenticate those REST calls with the workload's cloud identity token, sent as `Bearer WIF.<provider>.<token>` with the WORKLOAD_IDENTITY_FEDERATION token type, and cache it until shortly before it expires. A connection that also sets a private key still uses key-pair authentication. closes: apache#75808
…ibraries Do not call snowflake.connector.wif_util, which is not a documented API of the connector. Request the identity token directly: sts:GetWebIdentityToken through boto3 for AWS, azure-identity for Azure (AKS workload identity or the managed identity), google-auth for GCP, and the connection's token or token_file_path for OIDC. Each library is imported only for the provider the connection names, so none becomes a dependency of the provider. This also drops the snowflake-connector-python>=4.7.1 requirement for AWS.
WIF connections must report incorrect authenticator settings clearly, and credential selection and tests must reflect the authentication path actually used by the REST hooks. Generated-by: OpenAI Codex
…ooks Ask STS for a 3600 s GetWebIdentityToken lifetime instead of the 300 s default, so the deferred SQL API trigger refreshes the token on its event loop about once an hour rather than every few minutes. List WIF in the SnowflakeCortexAgentHook and SnowflakeSqlApiHook docstrings, name GetWebIdentityToken in the global-endpoint note, and test a lowercase authenticator value.
kaxil
force-pushed
the
snowflake-rest-wif
branch
from
November 4, 2026 21:17
cc801ed to
ffd0b4d
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The problem
SnowflakeSqlApiOperatorcan't be used with Workload Identity Federation (WIF). If a Snowflake connection is set up for WIF (authenticator=WORKLOAD_IDENTITY), the SQL API hook fails with:SnowflakeHookalready supports WIF (#68107), and the connection docs say the same connection works for the SQL API hook, so the two disagreed. The same limit applied to the Cortex Agent hook and thepydanticai_snowflakeconnection type, because they share the same authentication code.Snowflake's REST API supports WIF: you send the cloud identity token as
Authorization: Bearer WIF.<provider>.<token>, together with the headerX-Snowflake-Authorization-Token-Type: WORKLOAD_IDENTITY_FEDERATION(Snowflake docs).closes: #75808
What this changes
A WIF connection now works for these hooks. The fix is one new branch in
SnowflakeRestTokenProvider(utils/_rest_auth.py), which all the REST hooks use.How the token is obtained. The provider asks the cloud for an identity token using that cloud's own library:
AWSboto3sts:GetWebIdentityTokenAZUREazure-identityMANAGED_IDENTITY_CLIENT_IDpicks a user-assigned one)GCPgoogle-authOIDCtokenortoken_file_pathNo new dependencies. Each library is imported only when a connection uses that cloud. If it's missing, the error names the package to install.
Existing behaviour is unchanged. The order is still OAuth, then PAT, then key-pair. A connection that has a private key keeps using key-pair, even if WIF is also configured. WIF is only used when nothing else applies.
Tokens are cached. The SQL API operator checks its status repeatedly, so the token is reused until 30 seconds before it expires, instead of calling the cloud every time.
Docs. The connection page now says what each provider needs installed.
Worth a look
boto3,azure-identityandgoogle-authbe added as optional extras?workload_identity_entra_resourceandworkload_identity_impersonation_patharen't passed through bySnowflakeHooktoday, so they aren't supported here either.How it was tested
Unit tests cover each cloud's token helper (with fake cloud libraries), OIDC from a token or a file, caching and refresh near expiry, missing libraries, and that key-pair still wins. They also check the headers from
SnowflakeSqlApiHook.get_headers()and a Cortex Agent request. 171 tests pass, andruffandmypyare clean on the changed code.Live test on Azure: an Azure Container Apps job, running this branch with a managed identity and no stored secret, ran a query through
SnowflakeSqlApiHookagainst a real Snowflake account. The token came fromazure-identity, the SQL API acceptedBearer WIF.AZURE.<token>, andselect current_user(), current_role()finished successfully.Not yet tested live: AKS workload identity, AWS, GCP and OIDC (unit tests only).
Two notes on the setup: I ran the tests in a scratch environment because the repo needs a newer
uvthan mine, and I skipped themypy-devel-commonpre-commit hook, which can't run on thatuv; CI will cover it.Was generative AI tooling used to co-author this PR?
Generated-by: Claude Code (Claude Sonnet 5.5) following the guidelines