Repository navigation
feat(kernel): route Azure Entra auth (azure-sp-m2m + azure-oauth) through the auth bridge - #919
Merged
Merged
Conversation
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
Teaches the
use_kernel=Trueauth bridge to route both Azure Entra auth flows to the kernel (databricks/databricks-sql-kernel#263):auth_type="azure-sp-m2m") — forward the SP credentials to the kernel, which owns Azure resolution.auth_type="azure-oauth") — route to the kernel's OAuth U2M flow, identically todatabricks-oauth.How
src/databricks/sql/backend/kernel/auth_bridge.py:azure-sp-m2m→ kernelazure-sp-m2m— forwardazure_client_id/azure_client_secret(+ optionalazure_tenant_id,azure_workspace_resource_id). The kernel builds the Entra v2.0 token endpoint and the{effective_app_id}/.defaultscope, and auto-discovers the tenant from the workspace's/aad/authredirect whenazure_tenant_idis omitted (Thrift parity). TheAuthorizationbearer (data token) alone authenticates a workspace-member SP; whenazure_workspace_resource_idis set, the kernel also sends the Azure SP management token (X-Databricks-Azure-SP-Management-Token) +X-Databricks-Azure-Workspace-Resource-Idheader (matching the JDBC driver), so an SP with an Azure RBAC role but no workspace membership authenticates. PECOBLR-4141.azure-oauth→ kerneloauth-u2m— routed through the shared U2M branch, exactly likedatabricks-oauth. The kernel runs the in-house workspace-federated browser flow, which Azure Databricks workspaces support (the workspace federates login to Entra). It forwards the connector'sdatabricks-sql-pythonapp bundle, not Thrift's Azure app (96eecda7/ redirect port8030): that app is registered for Thrift's direct-Entra flow (login.microsoftonline.comconfig +{tenant}/user_impersonationscopes), which the kernel does not perform. So on the kernel pathazure-oauthanddatabricks-oauthare the same flow. The U2M-vs-M2M ambiguity guard now also coversazure-oauth, soazure-oauth+oauth_client_secretis rejected as ambiguous rather than silently falling through to M2M. PECOBLR-4120.src/databricks/sql/session.pythreads theazure_*connection kwargs intokernel_auth_options(the kernel owns Azure resolution, so these raw kwargs are the only source).The binding is thin — it does not construct endpoints or scopes; the kernel does.
Tests
TestKernelAzureSpM2M: forwards creds; tenant optional (kernel auto-discovers);azure_workspace_resource_idforwarded; required-creds error; federation client id.TestKernelOAuthU2M:azure-oauthmaps tooauth-u2mwith thedatabricks-sql-pythonbundle (identical todatabricks-oauth); customclient_id/port/scopes honored; the ambiguity guard (U2M auth_type+oauth_client_secret) is parametrized over bothdatabricks-oauthandazure-oauth.azure_*kwargs reachauth_options.Bridge + session + auth unit tests pass;
blackclean. (test_kernel_client.pyskips without the kernel wheel, as before.)E2E verification (live Azure workspace)
Ran the full connector path (
sql.connect(use_kernel=True, ...)) against a live Azure Databricks workspace, kernel wheel built from databricks/databricks-sql-kernel#263. All three Azure kernel-path flows round-tripSELECT 1:auth_type="azure-oauth") — full interactive browser authorization-code flow (cache cleared to force it). Log confirms the design: authorize URL is the workspace's own OIDC endpoint ({host}/oidc/v1/authorize),client_id=databricks-sql-python,redirect_uri=http://localhost:8020,scope=sql offline_access— i.e. the in-house workspace-federated flow, not Thrift's direct-Entra app (96eecda7/ port 8030 /user_impersonation). Authenticated interactively and returnedSELECT 1. ✅auth_type="azure-sp-m2m", noazure_workspace_resource_id) — workspace-member SP,Row(one=1, who='<sp-app-id>'). ✅azure-sp-m2m+azure_workspace_resource_id) — the kernel mints the ARM management token via the Entra v1.0resource=grant (audhttps://management.core.windows.net/, trailing slash) and sends theX-Databricks-Azure-SP-Management-Token+-Workspace-Resource-Idheader pair; round-trip succeeds. ✅Negative controls confirm the pipeline is real, not a no-op: a mismatched SP secret surfaces Entra
AADSTS7000215, and a service principal with no workspace access returnsHTTP 403 User not authorized(a real control-plane authz decision, not a bridge error).Note: this required a kernel wheel with the
azure-sp-m2mpyo3 surface — the currently-publisheddatabricks-sql-kernel0.2.0 wheel lacks it (Session.__new__() got an unexpected keyword argument 'azure_client_id'), so merging this depends on a kernel release that includes #263. (Azure U2M works on the old wheel —oauth-u2mpredates it.) Not yet covered: the RBAC-only authorization case (a non-member SP authorized purely by an Azure role via the management token), which needs an Azure role assignment still pending.Related
This pull request and its description were written by Isaac.