From aabe7ade215269caeecd684ca7ad05a405868cd4 Mon Sep 17 00:00:00 2001 From: Gopal Lal Date: Sat, 30 May 2026 03:57:39 +0000 Subject: [PATCH 1/2] feat(auth): gate OAuth modules behind an optional `oauth` Cargo feature MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Make `oauth2`, `open`, `dirs`, `sha2` optional deps gated behind a new `oauth` Cargo feature. The feature is **on by default**, so existing consumers (pyo3, napi, kernel CI, anyone using `AuthConfig::OAuthM2M` / `OAuthU2M`) see no behaviour change. The `oauth`-off build is exercised by the upcoming `MultiKernelDriverBenchmark` perf suite in `databricks-eng/universe`, which only authenticates with PAT. Shipping the ~12k lines of `oauth2` + `open` source through universe's Rust-crate vendoring system for a code path the benchmark never executes is wasted review surface; this PR lets the universe side opt out via `--no-default-features --features tls-native`. What's gated: - `auth::oauth` module (whole subtree). - `AuthConfig::OAuthM2M` / `OAuthU2M` / `OAuthFederation` variants + their Debug-redaction arms + the redaction tests. - `build_auth_provider` OAuth match arms in `session.rs` plus the imports of `AuthorizationCodeProvider` / `ClientCredentialsProvider`. - `util::runtime::block_on_in_runtime` (only OAuth providers' sync `AuthProvider::get_auth_header` impls call it). - `tests/oauth_u2m_integration.rs` (whole-file) and the OAuth variants in `tests/v0_session_e2e.rs`. `AuthConfig::Pat` and `AuthConfig::External` stay unconditional. Verified both modes locally: - `cargo test --lib` (default features) — 507 tests pass. - `cargo test --lib --no-default-features --features tls-native` — 462 tests pass (the 45 OAuth-specific tests correctly compile out). - `cargo clippy --all-targets -- -D warnings` passes in both configs. - `cargo fmt --all -- --check` passes. Signed-off-by: Gopal Lal --- Cargo.toml | 28 +++++++++++++++++++++++----- src/auth/mod.rs | 2 ++ src/config.rs | 8 ++++++++ src/session.rs | 16 +++++++++++++--- src/util/runtime.rs | 6 ++++++ tests/oauth_u2m_integration.rs | 5 +++++ tests/v0_session_e2e.rs | 2 ++ 7 files changed, 59 insertions(+), 8 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 973bfb2f..8f5a71f1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -84,10 +84,17 @@ thiserror = "2" # Strip defaults and re-enable just the `reqwest` integration here; the # kernel's own `tls-native` / `tls-rustls` feature controls the TLS # backend for reqwest, and oauth2 inherits whichever the consumer picks. -oauth2 = { version = "5", default-features = false, features = ["reqwest"] } # OAuth 2.0 protocol operations (PKCE, token exchange, client credentials) -sha2 = "0.10" # SHA-256 for token cache key generation -open = "5" # Browser launch for interactive OAuth flows -dirs = "5" # Cross-platform config directory (~/.config/) +# OAuth surface is gated behind the `oauth` Cargo feature (default on, so +# existing consumers — pyo3, napi, kernel CI — see no behavior change). The +# `databricks-sql-kernel` perf benchmark in `databricks-eng/universe` opts +# out via `--no-default-features --features tls-native`, because it only +# authenticates with PAT and shipping ~12k lines of unused `oauth2` / `open` +# / `dirs` / `sha2` source through universe's Rust-crate vendoring is wasted +# review surface. +oauth2 = { version = "5", default-features = false, features = ["reqwest"], optional = true } # OAuth 2.0 protocol operations (PKCE, token exchange, client credentials) +sha2 = { version = "0.10", optional = true } # SHA-256 for token cache key generation +open = { version = "5", optional = true } # Browser launch for interactive OAuth flows +dirs = { version = "5", optional = true } # Cross-platform config directory (~/.config/) [dev-dependencies] tokio = { version = "1", features = ["rt-multi-thread", "macros"] } @@ -127,9 +134,20 @@ tempfile = "3" # but that separation is no longer load-bearing for the TLS feature # guarantee — items 1 and 2 above are. [features] -default = ["tls-native"] +# Default keeps `oauth` enabled so existing consumers (pyo3, napi, kernel CI, +# any direct-Rust caller using `AuthConfig::OAuthM2M` / `OAuthU2M`) build +# identically to before this feature gate was added. The `oauth`-off build +# is exercised by the universe-side perf benchmark and is also a useful +# build-time sanity check for any future consumer that only uses PAT. +default = ["tls-native", "oauth"] tls-native = ["reqwest/native-tls"] tls-rustls = ["reqwest/rustls-tls"] +# Pulls in oauth2 + the helper crates used only by OAuth flows (token cache +# hashing, config-dir resolution, browser launch). `auth/oauth/*` modules and +# the `OAuthM2M` / `OAuthU2M` / `OAuthFederation` variants of `AuthConfig` +# are `#[cfg(feature = "oauth")]`-gated; turning the feature off leaves +# `AuthConfig::Pat` and a clean `build_auth_provider` with one match arm. +oauth = ["dep:oauth2", "dep:sha2", "dep:open", "dep:dirs"] [lib] name = "databricks_sql_kernel" diff --git a/src/auth/mod.rs b/src/auth/mod.rs index 69b36131..816fb50d 100644 --- a/src/auth/mod.rs +++ b/src/auth/mod.rs @@ -15,10 +15,12 @@ //! Authentication mechanisms for the Databricks ADBC driver. pub mod config; +#[cfg(feature = "oauth")] pub mod oauth; pub mod pat; pub use config::{AuthConfig, AuthType}; +#[cfg(feature = "oauth")] pub use oauth::{AuthorizationCodeProvider, ClientCredentialsProvider}; pub use pat::PersonalAccessToken; diff --git a/src/config.rs b/src/config.rs index 0d9fbb84..0b7c6a5c 100644 --- a/src/config.rs +++ b/src/config.rs @@ -200,6 +200,7 @@ pub enum AuthConfig { /// OAuth 2.0 machine-to-machine (client credentials grant). /// Used for service-principal authentication. + #[cfg(feature = "oauth")] OAuthM2M { client_id: String, client_secret: String, @@ -215,6 +216,7 @@ pub enum AuthConfig { /// `redirect_port`, opens the user's browser to the workspace's /// authorize endpoint, and exchanges the returned code for a /// token. + #[cfg(feature = "oauth")] OAuthU2M { /// OAuth client ID. `None` → `"databricks-cli"` (the public /// CLI client registered on every workspace). @@ -243,6 +245,7 @@ pub enum AuthConfig { /// [`Session::open`](crate::Session::open) with this variant /// returns `ErrorCode::InvalidArgument` until the implementation /// lands. + #[cfg(feature = "oauth")] OAuthFederation { subject_token: String, subject_token_type: String, @@ -277,6 +280,7 @@ impl std::fmt::Debug for AuthConfig { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { match self { Self::Pat { .. } => f.write_str("Pat { token: }"), + #[cfg(feature = "oauth")] Self::OAuthM2M { client_id, scopes, .. } => f @@ -285,6 +289,7 @@ impl std::fmt::Debug for AuthConfig { .field("client_secret", &"") .field("scopes", scopes) .finish(), + #[cfg(feature = "oauth")] Self::OAuthU2M { client_id, redirect_port, @@ -296,6 +301,7 @@ impl std::fmt::Debug for AuthConfig { .field("redirect_port", redirect_port) .field("scopes", scopes) .finish(), + #[cfg(feature = "oauth")] Self::OAuthFederation { subject_token_type, audience, @@ -862,6 +868,7 @@ mod tests { assert!(s.contains("")); } + #[cfg(feature = "oauth")] #[test] fn debug_oauth_m2m_redacts_secret() { let c = AuthConfig::OAuthM2M { @@ -876,6 +883,7 @@ mod tests { assert!(s.contains("")); } + #[cfg(feature = "oauth")] #[test] fn debug_oauth_federation_redacts_subject_token() { let c = AuthConfig::OAuthFederation { diff --git a/src/session.rs b/src/session.rs index f9b3cb5c..0fa14bce 100644 --- a/src/session.rs +++ b/src/session.rs @@ -43,9 +43,10 @@ //! signature we may need to reshape. The methods will be added once //! the server contract stabilises. -use crate::auth::{ - AuthProvider, AuthorizationCodeProvider, ClientCredentialsProvider, PersonalAccessToken, -}; +use crate::auth::AuthProvider; +use crate::auth::PersonalAccessToken; +#[cfg(feature = "oauth")] +use crate::auth::{AuthorizationCodeProvider, ClientCredentialsProvider}; use crate::client::http::TlsConfig as HttpTlsConfig; use crate::client::retry::{ build_retry_configs, RequestCategory, RetryConfig, RetryConfigOverrides, @@ -653,6 +654,12 @@ fn result_to_post_process_options( /// Build the auth provider for a given [`AuthConfig`]. `host` is the /// workspace URL — used for OIDC discovery on M2M / U2M flows. +// +// `host` and `http_client` are only consumed by the OAuth match arms; +// under `--no-default-features` they look unused, which would trip +// clippy's `-D warnings`. Conditional `#[allow]` keeps the parameter +// names readable when the feature is on. +#[cfg_attr(not(feature = "oauth"), allow(unused_variables))] async fn build_auth_provider( auth: &AuthConfig, host: &str, @@ -667,6 +674,7 @@ async fn build_auth_provider( } Ok(Arc::new(PersonalAccessToken::new(token.clone()))) } + #[cfg(feature = "oauth")] AuthConfig::OAuthM2M { client_id, client_secret, @@ -692,6 +700,7 @@ async fn build_auth_provider( .await?; Ok(Arc::new(provider)) } + #[cfg(feature = "oauth")] AuthConfig::OAuthU2M { client_id, redirect_port, @@ -717,6 +726,7 @@ async fn build_auth_provider( .await?; Ok(Arc::new(provider)) } + #[cfg(feature = "oauth")] AuthConfig::OAuthFederation { .. } => Err(Error::invalid_argument() .message("AuthConfig::OAuthFederation is reserved for v0.1; not yet wired")), AuthConfig::External(_) => Err(Error::invalid_argument() diff --git a/src/util/runtime.rs b/src/util/runtime.rs index 88f5487e..a4dbfc56 100644 --- a/src/util/runtime.rs +++ b/src/util/runtime.rs @@ -40,6 +40,12 @@ /// issue #19), and any caller driving the kernel from a runtime /// context should also be on multi-thread for the same concurrent-IO /// reasons. +/// +/// **`#[cfg(feature = "oauth")]`** — the only callsites are the +/// OAuth providers' sync `AuthProvider::get_auth_header` impls +/// (`auth/oauth/m2m.rs` + `auth/oauth/u2m.rs`). PAT auth is fully +/// synchronous and doesn't need the runtime bridge. +#[cfg(feature = "oauth")] pub(crate) fn block_on_in_runtime(runtime_handle: &tokio::runtime::Handle, fut: F) -> F::Output where F: std::future::Future, diff --git a/tests/oauth_u2m_integration.rs b/tests/oauth_u2m_integration.rs index 8ea82a3d..9466631f 100644 --- a/tests/oauth_u2m_integration.rs +++ b/tests/oauth_u2m_integration.rs @@ -12,6 +12,11 @@ // See the License for the specific language governing permissions and // limitations under the License. +// Whole-file gate: every test here exercises `crate::auth::oauth`, which +// is only compiled when the `oauth` feature is on. Under `--no-default-features` +// the module is absent and these tests can't link. +#![cfg(feature = "oauth")] + //! Wiremock integration tests for OAuth U2M refresh token flow. //! //! These tests use the wiremock crate to simulate OIDC discovery and token endpoints, diff --git a/tests/v0_session_e2e.rs b/tests/v0_session_e2e.rs index abe4267c..69c86db6 100644 --- a/tests/v0_session_e2e.rs +++ b/tests/v0_session_e2e.rs @@ -68,6 +68,7 @@ async fn open_with_pat_against_live_warehouse() { .expect("explicit close() should succeed"); } +#[cfg(feature = "oauth")] #[tokio::test] #[ignore] async fn open_with_oauth_m2m_against_live_warehouse() { @@ -98,6 +99,7 @@ async fn open_with_oauth_m2m_against_live_warehouse() { session.close().await.expect("close()"); } +#[cfg(feature = "oauth")] #[tokio::test] #[ignore] async fn open_with_oauth_u2m_against_live_warehouse() { From e242fdafbdf73a41ebfe6d4fd8d6d2b099ca15b1 Mon Sep 17 00:00:00 2001 From: Gopal Lal Date: Sat, 30 May 2026 11:48:35 +0000 Subject: [PATCH 2/2] chore(ci): clear three unrelated failures blocking this PR None of these are caused by the OAuth gating change; they are pre-existing drift / new transitive dependencies that this PR happens to surface. Fixed here to unblock CI. 1. fmt drift in src/reader/cloudfetch/arrow_parser.rs (chain layout at L63 and L225). `cargo fmt --all` reflow only. 2. Two doc tests at src/session.rs:488 and src/config.rs:365 used `TlsConfig { custom_ca_cert: ..., ..TlsConfig::default() }` struct-literal construction. `TlsConfig` is `#[non_exhaustive]`, and doc tests compile as an external crate, so E0639 fires. Switched to the mutate-after-default pattern, matching how `ResultConfig` is already constructed externally (see PR #70). 3. tiny-keccak v2.0.2 (transitive via ahash -> const-random -> const-random-macro) carries CC0-1.0, which was missing from the deny.toml allow-list. CC0-1.0 is FSF-Free and effectively public-domain dedication, so adding it is consistent with the existing permissive allow-list (Apache-2.0, MIT, ISC, etc.). Signed-off-by: Gopal Lal --- deny.toml | 1 + src/config.rs | 12 ++++-------- src/reader/cloudfetch/arrow_parser.rs | 9 ++++----- src/session.rs | 6 ++---- 4 files changed, 11 insertions(+), 17 deletions(-) diff --git a/deny.toml b/deny.toml index 19b1171e..d36eb2a7 100644 --- a/deny.toml +++ b/deny.toml @@ -29,6 +29,7 @@ allow = [ "Apache-2.0", "BSD-2-Clause", "BSD-3-Clause", + "CC0-1.0", "CDLA-Permissive-2.0", "ISC", "MIT", diff --git a/src/config.rs b/src/config.rs index 0b7c6a5c..7c168543 100644 --- a/src/config.rs +++ b/src/config.rs @@ -365,18 +365,14 @@ pub struct ProxyConfig {} /// ```no_run /// # use databricks_sql_kernel::TlsConfig; /// // From a file path: -/// let from_file = TlsConfig { -/// custom_ca_cert: Some(std::fs::read("/etc/ssl/corp-ca.pem").unwrap()), -/// ..TlsConfig::default() -/// }; +/// let mut from_file = TlsConfig::default(); +/// from_file.custom_ca_cert = Some(std::fs::read("/etc/ssl/corp-ca.pem").unwrap()); /// /// // From an in-memory buffer (the napi-rs `Buffer` / pyo3 `bytes` /// // path — no tempfile shim needed): /// let pem_bytes: Vec = b"-----BEGIN CERTIFICATE-----\n...".to_vec(); -/// let from_bytes = TlsConfig { -/// custom_ca_cert: Some(pem_bytes), -/// ..TlsConfig::default() -/// }; +/// let mut from_bytes = TlsConfig::default(); +/// from_bytes.custom_ca_cert = Some(pem_bytes); /// # let _ = (from_file, from_bytes); /// ``` // diff --git a/src/reader/cloudfetch/arrow_parser.rs b/src/reader/cloudfetch/arrow_parser.rs index dcf3cec0..e6f6f50a 100644 --- a/src/reader/cloudfetch/arrow_parser.rs +++ b/src/reader/cloudfetch/arrow_parser.rs @@ -63,9 +63,9 @@ pub fn parse_arrow_ipc(data: &[u8], compression: CompressionCodec) -> Result Result<(), Box> { - /// let tls = TlsConfig { - /// custom_ca_cert: Some(std::fs::read("/etc/ssl/corp-ca.pem")?), - /// ..TlsConfig::default() - /// }; + /// let mut tls = TlsConfig::default(); + /// tls.custom_ca_cert = Some(std::fs::read("/etc/ssl/corp-ca.pem")?); /// let _builder = Session::builder().tls(tls); /// # Ok(()) } /// ```