Repository navigation
feat(auth): kernel-owned Azure service-principal M2M (azure-sp-m2m) (PECOBLR-4141) #263
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
eric-wang-1990
merged 50 commits into
main
from
eric-wang/azure-service-principal-design
Aug 21, 2026
Merged
Changes from all commits
Commits
Show all changes
50 commits
Select commit
Hold shift + click to select a range
d41d806
docs: design for Azure Entra ID service-principal (M2M) auth (PECOBLR…
eric-wang-1990 dda8553
docs: correct azure-oauth scope boundary and selector name
eric-wang-1990 0469a6e
docs: rework Azure auth design to generic-override approach
eric-wang-1990 01fa559
docs: answer PR #263 review threads in the reworked design
eric-wang-1990 3a509e0
feat(auth): drive Azure Entra OAuth via generic overrides across bind…
eric-wang-1990 8d99e8c
refactor(c-abi): unify OAuth scopes into one shared set_oauth_scopes
eric-wang-1990 341ce09
ai: apply changes for #263 (1 review thread)
86d1a5c
docs: pivot Azure design to kernel-as-auth-core (bindings thin)
eric-wang-1990 cb2bf20
ai: apply changes for #263 (1 review thread)
197e2ce
feat(auth): kernel-owned Azure U2M (azure-oauth) — LIVE VERIFIED
eric-wang-1990 33b9833
docs: mark azure-oauth U2M as kernel-owned + live-verified
eric-wang-1990 389bed6
ai: apply changes for #263 (1 review thread)
b29a2a1
ai: apply changes for #263 (1 review thread)
0ee99c7
feat(auth): kernel-owned Azure SP M2M (azure-sp-m2m) with optional ma…
eric-wang-1990 7c647ec
ai: apply changes for #263 (2 review threads)
ff4a10c
ai: apply changes for #263 (1 review thread)
09b5aed
docs: mark azure-sp-m2m as kernel-owned + live-verified (PECOBLR-4141)
eric-wang-1990 5861975
Merge remote-tracking branch 'origin/main' into eric-wang/azure-servi…
eric-wang-1990 8c69c30
ai: apply changes for #263 (1 review thread)
f117741
ai: apply changes for #263 (1 review thread)
2ff22bc
ai: apply changes for #263 (1 review thread)
98a8b27
ai: apply changes for #263 (1 review thread)
f8dc333
ai: apply changes for #263 (3 review threads)
af1d6d1
ai: apply changes for #263 (1 review thread)
dfd629f
refactor(auth): simplify azure — drop SP management token, derive U2M…
eric-wang-1990 1e0bfd8
test(e2e): add live azure-sp-m2m round-trip test
eric-wang-1990 cfce443
Merge remote-tracking branch 'origin/main' into eric-wang/azure-servi…
eric-wang-1990 d3f910b
refactor(auth): drop azure-oauth (U2M); keep only azure-sp-m2m
eric-wang-1990 f6bdac3
ai: apply changes for #263 (3 review threads)
abd730e
ai: apply changes for #263 (2 review threads)
f362ee4
ai: apply changes for #263 (1 review thread)
5a8334c
ai: apply changes for #263 (1 review thread)
f9d2bfd
refactor(auth): drop azure-sp-m2m sovereign-host rejection
eric-wang-1990 bbc5a51
ai: apply changes for #263 (1 review thread)
f52a47f
feat(auth): azure-sp-m2m sends the Azure SP management token (complet…
eric-wang-1990 f9194a1
ai: apply changes for #263 (1 review thread)
6f52ae3
ai: apply changes for #263 (3 review threads)
b0e36f8
ai: apply changes for #263 (1 review thread)
c3e93af
ai: apply changes for #263 (1 review thread)
829897c
ai: apply changes for #263 (1 review thread)
8e053f8
ai: apply changes for #263 (1 review thread)
0f45652
ai: apply changes for #263 (2 review threads)
11c4fbd
ai: apply changes for #263 (1 review thread)
c16ca0a
ai: apply changes for #263 (1 review thread)
f430b70
refactor(auth): revert u2m.rs to main — azure-sp-m2m is M2M-only
eric-wang-1990 7b441a8
ai: apply changes for #263 (1 review thread)
22908e5
ai: apply changes for #263 (2 review threads)
132975d
refactor(auth): drop azure-sp-m2m sovereign-host rejection (again)
eric-wang-1990 d963da6
fix(auth): mint Azure SP management token via v1.0 resource grant
eric-wang-1990 ad78a5b
Merge remote-tracking branch 'origin/main' into eric-wang/azure-servi…
eric-wang-1990 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
200 changes: 200 additions & 0 deletions
200
docs/designs/PECOBLR-4141-azure-service-principal-design.md
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,200 @@ | ||
| <!-- | ||
| Copyright (c) 2026 Databricks, Inc. | ||
|
|
||
| Licensed under the Apache License, Version 2.0 (the "License"); | ||
| you may not use this file except in compliance with the License. | ||
| You may obtain a copy of the License at | ||
|
|
||
| http://www.apache.org/licenses/LICENSE-2.0 | ||
|
|
||
| Unless required by applicable law or agreed to in writing, software | ||
| distributed under the License is distributed on an "AS IS" BASIS, | ||
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| See the License for the specific language governing permissions and | ||
| limitations under the License. | ||
| --> | ||
|
|
||
| # Azure Entra ID OAuth — kernel as the Azure-aware auth core (PECOBLR-4141 / 4120) | ||
|
|
||
| > **Scope of this PR (shipped vs. planned).** This PR ships **only** the M2M | ||
| > path — `AuthConfig::AzureServicePrincipal` (`azure-sp-m2m`), its provider in | ||
| > `src/auth/oauth/azure.rs`, and the pyo3 `auth_type="azure-sp-m2m"` selector. | ||
| > Everything describing the **U2M** path — the `azure-oauth` selector, the | ||
| > `AuthConfig::AzureOAuthU2M` variant, the authorize-endpoint override, and the | ||
| > napi/C-ABI U2M setters — is **PLANNED (PECOBLR-4120), not in this PR**. Those | ||
| > sections are marked inline below; treat this document as the design target for | ||
| > the full Azure surface, not a description of the delivered code. | ||
|
|
||
| ## Direction | ||
|
|
||
| **The kernel is the auth core; bindings are thin.** The kernel owns Azure | ||
| cloud-awareness — it detects the cloud from the workspace host, constructs the | ||
| correct Entra endpoints, auto-discovers the tenant, and applies the Azure client | ||
| id / scope / redirect-port defaults. Each binding forwards only its native auth | ||
| selector (+ the SP credentials for M2M); it does **not** build URLs, map scopes, | ||
| or discover tenants. | ||
|
|
||
| This supersedes the earlier "generic-override, kernel stays cloud-agnostic" | ||
| draft. The generic `token_url` / `scopes` overrides added in the first cut of | ||
| this PR **remain** as primitives (the Azure layer sets them internally, and they | ||
| stay usable for non-Azure custom endpoints), but Azure resolution now lives in | ||
| the kernel. | ||
|
|
||
| ### Why (and the correction that motivated it) | ||
|
|
||
| A live run against a real Azure workspace showed the generic approach's fatal | ||
| gap: the kernel's OIDC discovery returns `{host}/oidc/v1/authorize`, and the | ||
| workspace redirects that to a **malformed** `login.microsoftonline.com/{tenant}/ | ||
| v1/authorize` (404). Every connector instead uses `{host}/oidc/oauth2/v2.0/ | ||
| authorize`, which redirects to a valid Entra URL. Getting that right — plus | ||
| tenant discovery, per-cloud hosts, and the Azure defaults — is knowledge that | ||
| would otherwise be duplicated into every binding adapter. Putting it in the | ||
| kernel (as the Go driver's core already does) keeps it in one place. | ||
|
|
||
| ## Non-negotiable: invocation parity with Thrift | ||
|
|
||
| Switching a connection to `use_kernel=True` must **not** change how a user | ||
| invokes Azure auth. The kernel API must let each binding preserve its exact | ||
| Thrift-path `connect()` surface: | ||
|
|
||
| | Driver | Azure U2M — user passes | Azure M2M — user passes | | ||
| | --- | --- | --- | | ||
| | **Python** | `auth_type="azure-oauth"` | `auth_type="azure-sp-m2m"` + `azure_client_id` / `azure_client_secret`; **`azure_tenant_id` optional** (auto-discovered) | | ||
| | **Go** | `authType=OauthU2M` (Azure inferred from host; no azure param) | `authType=OauthM2M` + `clientID`/`clientSecret` — a *Databricks* SP (workspace OIDC), **not** Azure AD | | ||
| | **Node** | `authType='databricks-oauth'` + `azureTenantId` | `authType='databricks-oauth'` + `oauthClientId`/`Secret` + `azureTenantId` | | ||
|
|
||
| Consequences the kernel API must satisfy: | ||
| - `azure_tenant_id` is **optional** everywhere (kernel discovers it) — Thrift | ||
| parity, and a correction to the first cut which wrongly required it. | ||
| - The kernel exposes **both** a Databricks-SP M2M (`oauth-m2m`, workspace OIDC) | ||
| and an Azure-AD-SP M2M (`azure-sp-m2m`, Entra) — Go's "Azure M2M" maps to the | ||
| former, Python's `azure-sp-m2m` to the latter. | ||
| - Each binding's thin adapter normalizes its native selector (Python's explicit | ||
| `auth_type`, Go's host-inference, Node's `azureTenantId` flag) onto the kernel | ||
| Azure API; the kernel accepts an explicit Azure signal and does the rest. | ||
|
|
||
| ## What the kernel owns — `src/auth/oauth/azure.rs` (new) | ||
|
|
||
| 1. **Cloud / environment detection** from the host suffix: | ||
| `.azuredatabricks.net` → Public, `.databricks.azure.us` → USGov, | ||
| `.databricks.azure.cn` → China. Per-cloud login host + Databricks app-id | ||
| table (Public/dev/staging app ids from the connector's `AzureAppId`; Gov/China | ||
| use the prod app id). Mirrors the Go driver's `azureTenants` map. | ||
| 2. **Endpoint construction** (see per-flow sections). | ||
| 3. **Tenant auto-discovery**: `GET {host}/aad/auth`, read the redirect to | ||
| `login.microsoftonline.com/{tenant}/…`, parse the tenant from the path. | ||
| Sovereign-aware (reads the real redirect host). Only needed for M2M. | ||
| 4. **Azure defaults**: U2M client id `96eecda7-19ea-49cc-abb5-240097d554f5`, | ||
| port `8030`; scope app-id `2ff814a6-3304-4ab8-85cb-cd0e6f879c1d` (overridable | ||
| via `DATABRICKS_AZURE_TENANT_ID`, matching the connector). | ||
|
|
||
| ## `azure-oauth` (U2M) — PECOBLR-4120 — **PLANNED, not in this PR** | ||
|
|
||
| > Not implemented in this PR. `src/auth/oauth/azure.rs` currently has no U2M | ||
| > flow; the design below is the target for the follow-up (PECOBLR-4120). | ||
|
|
||
| Browser authorization-code + PKCE, driven by the kernel's existing U2M provider | ||
| with Azure endpoints/values: | ||
|
|
||
|
oss-reviewer-bot[bot] marked this conversation as resolved.
Resolved
|
||
| - **Authorize + token**: `{host}/oidc/oauth2/v2.0/authorize` and | ||
| `{host}/oidc/oauth2/v2.0/token` — the **workspace-host v2.0** paths (the Go | ||
| driver's proven pattern). No tenant needed: the workspace redirects the | ||
| authorize to Entra. This is the exact fix for the live 404 (`/oidc/v1/*` → | ||
| `/oidc/oauth2/v2.0/*`). | ||
| - **Client id** `96eecda7-…`, **scope** `{app_id}/user_impersonation | ||
| offline_access`, **redirect port** `8030`. | ||
| - The kernel gains an **authorize-endpoint override** internally so the Azure | ||
| path can pin `/oidc/oauth2/v2.0/authorize` instead of the discovered | ||
| `/oidc/v1/authorize`. (Discovery is otherwise unchanged for non-Azure U2M.) | ||
|
|
||
| ## `azure-sp-m2m` (M2M) — PECOBLR-4141 | ||
|
|
||
| Client-credentials against **Entra directly** (no browser, so no workspace | ||
| redirect available): | ||
|
|
||
| - **Token endpoint**: `{login_host}/{tenant}/oauth2/v2.0/token`, tenant | ||
| **auto-discovered** via `/aad/auth` when `azure_tenant_id` is omitted. | ||
| - **Scope**: `{effective_app_id}/.default` (app id from the host's cloud). | ||
| - **Credentials**: `azure_client_id` / `azure_client_secret` via HTTP Basic | ||
| (Entra v2.0 advertises `client_secret_basic`; verified). | ||
| - **Management token / `azure_workspace_resource_id`: optional add-on, gated on | ||
| the resource id (JDBC parity: `if (resourceId != null)`).** When | ||
| `azure_workspace_resource_id` is supplied, the kernel additionally fetches an | ||
| Azure-management token (scope `https://management.core.windows.net/.default`) | ||
| and emits the `X-Databricks-Azure-SP-Management-Token` + | ||
| `X-Databricks-Azure-Workspace-Resource-Id` header pair, so the control plane | ||
| can authorize an SP that holds an Azure RBAC role but is not a workspace | ||
| member. It defaults to `None` (data token only — the common workspace-member | ||
| case); gating avoids forcing the ARM `.default` exchange, which an app | ||
| registration without ARM access cannot complete, onto every SP's request hot | ||
| path. Implemented in `src/auth/oauth/azure.rs` | ||
| (`AzureServicePrincipalProvider`). | ||
|
|
||
| ## Federation | ||
|
|
||
| Unchanged. `FederationProvider` still wraps every flow; an Entra-issued token is | ||
| foreign-issuer and round-trips through `{host}/oidc/v1/token` (benign on Azure, | ||
| required for an Azure SP reaching a non-Azure workspace), with the non-breaking | ||
| fallback. | ||
|
|
||
| ## AuthConfig | ||
|
|
||
| Target surface — two variants. **`AzureServicePrincipal` ships in this PR; | ||
| `AzureOAuthU2M` is PLANNED (PECOBLR-4120) and not yet added to `config.rs`.** | ||
|
|
||
| ```rust | ||
| // PLANNED (PECOBLR-4120) — not in this PR | ||
| AuthConfig::AzureOAuthU2M { | ||
| client_id: Option<String>, // None → 96eecda7-… | ||
| redirect_ports: Option<Vec<u16>>, // None → [8030] | ||
| app_id: Option<String>, // scope resource; None → 2ff814a6-… / env | ||
| token_cache: Option<TokenCacheConfig>, | ||
| identity_federation_client_id: Option<String>, | ||
| } | ||
| AuthConfig::AzureServicePrincipal { // azure-sp-m2m | ||
| azure_client_id: String, | ||
| azure_client_secret: String, | ||
| azure_tenant_id: Option<String>, // None → auto-discover via /aad/auth | ||
| azure_workspace_resource_id: Option<String>, // Some → emit management-token headers (JDBC-gated) | ||
| identity_federation_client_id: Option<String>, | ||
| } | ||
| ``` | ||
|
|
||
| The existing `OAuthU2M` / `OAuthM2M` variants are unchanged (Databricks-native | ||
| flows, incl. Go's Databricks-SP M2M and the workspace-OIDC databricks-oauth). | ||
|
|
||
| ## Thin bindings | ||
|
|
||
| - **pyo3**: `auth_type="azure-sp-m2m"` + `azure_*` kwargs → `AzureServicePrincipal` | ||
| (shipped). `auth_type="azure-oauth"` → `AzureOAuthU2M` is **PLANNED | ||
| (PECOBLR-4120)**. No endpoint/scope/tenant logic in the binding. | ||
| - **napi**: `AzureSpM2m` + `azure*` fields (planned surface); `AzureOAuth` | ||
| U2M is **PLANNED (PECOBLR-4120)**. | ||
| - **C ABI**: `set_auth_azure_sp_m2m` setter (planned surface); | ||
| `set_auth_azure_oauth` is **PLANNED (PECOBLR-4120)**. | ||
| - **Connector #919**: `auth_bridge.py` simplifies to selector-mapping only — | ||
| forwards `auth_type` + azure creds, stops constructing URLs / scopes and stops | ||
| discovering the tenant (the kernel does it). Drops the kernel-path dependency | ||
| on `AzureOAuthEndpointCollection` / `get_azure_tenant_id_from_host`. | ||
|
|
||
| ## Testing | ||
|
|
||
| - **Unit (`azure.rs`)**: cloud/env detection per host suffix; endpoint | ||
| construction (U2M workspace v2.0; M2M Entra token URL per cloud); scope | ||
| app-id defaulting + `DATABRICKS_AZURE_TENANT_ID` override. | ||
| - **Wiremock**: tenant discovery (`/aad/auth` 302 → parse tenant); `azure-sp-m2m` | ||
| hits the Entra token endpoint with Basic + `.default` scope; `azure-oauth` | ||
| uses the `/oidc/oauth2/v2.0/authorize` path (regression for the live 404). | ||
| - **Binding boundary**: pyo3 kwargs accepted; napi/C-ABI selectors record values. | ||
| - **Live (required before GA)**: `azure-oauth` U2M against a real Azure workspace | ||
| (browser) — confirm the v2.0 authorize path fixes the 404 and the query runs; | ||
| `azure-sp-m2m` with a real workspace-member Entra SP; sovereign-cloud spot check. | ||
|
|
||
| ## Status / evolution | ||
|
|
||
| - First cut: generic overrides, kernel cloud-agnostic (shipped in this PR's early | ||
| commits). Retained as primitives. | ||
| - Live test found the `/oidc/v1/authorize` 404 → authorize must be v2.0. | ||
| - Decision (team): kernel is the auth core, bindings thin → Azure resolution | ||
| moves into the kernel (this doc). Management token implemented as an optional | ||
| add-on gated on `azure_workspace_resource_id` (RBAC-only SP support). | ||
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.