Skip to content

Commit 6a78cef

Browse files
cathleenyIsaac
andcommitted
fix(kernel): black formatting and OAuth guard follows the auth bridge
Wraps the origin-guard condition to the repo's black line length (check-linting). The guard no longer treats a custom credentials_provider as OAuth: the kernel auth bridge rejects that provider with NotSupportedError, so no OAuth origin is involved. Co-authored-by: Isaac <no-reply@databricks.com> Signed-off-by: Cathleen Yan <58714163+cathleeny@users.noreply.github.com>
1 parent 5bb846e commit 6a78cef

2 files changed

Lines changed: 13 additions & 3 deletions

File tree

‎src/databricks/sql/session.py‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -151,18 +151,20 @@ def _check_oauth_origin(server_hostname: str, kernel_host: str, kwargs: dict) ->
151151
kwargs.get("auth_type") in _OAUTH_AUTH_TYPES
152152
or kwargs.get("oauth_jwt_key_file")
153153
or (kwargs.get("oauth_client_id") and kwargs.get("oauth_client_secret"))
154-
or kwargs.get("credentials_provider") is not None
155154
)
156155
# The kernel auth bridge routes an access_token with no JWT or client-secret
157156
# M2M credentials to PAT, even for auth_type='databricks-oauth'; azure-sp-m2m
158-
# is resolved before that branch and stays OAuth.
157+
# is resolved before that branch and stays OAuth. A custom credentials_provider
158+
# is rejected by the bridge, so it is not an OAuth origin here.
159159
routed_to_pat = (
160160
bool(kwargs.get("access_token"))
161161
and kwargs.get("auth_type") != "azure-sp-m2m"
162162
and not kwargs.get("oauth_jwt_key_file")
163163
and not (kwargs.get("oauth_client_id") and kwargs.get("oauth_client_secret"))
164164
)
165-
if routed_to_pat or not (kwargs.get("_connection_uri") and server_hostname and oauth):
165+
if routed_to_pat or not (
166+
kwargs.get("_connection_uri") and server_hostname and oauth
167+
):
166168
return
167169
_, name, port = _split_host(server_hostname)
168170
uri = urlsplit(kernel_host)

‎tests/unit/test_session.py‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1337,6 +1337,14 @@ def test_kernel_host_and_path_rejects(server, kwargs, message):
13371337
"https://evil.io/sql/x",
13381338
True,
13391339
),
1340+
# The kernel auth bridge rejects a custom credentials_provider with NotSupportedError,
1341+
# so the origin guard does not classify it as OAuth.
1342+
(
1343+
"h.io",
1344+
{"credentials_provider": object()},
1345+
"https://evil.io/sql/x",
1346+
False,
1347+
),
13401348
(
13411349
"h.io",
13421350
{"oauth_jwt_key_file": "/k.pem", "access_token": "dapi"},

0 commit comments

Comments
 (0)