Skip to content

feat(auth): kernel-owned Azure service-principal M2M (azure-sp-m2m) (PECOBLR-4141) - #263

Merged
eric-wang-1990 merged 50 commits into
mainfrom
eric-wang/azure-service-principal-design
Aug 21, 2026
Merged

eric-wang-1990 merged 50 commits into
mainfrom
eric-wang/azure-service-principal-design

Conversation

@eric-wang-1990

@eric-wang-1990 eric-wang-1990 commented Aug 18, 2026 •

Copy link
Copy Markdown
Collaborator

What

Azure Entra ID service-principal M2M (azure-sp-m2m) as a kernel-owned auth flow. The kernel is the Azure-aware auth core — it resolves the Entra token endpoint, scope, effective app id, and tenant from the host; bindings just forward the SP credentials. See docs/designs/PECOBLR-4141-azure-service-principal-design.md.

Scope note: an earlier iteration also added a dedicated Azure U2M flow (azure-oauth). That was removed — the in-house databricks-oauth browser flow works against Azure workspaces (the workspace federates login to Entra) and is the default there, so a separate Azure U2M flow added surface without adding capability. Azure U2M = databricks-oauth.

azure-sp-m2m

  • AuthConfig::AzureServicePrincipal + src/auth/oauth/azure.rs: builds the Entra v2.0 token endpoint ({login}/{tenant}/oauth2/v2.0/token) and the {effective_app_id}/.default scope (dev/staging/prod app-id mapping, mirroring the connector's get_effective_azure_login_app_id), and auto-discovers the tenant from the workspace's /aad/auth redirect when azure_tenant_id is omitted (Thrift parity).
  • Management token (RBAC-only SPs — gated): the Authorization bearer is the Databricks-audience data token, which alone authenticates a workspace-member SP. When azure_workspace_resource_id is set, the kernel additionally sends X-Databricks-Azure-SP-Management-Token (a second Entra token on the ARM .default scope) paired with X-Databricks-Azure-Workspace-Resource-Id — matching the JDBC driver (if (resourceId != null)) — so a service principal that holds an Azure RBAC role but is not a workspace member can authenticate. When it's unset, no ARM management-scope token is fetched (keeping the second exchange off the hot path for the common member-SP case). Carried via a new AuthProvider::extra_headers() (delegated by FederationProvider, applied by the HTTP client on authenticated requests only).
  • pyo3: auth_type="azure-sp-m2m" with azure_client_id / azure_client_secret / azure_tenant_id / azure_workspace_resource_id. Connector (thin, forwards selector + creds): feat(kernel): route Azure Entra auth (azure-sp-m2m + azure-oauth) through the auth bridge databricks-sql-python#919.

Live verification

SELECT 1 round trip against a real Azure workspace via azure-sp-m2m, tenant auto-discovered:

RESULT: [Row(one=1, who='<sp-client-id>')]

Negative control (wrong secret) → AADSTS7000215: Invalid client secret from login.microsoftonline.com, confirming the real Entra client-credentials exchange (not a silent skip). Covered by an #[ignore], env-gated E2E test (azure_sp_m2m_select_one_round_trip), alongside wiremock tests for the header composition (management token + resource-id header sent together only when the resource id is set).

Also in this PR (generic, not Azure-specific)

  • Generic OAuth token_url override + C ABI kernel_session_config_set_oauth_token_endpoint() / set_oauth_scopes(). These back the JWT private-key M2M flow (merged from main) and custom-OIDC setups — retained, not Azure-specific.

Not included / follow-ups

  • Azure U2M — use databricks-oauth on Azure (works, and is the default). A dedicated azure-oauth flow can return later if needed.
  • Sovereign clouds (China / Gov) — the Entra login host is hardcoded commercial, matching the Thrift connector; a sovereign workspace fails naturally at the token exchange. Tenant discovery accepts sovereign login hosts (anchored on the host authority, so a spoofed login.microsoftonline.com.attacker.example is rejected). Documented in azure.rs.
  • napi + C-ABI dedicated azure-sp-m2m wiring.

JIRA: PECOBLR-4141.

This pull request and its description were written by Isaac.

…-4141)

Adds the design doc for kernel-native Azure service-principal M2M auth:
a new AuthConfig::AzureServicePrincipal variant + provider that mints an
Entra token via client-credentials, an AuthProvider::extra_headers() seam
for the two X-Databricks-Azure-* headers, and wiring across the pyo3, napi,
and C ABI bindings. Azure U2M is unchanged (already works via workspace OIDC).

Co-authored-by: Isaac
Signed-off-by: eric-wang-1990 <e.wang@databricks.com>

@oss-reviewer-bot oss-reviewer-bot Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verdict: 1 Medium · 2 Low

Solid, well-structured design doc — the structural claims I could check (AuthProvider trait shape, OnceLock auth storage in http.rs, the non_exhaustive Azure-AD note in config.rs) all match the code. No blocking issues for a design-only PR; one medium worth resolving before implementation (the uniform-federation-on-foreign-AAD-token assumption is the riskiest, least-verified piece) plus two low notes on externally-sourced values I couldn't verify here (host suffixes, Basic-vs-body client-secret).

- azure-oauth (U2M) is a distinct AAD-scoped flow tracked by PECOBLR-4120,
  not plain workspace OIDC; it needs no new kernel flow (connector-side
  scope synthesis in auth_bridge.py). Corrects the earlier wrong claim that
  it 'already works' as standard workspace OIDC.
- Selector renamed azure-client-secret -> azure-sp-m2m to match the
  connector's AuthType enum (databricks-sql-python auth/common.py).

Co-authored-by: Isaac
Signed-off-by: eric-wang-1990 <e.wang@databricks.com>

@oss-reviewer-bot oss-reviewer-bot Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verdict: 2 Low

Design-only doc for Azure Entra ID SP (M2M) auth — well-reasoned and its claims about existing code (AuthProvider trait shape, FederationProvider fallback, reserved-header set, non_exhaustive AuthConfig note) all check out against the source. Two low-severity clarity notes: the interaction between the new identity_federation_client_id field and the federation exchange branch it selects, and the retry semantics of the deliberately-fatal management-token refresh. No blocking concerns for a design review.

@eric-wang-1990 eric-wang-1990 added the engineer-bot Apply to an issue to trigger the engineer-bot; on a PR to enable engineer follow-up label Aug 18, 2026
oss-engineer-bot Bot pushed a commit that referenced this pull request Aug 18, 2026
Addresses:
  - #3805985323 at docs/designs/PECOBLR-4141-azure-service-principal-design.md:149
  - #3805985334 at docs/designs/PECOBLR-4141-azure-service-principal-design.md:183
  - #3805985342 at docs/designs/PECOBLR-4141-azure-service-principal-design.md:71
  - #3806018323 at docs/designs/PECOBLR-4141-azure-service-principal-design.md:205
  - #3806018337 at docs/designs/PECOBLR-4141-azure-service-principal-design.md:186

Signed-off-by: peco-engineer-bot[bot] <peco-engineer-bot[bot]@users.noreply.github.com>
Addresses:
  - #3824506029 at src/session.rs:1313

Signed-off-by: peco-engineer-bot[bot] <peco-engineer-bot[bot]@users.noreply.github.com>

@oss-reviewer-bot oss-reviewer-bot Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verdict: 1 High · 1 Medium · 1 Low

Mostly docs plus one kernel behavior worth a second look. The azure-sp-m2m provider is well-tested and the M2M/U2M discovery-skip and C-ABI wiring look correct. The one substantive concern (F1, High): the Azure SP provider always performs a second Entra token exchange for the ARM management scope and sends X-Databricks-Azure-SP-Management-Token on every request via extra_headers()?, whereas the JDBC reference gates that header on a configured resource id — a potential regression for workspace-member SPs lacking ARM access, and it contradicts this PR's own docs. F2/F3 are doc-vs-code inconsistencies (management token "not implemented" claims; design doc describes an unshipped Azure U2M variant).

Comment thread src/auth/oauth/azure.rs Resolved
Comment thread CONNECTION_PARAMETERS.md Resolved
Addresses:
  - #3824612628 at src/auth/oauth/azure.rs:236
  - #3824612635 at CONNECTION_PARAMETERS.md:93
  - #3824612639 at docs/designs/PECOBLR-4141-azure-service-principal-design.md:86

Signed-off-by: peco-engineer-bot[bot] <peco-engineer-bot[bot]@users.noreply.github.com>

@oss-reviewer-bot oss-reviewer-bot Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verdict: 1 Low

Solid, well-tested addition — the azure-sp-m2m kernel flow, the OIDC-discovery skip on token-URL override (M2M + U2M), and the C-ABI/napi override plumbing all look correct, and the refactors (build_reqwest_client, extra_headers delegation through FederationProvider, test_keys gating via #[cfg(test)] in mod.rs) are sound. One low-severity doc mismatch inline. Note: the PR description claims the azure-oauth U2M path is "implemented + LIVE-VERIFIED," but the actual diff ships only M2M (AzureServicePrincipal); the in-tree docs correctly mark U2M as planned — worth reconciling the description so reviewers/consumers aren't misled about what landed.

Comment thread tests/v0_execute_e2e.rs Resolved
Addresses:
  - #3824759344 at tests/v0_execute_e2e.rs:129

Signed-off-by: peco-engineer-bot[bot] <peco-engineer-bot[bot]@users.noreply.github.com>

@oss-reviewer-bot oss-reviewer-bot Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verdict: 1 Medium

Solid, well-tested PR — the kernel-owned Azure SP M2M flow, the extra_headers() trait addition (correctly delegated through FederationProvider and applied only on authenticated requests), the sovereign-host guards, and the C-ABI override plumbing all look correct, with good unit/wiremock coverage. One medium concern: the U2M token_url_override path now skips discovery and derives (rather than discovers) the authorize endpoint, a behavior change for pre-existing oauth-u2m + token_url callers that isn't reflected in the changelog. Note also the PR description claims azure-oauth U2M is shipped/live-verified, but the code and in-repo docs correctly state only M2M ships here (U2M is planned) — the description is stale, not the code.

Comment thread src/auth/oauth/u2m.rs Resolved
peco-engineer-bot[bot] added 2 commits August 20, 2026 19:51
Addresses:
  - #3824840562 at src/auth/oauth/u2m.rs:281

Signed-off-by: peco-engineer-bot[bot] <peco-engineer-bot[bot]@users.noreply.github.com>
Addresses:
  - #3824840562 at src/auth/oauth/u2m.rs:281

Signed-off-by: peco-engineer-bot[bot] <peco-engineer-bot[bot]@users.noreply.github.com>

@oss-reviewer-bot oss-reviewer-bot Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verdict: 1 Low

Solid, well-tested PR. The discovery-skip refactors (M2M/U2M), the C-ABI auth_spec_to_config extraction, and the Azure SP provider are correct; CloudFetch downloads use execute_without_auth so the new management-token extra_headers won't leak to presigned URLs, and extra_headers()'s blocking token fetch mirrors the pre-existing auth_header() call site. One Low: the tenant-host guard in tenant_from_login_url uses a substring check that is looser than its comment and than the suffix-matching used elsewhere in the module (defended today by reject_sovereign_host on the workspace host). Non-blocking nits: (a) the PR description states Azure U2M (azure-oauth) is "done + LIVE-VERIFIED" while the design doc repeatedly marks it PLANNED/not-in-this-PR — the code matches the design doc (no AzureOAuthU2M variant added), so the description is the stale artifact; (b) the BREAKING U2M token_url semantics change is duplicated into both `CHA

[...truncated to keep verdict scannable]

Comment thread src/auth/oauth/azure.rs Resolved
Addresses:
  - #3824937168 at src/auth/oauth/azure.rs:334

Signed-off-by: peco-engineer-bot[bot] <peco-engineer-bot[bot]@users.noreply.github.com>

@oss-reviewer-bot oss-reviewer-bot Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verdict: 2 Low

Solid, well-tested change: the new AzureServicePrincipal variant, azure.rs (sovereign/host-authority guards, tenant discovery via first-redirect-hop), the M2M/U2M discovery-skip semantics, and the C-ABI auth_spec_to_config refactor all carry good unit/wiremock coverage, and the empty-string precedence edge cases are explicitly tested. No correctness blockers found. Two low doc-consistency nits filed inline. Two meta notes not anchored to code: (1) the PR title uses docs: but the change ships a new kernel auth flow, a C ABI surface, and a provider — feat: would match the conventional-commit type to the actual content; (2) the PR description prominently claims azure-oauth U2M is "done + LIVE-VERIFIED," while the design doc added in the same PR and the diff itself show U2M is explicitly not shipped here (M2M only) — worth reconciling the description before merge to avoid reviewer/consumer confusion.

Comment thread CHANGELOG.md Resolved
Comment thread pyo3/src/auth.rs Resolved
Addresses:
  - #3825010408 at CHANGELOG.md:27
  - #3825010413 at pyo3/src/auth.rs:29

Signed-off-by: peco-engineer-bot[bot] <peco-engineer-bot[bot]@users.noreply.github.com>

@oss-reviewer-bot oss-reviewer-bot Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verdict: 1 Low

Looks good — a substantial, well-tested addition (kernel-owned azure-sp-m2m provider + generic OAuth token-endpoint/scope overrides across the C ABI/napi/pyo3). Unit, wiremock, and #[ignore] e2e coverage all present; the skip-discovery and management-token-gating logic match the stated JDBC parity, and the sovereign-host/tenant-parse guards are correctly anchored on the host authority rather than substrings.

One non-blocking note: the PR description claims the azure-oauth U2M flow is "implemented + LIVE-VERIFIED" in this PR, but the delivered code, docs/designs/PECOBLR-4141-...md, and CONNECTION_PARAMETERS.md all state U2M (AuthConfig::AzureOAuthU2M / auth_type="azure-oauth") is planned, not shipped here — only the M2M path lands. The docs/code are internally consistent; it's the PR summary/changelog framing that is misleading and worth correcting before merge so reviewers and the release notes reflect the actual scope. S

[...truncated to keep verdict scannable]

Comment thread NEXT_CHANGELOG.md Resolved
Addresses:
  - #3825062693 at NEXT_CHANGELOG.md:62

Signed-off-by: peco-engineer-bot[bot] <peco-engineer-bot[bot]@users.noreply.github.com>

@oss-reviewer-bot oss-reviewer-bot Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verdict: 1 Medium

Solid, well-tested slice: the shipped surface is AuthConfig::AzureServicePrincipal (azure-sp-m2m) plus generic OAuth token/scope overrides, and the diff matches that (no AzureOAuthU2M variant is actually added). Discovery-skip logic, sovereign-host guards, empty-string normalization, and header gating are all covered by unit/wiremock tests. One medium: the AuthProvider::extra_headers trait doc says the management-token header is "always" emitted, contradicting the code (and the rest of the PR), which gates it on azure_workspace_resource_id. Separately, note the PR description claims azure-oauth U2M is "implemented + live-verified," but the diff and in-tree docs correctly state U2M is planned/not-in-this-PR — the description is stale relative to what actually ships.

Comment thread src/auth/mod.rs Resolved
Addresses:
  - #3825110399 at src/auth/mod.rs:38

Signed-off-by: peco-engineer-bot[bot] <peco-engineer-bot[bot]@users.noreply.github.com>

@oss-reviewer-bot oss-reviewer-bot Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verdict: 1 Low

Solid, well-tested slice: the azure-sp-m2m kernel flow, the M2M/U2M token_url_override discovery-skip, the shared C-ABI OAuth setters, and the extra_headers() management-token pair are all coherent, correctly gated on azure_workspace_resource_id (JDBC parity), and covered by unit/wiremock tests; the sovereign-host and spoofed-microsoftonline guards are anchored on host authority rather than substrings, which is the right call. One low-severity robustness note on tenant-discovery retry (inline). Meta note (not a code finding): the PR title/description claim the azure-oauth U2M flow is "implemented + LIVE-VERIFIED" with an AuthConfig::AzureOAuthU2M variant and auth_type="azure-oauth" selector, but none of that is in the diff — the design doc, CONNECTION_PARAMETERS.md, and NEXT_CHANGELOG all correctly state U2M is planned/not shipped and only M2M lands here. Worth reconciling the description with the actual shipped scope before mer

[...truncated to keep verdict scannable]

Comment thread src/client/http.rs Resolved
eric-wang-1990 and others added 2 commits August 20, 2026 13:43
The U2M provider's derive-authorize-from-token change was added solely for the
azure-oauth (U2M) flow, which has been removed. azure-sp-m2m uses the M2M
provider (m2m.rs), never the U2M authorization-code provider, so this PR should
not touch u2m.rs at all. Restore it to main (its `token_endpoint_override`
handling — discover the authorize endpoint — is unchanged and still serves the
generic U2M token-endpoint override).

Co-authored-by: Isaac
Signed-off-by: eric-wang-1990 <e.wang@databricks.com>
Addresses:
  - #3825179963 at src/client/http.rs:782

Signed-off-by: peco-engineer-bot[bot] <peco-engineer-bot[bot]@users.noreply.github.com>

@oss-reviewer-bot oss-reviewer-bot Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verdict: 2 Medium

Solid, well-tested Azure SP M2M addition; the kernel-owned resolution, sovereign-host guards, management-token gating, and the M2M discovery-skip all look correct and are covered by unit/wiremock tests. My only concern is a documentation-vs-code mismatch (2 medium): NEXT_CHANGELOG.md's Breaking U2M entry and the C ABI header both describe a U2M token_url behavior (skip discovery, derive /authorize from /token, reject non-/token at session open) that the U2M code path does not implement — only the M2M path changed. No functional/correctness bugs found in the code itself.

Comment thread include/databricks_kernel.h Resolved
Comment thread NEXT_CHANGELOG.md Resolved
Addresses:
  - #3825250644 at include/databricks_kernel.h:281
  - #3825250652 at NEXT_CHANGELOG.md:14

Signed-off-by: peco-engineer-bot[bot] <peco-engineer-bot[bot]@users.noreply.github.com>

@oss-reviewer-bot oss-reviewer-bot Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ No issues identified by the review bot.

No other driver rejects sovereign hosts — Python Thrift's Azure SP provider
hardcodes commercial Entra and lets a sovereign workspace fail naturally at the
token exchange. Match that: remove `reject_sovereign_host` +
`AZURE_SOVEREIGN_HOST_SUFFIXES` and the up-front session.rs guard.

Kept the review bot's genuine improvements: the shared `host_authority` helper,
and `tenant_from_login_url`'s authority-*anchored* host check (rejects a spoofed
`login.microsoftonline.com.attacker.example`, which a loose `contains()` would
admit). That check now accepts the Microsoft/Azure AD login authorities —
commercial and sovereign (`login.microsoftonline.us`, `login.chinacloudapi.cn`)
— so discovery parses the tenant and a sovereign workspace fails at the
commercial token exchange, rather than being special-cased. Sovereign support
remains a documented follow-up in azure.rs.

Co-authored-by: Isaac
Signed-off-by: eric-wang-1990 <e.wang@databricks.com>
The management token (X-Databricks-Azure-SP-Management-Token) was minted
via the Entra v2.0 client-credentials grant with
scope=https://management.core.windows.net/.default, which yields an aud
claim of https://management.core.windows.net (no trailing slash). The
Databricks control plane strict-matches aud against
https://management.core.windows.net/ (with slash) and rejected the token
with HTTP 400 IncorrectClaimException.

Mint it instead via the Entra v1.0 resource= grant
({login}/{tenant}/oauth2/token), whose aud is the requested resource
verbatim — trailing slash included. The v1.0 endpoint returns expires_in
as a JSON string, which the oauth2 crate's strict parser rejects, so the
v1.0 path fetches and parses the token response leniently.

Verified end-to-end against a live Azure workspace + RBAC-only SP.

Co-authored-by: Isaac
Signed-off-by: eric-wang-1990 <e.wang@databricks.com>
…ce-principal-design

# Conflicts:
#	NEXT_CHANGELOG.md

@oss-reviewer-bot oss-reviewer-bot Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verdict: 1 Low

Looks good — a clean, kernel-owned azure-sp-m2m flow with strong test coverage (host-suffix guards, spoofed-host rejection, v1.0 string-expires_in tolerance, management-token gating, discovery-skip-on-override). Token caching is preserved (both data and management tokens ride ClientCredentialsProvider/TokenStore), extra_headers is correctly gated on azure_workspace_resource_id and delegated through FederationProvider, and the C ABI/pyo3/napi wiring is unit-tested. One low-severity robustness note on non-retry-aware tenant discovery is filed inline.

Nit (summary-only): the AZURE_DATABRICKS_APP_ID doc comment in src/auth/oauth/azure.rs says the connector's DATABRICKS_AZURE_TENANT_ID env override "maps onto the resource app id," but effective_app_id resolves solely by host suffix with no env override — the comment describes behavior the shipped M2M code does not implement.

Comment thread src/auth/oauth/azure.rs
))
})?;
let redirect_url = reqwest::Url::parse(&location).map_err(|e| {
Error::unauthenticated().message(format!(

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Low — Azure tenant auto-discovery uses first_redirect_location, which the authors correctly note is not run through the kernel's retry ladder (unlike OidcEndpoints::discover, which flows through execute). The error is propagated with ? here and again in build_base_auth_provider with no fallback, so a single transient 5xx / timeout / connection reset on the /aad/auth probe fails Session::open outright for a zero-config-tenant azure-sp-m2m caller — a robustness regression relative to every other OAuth flow, which retry their discovery hop.

This is documented and has a workaround (pass azure_tenant_id explicitly), so severity is low, but since the probe is a single deterministic hop it would be cheap to run it through the same retry policy (or add a bounded retry) so a blip during open doesn't hard-fail the common zero-config path. Worth a follow-up rather than a blocker.

This branch was previously deployed

1 inactive deployment
azure-prod — ad78a5be Deployed Aug 21, 2026 by oss-reviewer-bot[bot] via followup #877
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants