Support OAuth M2M (client credentials) on the default backend; reject unknown auth_type - #962
Open
aminghadersohi wants to merge 2 commits into
Open
aminghadersohi wants to merge 2 commits into
aminghadersohi wants to merge 2 commits into
Conversation
… unknown auth_type oauth_client_id + oauth_client_secret now authenticate a Databricks service principal with the client-credentials flow against the workspace /oidc/v1/token endpoint (scope all-apis), with tokens refreshed as they expire. Previously the Thrift backend ignored oauth_client_secret and started an interactive browser login with the service principal's client ID, which blocks indefinitely on a server. This matches the credential shape the kernel backend already accepts. An auth_type the connector does not implement now raises ValueError instead of falling through to the interactive login, and a U2M auth_type combined with oauth_client_secret is rejected as ambiguous. The client-credentials token source also ignores extra fields in the token response (the workspace endpoint returns 'scope'), which made OAuthResponse(**payload) raise.
There was a problem hiding this comment.
Copilot review overview
🟡 Changes recommended
Reject the ambiguous combination of credentials_provider and oauth_client_secret, and update the OAuth parameter documentation.
Review effort: Lite
Findings: 1
Open (1)
What changed in this PR
Adds OAuth M2M client-credentials authentication for the default Thrift backend and rejects invalid or ambiguous authentication settings.
Changes:
- Adds service-principal token acquisition and refresh.
- Supports
oauth_client_idandoauth_client_secret. - Validates unsupported authentication types and OAuth response fields.
- Adds authentication tests.
| File | Description |
|---|---|
tests/unit/test_auth.py |
Tests M2M authentication and validation. |
src/databricks/sql/client.py |
Documents OAuth configuration. |
src/databricks/sql/auth/oauth.py |
Handles extra token-response fields. |
src/databricks/sql/auth/common.py |
Stores the OAuth client secret. |
src/databricks/sql/auth/authenticators.py |
Implements service-principal authentication. |
src/databricks/sql/auth/auth.py |
Routes M2M credentials and validates auth types. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
…tions - credentials_provider together with oauth_client_secret now raises ValueError instead of silently using the provider, matching the kernel auth bridge. azure-sp-m2m keeps ignoring oauth_* values. - The missing-oauth_client_id check no longer fires for azure-sp-m2m. - oauth_redirect_port is documented as U2M-only; oauth_client_id and oauth_client_secret docs describe the M2M shape and its exclusions. - CONNECTION_PARAMETERS.md: oauth_client_secret is supported on Thrift. - Add changelog entries. Signed-off-by: Amin Ghadersohi <amin.ghadersohi@gmail.com>
This branch has not been deployed
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.

What type of PR is this?
Description
Changes:
oauth_client_id+oauth_client_secretnow authenticate a Databricks service principal on the default (Thrift) backend with OAuth M2M (client credentials againsthttps://<host>/oidc/v1/token, scopeall-apis). Tokens are refreshed when they expire. This is the credential shape the kernel backend (use_kernel=True) already accepts.auth_typethe connector does not implement now raisesValueError. Before, it fell through to the interactive browser login.oauth_client_secretwithauth_type="databricks-oauth"/"azure-oauth", andoauth_client_secretwith a customcredentials_provider.auth_type="azure-sp-m2m"keeps ignoringoauth_*values.ClientCredentialsTokenSourceignores unknown fields in the token response. The workspace endpoint returnsscope, andOAuthResponse(**payload)raisedTypeErroron it.connect()docstring and CONNECTION_PARAMETERS.md describeoauth_client_secreton Thrift, andoauth_redirect_portis documented as U2M-only. Changelog entries under# Unreleased.Why: on the Thrift backend
oauth_client_secretwas silently ignored.oauth_client_idwas then used as the client of an interactive U2M login: the connector opened a listener on 127.0.0.1:8020 and blocked until a browser redirect arrived. On a server that redirect never comes, so the process hangs. A mistypedauth_typehung the same way. For Databricks-managed service principals, the only M2M option was acredentials_providercallable, which applications that configure the connector from JSON or connection strings cannot pass.How is this tested?
Unit tests
E2E Tests
Manually
N/A
Unit:
tests/unit/test_auth.pycovers the M2M request/header, the M2M argument errors (includingcredentials_provider+oauth_client_secret), and an unknownauth_typewith no interactive fallback. The first three fail onmain. At the first committests/unitpassed (530 passed, 237 skipped;test_parameters.pyexcluded because it fails to collect in the local environment with and without this change). The follow-up commit (ambiguity check, docs) was not run locally; CI covers it.Live, against a Databricks SQL warehouse on AWS with a service principal (scope
all-apis, CAN USE on the warehouse):connect(oauth_client_id=..., oauth_client_secret=...)runs queries, andcurrent_user()is the service principal.RequestError ... 401 invalid_client.auth_type="oauth-u2m"raisesValueErrorand opens no listener.OAuthResponsefix, the live connect failed withOAuthResponse.__init__() got an unexpected keyword argument 'scope'.Related Tickets & Documents
None.