Skip to content

feat(auth): add mandatory OIDC token exchange - #241

Merged
vuanhphung merged 8 commits into
mainfrom
feature/token-federation-core
Aug 13, 2026
Merged

vuanhphung merged 8 commits into
mainfrom
feature/token-federation-core

Conversation

@vuanhphung

@vuanhphung vuanhphung commented Aug 11, 2026 •

Copy link
Copy Markdown
Collaborator

Implements mandatory OIDC token exchange for foreign-issuer JWTs. PATs and same-workspace OAuth tokens pass through, while exchange failures fall back to the original token.

Adds optional SP-wide WIF configuration to the PAT, OAuth M2M, and OAuth U2M AuthConfig variants. Existing constructors retain their current signatures and default the option to None. Exchange results are cached and concurrent misses are coalesced; binding exposure will follow separately.

Testing: cargo +stable fmt --all, cargo clippy --all-targets -- -D warnings, cargo test, and napi Clippy/tests.

@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 · 1 Nit

Looks good — clean, well-tested implementation of BYOT token exchange with sound single-flight coalescing and non-breaking fallback. A few low-severity edge notes: follower poll blocks a tokio worker thread, host comparison is port-sensitive, and the server's token_type is ignored when building the header.

Other findings

  • ⚪ Nit — The exchange parses and stores token_type (defaulting to Bearer), but get_auth_header unconditionally formats format!("Bearer {token}"), so a non-Bearer token_type from the server would be silently dropped. In practice the exchange always yields a Bearer token for the sql scope, so this is cosmetic — either honor the returned token_type or drop the field to avoid implying it's used.

Comment thread src/auth/oauth/federation.rs Resolved
Comment thread src/auth/oauth/federation.rs Resolved

@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 · 1 Low

Solid, well-tested feature — the issuer gating, single-flight coalescing, RAII flag-clear, and non-breaking fallback are all sound, and coverage (unit + wiremock, incl. concurrency) is strong. Two non-blocking notes: the failure-fallback cache entry's effective de-dup window is ~20s not the 60s the comment implies (40s expiry buffer eats into it), and the follower sleep-poll path can park worker threads and doesn't short-circuit once the leader has published. Neither breaks correctness.

Comment thread src/auth/oauth/federation.rs Resolved
Comment thread src/auth/oauth/federation.rs Resolved

@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

Looks good — clean, well-tested implementation of mandatory OIDC token exchange. The single-flight coalescing, expiry/fallback caching math, current-thread-runtime guard, and non-breaking fallback all verify correctly, and all SessionConfig literals are updated. Two minor (Low) notes: a per-request JWT re-parse on the hot path, and a couple of test assertions that could tighten the WIF-vs-BYOT mutual-exclusivity contract.

Comment thread src/auth/oauth/federation.rs Resolved
Comment thread tests/token_federation_wiremock.rs Resolved
Comment thread src/session.rs Outdated
pub struct SessionBuilder {
connection: Option<ConnectionConfig>,
auth: Option<AuthConfig>,
identity_federation_client_id: Option<String>,

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Why not put this in the AuthConfig but as a separate sessionBuilder param?

Comment thread src/auth/oauth/federation.rs Resolved
Exchange foreign-issuer JWTs for workspace tokens while passing through PATs and same-workspace tokens. Cache successful exchanges, coalesce concurrent callers, and fall back to the original token on exchange failures.

Signed-off-by: Vu Anh Phung <vu.phung@databricks.com>
Move follower waits off Tokio workers and normalize explicit default ports during issuer comparison.

Signed-off-by: Vu Anh Phung <vu.phung@databricks.com>
Match the Python and Go token federation providers by comparing parsed hostnames independently of port.

Signed-off-by: Vu Anh Phung <vu.phung@databricks.com>
Signed-off-by: Vu Anh Phung <vu.phung@databricks.com>
Signed-off-by: Vu Anh Phung <vu.phung@databricks.com>
Signed-off-by: Vu Anh Phung <vu.phung@databricks.com>
Signed-off-by: Vu Anh Phung <vu.phung@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.

✅ No issues identified by the review bot.

Signed-off-by: Vu Anh Phung <vu.phung@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

Looks good — a clean, careful, and unusually well-tested implementation of mandatory OIDC token exchange. Production wiring is sound: the SEA transport retains the strong Arc<DatabricksHttpClient> so the FederationProvider's Weak upgrade succeeds (the cycle-avoidance rationale checks out), the AuthProvider trait has only get_auth_header so wrapping fully delegates, the single-flight leader/follower coalescing re-checks the cache after winning the election (no redundant exchanges), the current-thread runtime is guarded before block_in_place, and non-2xx/parse failures fall back to the original token with wiremock coverage for each. The AuthConfig field additions are threaded consistently through all constructors, bindings, and tests. Only two minor, non-blocking robustness notes are posted inline (coupled-by-comment timeout bounds; an unreachable-by-construction blocking arm).

Comment thread src/auth/oauth/federation.rs Resolved
Comment thread src/auth/oauth/federation.rs Resolved

This branch was previously deployed

1 inactive deployment
azure-prod — 2ce4b441 Deployed Aug 13, 2026 by oss-reviewer-bot[bot] via followup #340
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.

2 participants