This is an automated email from the ASF dual-hosted git repository.

kaxil pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/airflow.git


The following commit(s) were added to refs/heads/main by this push:
     new dfb8bbd90f7 Expose the Snowflake authenticator as a connection form 
field (#77565)
dfb8bbd90f7 is described below

commit dfb8bbd90f7d7593d765b90796e5a5be5103b2e7
Author: Mattias P <[email protected]>
AuthorDate: Wed Nov 25 22:39:04 2026 +0100

    Expose the Snowflake authenticator as a connection form field (#77565)
    
    The authenticator was only settable through the Extra JSON, even though 
Workload Identity Federation and PAT authentication require it. It now has its 
own field in the Snowflake connection form, listing the supported values, and 
is removed from the Extra placeholder.
    
    A blank form field is stored as an empty string, so the hook now falls back 
to the default snowflake authenticator for it instead of passing the empty 
value to the connector. The backcompat extra__snowflake__ prefix is honored for 
authenticator as for the other fields.
    
    * Normalise the Snowflake authenticator and point docs at its form field
    
    A free-text Authenticator field makes values like OAUTH or a trailing space 
easy to enter. The connector accepts any case, but the hooks compare oauth and 
programmatic_access_token exactly, so such values silently skipped the OAuth 
and PAT setup.
    
    On Airflow 2, the connection form drops an Extra JSON key when the custom 
field of the same name is left blank, so an authenticator set in Extra as the 
docs described would be lost on save.
---
 .../docs/connections/pydantic_ai_snowflake.rst     |  2 +-
 providers/snowflake/docs/connections/snowflake.rst |  6 +++--
 .../snowflake/docs/operators/cortex_agent.rst      |  2 +-
 providers/snowflake/provider.yaml                  |  8 ++++++-
 .../providers/snowflake/get_provider_info.py       |  4 +++-
 .../airflow/providers/snowflake/hooks/snowflake.py | 11 ++++++---
 .../tests/unit/snowflake/hooks/test_snowflake.py   | 27 ++++++++++++++++++++++
 7 files changed, 51 insertions(+), 9 deletions(-)

diff --git a/providers/snowflake/docs/connections/pydantic_ai_snowflake.rst 
b/providers/snowflake/docs/connections/pydantic_ai_snowflake.rst
index 8d51b94baf3..6bbad26bdac 100644
--- a/providers/snowflake/docs/connections/pydantic_ai_snowflake.rst
+++ b/providers/snowflake/docs/connections/pydantic_ai_snowflake.rst
@@ -75,7 +75,7 @@ Credentials are not configured on this connection -- they 
come from whichever au
 method the referenced Snowflake connection uses, set the same way as for
 :ref:`SnowflakeSqlApiHook and SnowflakeCortexAgentHook 
<howto/connection:snowflake>`:
 
-- **OAuth**: set ``authenticator`` to ``oauth`` in the Snowflake connection's 
extra, and configure
+- **OAuth**: set the Snowflake connection's **Authenticator** field to 
``oauth``, and configure
   a refresh token, a client credentials grant, or ``azure_conn_id``.
 - **PAT (Programmatic Access Token)**: set ``authenticator`` to 
``programmatic_access_token`` and
   put the PAT value in the Snowflake connection's Password field.
diff --git a/providers/snowflake/docs/connections/snowflake.rst 
b/providers/snowflake/docs/connections/snowflake.rst
index 79d2b796e1c..4532030b353 100644
--- a/providers/snowflake/docs/connections/snowflake.rst
+++ b/providers/snowflake/docs/connections/snowflake.rst
@@ -44,7 +44,7 @@ Login
 Password
     Specify the snowflake password. For public key authentication, the 
passphrase for the private key.
     For OAuth, the OAuth Client Secret. For Programmatic Access Token (PAT) 
authentication, specify
-    the PAT token value and set ``authenticator`` to 
``programmatic_access_token``.
+    the PAT token value and set the **Authenticator** field to 
``programmatic_access_token``.
 
 Schema (optional)
     Specify the snowflake schema to be used.
@@ -58,7 +58,9 @@ Extra (optional)
     * ``region``: Warehouse region.
     * ``warehouse``: Snowflake warehouse name.
     * ``role``: Snowflake role.
-    * ``authenticator``: To connect using OAuth set this parameter ``oauth``. 
To connect without a stored secret using
+    * ``authenticator``: Set this in the **Authenticator** field of the 
connection form. In the Airflow 2 UI,
+      leaving that field blank removes an ``authenticator`` key typed into the 
Extra JSON when the connection
+      is saved. To connect using OAuth set this parameter ``oauth``. To 
connect without a stored secret using
       `Workload Identity Federation 
<https://docs.snowflake.com/en/user-guide/workload-identity-federation>`_,
       set it to ``WORKLOAD_IDENTITY`` and also set 
``workload_identity_provider`` (see below). For Programmatic Access
       Token (PAT) authentication, set it to ``programmatic_access_token`` and 
put the PAT token in the
diff --git a/providers/snowflake/docs/operators/cortex_agent.rst 
b/providers/snowflake/docs/operators/cortex_agent.rst
index cb2ae03b74a..6b97ecd426e 100644
--- a/providers/snowflake/docs/operators/cortex_agent.rst
+++ b/providers/snowflake/docs/operators/cortex_agent.rst
@@ -45,7 +45,7 @@ Authentication
 ^^^^^^^^^^^^^^
 
 ``SnowflakeCortexAgentHook`` (and the operator built on it) authenticate 
according to the connection's
-``authenticator`` extra:
+**Authenticator** field (``authenticator``):
 
 - **OAuth**: set ``authenticator`` to ``oauth`` and configure a refresh token, 
a client
   credentials grant, or ``azure_conn_id``, as on the Snowflake connection 
generally.
diff --git a/providers/snowflake/provider.yaml 
b/providers/snowflake/provider.yaml
index bc2faaa4526..5613e961e18 100644
--- a/providers/snowflake/provider.yaml
+++ b/providers/snowflake/provider.yaml
@@ -189,7 +189,6 @@ connection-types:
       placeholders:
         extra: |
           {
-            "authenticator": "snowflake oauth / WORKLOAD_IDENTITY",
             "private_key_file": "private key",
             "session_parameters": "session parameters",
             "client_request_mfa_token": "client request mfa token",
@@ -213,6 +212,7 @@ connection-types:
         database: snowflake db name
         region: snowflake hosted region
         role: snowflake role
+        authenticator: snowflake (default), oauth, programmatic_access_token, 
WORKLOAD_IDENTITY
         private_key_file: Path of snowflake private key (PEM Format)
         private_key_content: Content to snowflake private key (PEM format)
         workload_identity_provider: AWS, AZURE, GCP or OIDC
@@ -252,6 +252,12 @@ connection-types:
           type:
             - string
             - 'null'
+      authenticator:
+        label: Authenticator
+        schema:
+          type:
+            - string
+            - 'null'
       private_key_file:
         label: Private key (Path)
         schema:
diff --git 
a/providers/snowflake/src/airflow/providers/snowflake/get_provider_info.py 
b/providers/snowflake/src/airflow/providers/snowflake/get_provider_info.py
index bc8edf6ef53..8d8e5399c1c 100644
--- a/providers/snowflake/src/airflow/providers/snowflake/get_provider_info.py
+++ b/providers/snowflake/src/airflow/providers/snowflake/get_provider_info.py
@@ -113,7 +113,7 @@ def get_provider_info():
                     "hidden-fields": ["port", "host"],
                     "relabeling": {},
                     "placeholders": {
-                        "extra": '{\n  "authenticator": "snowflake oauth / 
WORKLOAD_IDENTITY",\n  "private_key_file": "private key",\n  
"session_parameters": "session parameters",\n  "client_request_mfa_token": 
"client request mfa token",\n  "client_store_temporary_credential": "client 
store temporary credential (externalbrowser mode)",\n  "grant_type": 
"refresh_token client_credentials",\n  "token_endpoint": "token endpoint",\n  
"refresh_token": "refresh token",\n  "scope": "scope",\n   [...]
+                        "extra": '{\n  "private_key_file": "private key",\n  
"session_parameters": "session parameters",\n  "client_request_mfa_token": 
"client request mfa token",\n  "client_store_temporary_credential": "client 
store temporary credential (externalbrowser mode)",\n  "grant_type": 
"refresh_token client_credentials",\n  "token_endpoint": "token endpoint",\n  
"refresh_token": "refresh token",\n  "scope": "scope",\n  "oauth_username": 
"IdP resource owner user name (password g [...]
                         "schema": "snowflake schema",
                         "login": "snowflake username",
                         "password": "snowflake password",
@@ -122,6 +122,7 @@ def get_provider_info():
                         "database": "snowflake db name",
                         "region": "snowflake hosted region",
                         "role": "snowflake role",
+                        "authenticator": "snowflake (default), oauth, 
programmatic_access_token, WORKLOAD_IDENTITY",
                         "private_key_file": "Path of snowflake private key 
(PEM Format)",
                         "private_key_content": "Content to snowflake private 
key (PEM format)",
                         "workload_identity_provider": "AWS, AZURE, GCP or 
OIDC",
@@ -138,6 +139,7 @@ def get_provider_info():
                     "database": {"label": "Database", "schema": {"type": 
["string", "null"]}},
                     "region": {"label": "Region", "schema": {"type": 
["string", "null"]}},
                     "role": {"label": "Role", "schema": {"type": ["string", 
"null"]}},
+                    "authenticator": {"label": "Authenticator", "schema": 
{"type": ["string", "null"]}},
                     "private_key_file": {
                         "label": "Private key (Path)",
                         "schema": {"type": ["string", "null"]},
diff --git 
a/providers/snowflake/src/airflow/providers/snowflake/hooks/snowflake.py 
b/providers/snowflake/src/airflow/providers/snowflake/hooks/snowflake.py
index 65249842203..43c9e9a54c9 100644
--- a/providers/snowflake/src/airflow/providers/snowflake/hooks/snowflake.py
+++ b/providers/snowflake/src/airflow/providers/snowflake/hooks/snowflake.py
@@ -53,6 +53,8 @@ from airflow.utils.strings import to_boolean
 OAUTH_REQUEST_TIMEOUT = 30  # seconds, avoid hanging tasks on token request
 OAUTH_EXPIRY_BUFFER = 30
 SUPPORTED_GRANT_TYPES = {"refresh_token", "client_credentials", "password"}
+# The connector matches authenticator names case-insensitively, but the hooks 
compare these exactly.
+LOWERCASE_AUTHENTICATORS = {"oauth", "programmatic_access_token"}
 LOGOUT_AUTO_DETECTION_PARAM = "enable_server_session_keep_alive_auto_detection"
 # Logout behaviour of connectors before 5.0: keep the server session while 
async queries
 # started on the connection are still running. Connector 5 plans to change its 
default.
@@ -303,6 +305,7 @@ class SnowflakeHook(DbApiHook):
             "database": StringField(lazy_gettext("Database"), 
widget=BS3TextFieldWidget()),
             "region": StringField(lazy_gettext("Region"), 
widget=BS3TextFieldWidget()),
             "role": StringField(lazy_gettext("Role"), 
widget=BS3TextFieldWidget()),
+            "authenticator": StringField(lazy_gettext("Authenticator"), 
widget=BS3TextFieldWidget()),
             "private_key_file": StringField(lazy_gettext("Private key 
(Path)"), widget=BS3TextFieldWidget()),
             "private_key_content": PasswordField(
                 lazy_gettext("Private key (Text)"), 
widget=BS3PasswordFieldWidget()
@@ -340,7 +343,6 @@ class SnowflakeHook(DbApiHook):
             "placeholders": {
                 "extra": json.dumps(
                     {
-                        "authenticator": "snowflake oauth / WORKLOAD_IDENTITY",
                         "private_key_file": "private key",
                         "session_parameters": "session parameters",
                         "client_request_mfa_token": "client request mfa token",
@@ -366,6 +368,7 @@ class SnowflakeHook(DbApiHook):
                 "database": "snowflake db name",
                 "region": "snowflake hosted region",
                 "role": "snowflake role",
+                "authenticator": "snowflake (default), oauth, 
programmatic_access_token, WORKLOAD_IDENTITY",
                 "private_key_file": "Path of snowflake private key (PEM 
Format)",
                 "private_key_content": "Content to snowflake private key (PEM 
format)",
                 "workload_identity_provider": "AWS, AZURE, GCP or OIDC",
@@ -529,8 +532,10 @@ class SnowflakeHook(DbApiHook):
 
         schema = conn.schema or ""
 
-        # authenticator and session_parameters never supported long name
-        authenticator = extra_dict.get("authenticator", "snowflake")
+        authenticator = (self._get_field(extra_dict, "authenticator") or 
"").strip() or "snowflake"
+        if authenticator.lower() in LOWERCASE_AUTHENTICATORS:
+            authenticator = authenticator.lower()
+        # session_parameters never supported long name
         session_parameters = extra_dict.get("session_parameters")
 
         return {
diff --git a/providers/snowflake/tests/unit/snowflake/hooks/test_snowflake.py 
b/providers/snowflake/tests/unit/snowflake/hooks/test_snowflake.py
index 7c1fc8e5e17..1064c1de7f4 100644
--- a/providers/snowflake/tests/unit/snowflake/hooks/test_snowflake.py
+++ b/providers/snowflake/tests/unit/snowflake/hooks/test_snowflake.py
@@ -2261,6 +2261,33 @@ class TestPytestSnowflakeHook:
 
         assert "workload_identity_provider" in widgets
 
+    @pytest.mark.parametrize(
+        ("extra", "expected"),
+        [
+            pytest.param({"authenticator": ""}, "snowflake", 
id="blank-form-field-uses-default"),
+            pytest.param(
+                {"extra__snowflake__authenticator": 
"programmatic_access_token"},
+                "programmatic_access_token",
+                id="backcompat-prefix",
+            ),
+            pytest.param({"authenticator": "OAUTH"}, "oauth", 
id="oauth-uppercase"),
+            pytest.param(
+                {"authenticator": " Programmatic_Access_Token "},
+                "programmatic_access_token",
+                id="pat-mixed-case-whitespace",
+            ),
+            pytest.param({"authenticator": "   "}, "snowflake", 
id="whitespace-uses-default"),
+        ],
+    )
+    def test_get_conn_params_authenticator_from_extra(self, extra, expected):
+        connection_kwargs = deepcopy(BASE_CONNECTION_KWARGS)
+        connection_kwargs["extra"].update(extra)
+
+        with mock.patch.dict("os.environ", 
AIRFLOW_CONN_TEST_CONN=Connection(**connection_kwargs).get_uri()):
+            conn_params = 
SnowflakeHook(snowflake_conn_id="test_conn")._get_static_conn_params
+
+        assert conn_params["authenticator"] == expected
+
     @pytest.mark.parametrize(
         ("field", "value"),
         [("token", "an-oidc-jwt"), ("token_file_path", 
"/var/run/secrets/oidc/token")],

Reply via email to