From 0b35f7a295c660da1a1ebde5e887e40b762d11cb Mon Sep 17 00:00:00 2001 From: Vikrant Puppala Date: Wed, 2 Sep 2026 22:55:11 +0000 Subject: [PATCH] fix(http): identify direct kernel traffic Signed-off-by: Vikrant Puppala --- napi/index.d.ts | 11 +++++------ napi/src/database.rs | 11 +++++------ src/client/http.rs | 31 +++++++++++++++++-------------- src/config.rs | 4 ++-- 4 files changed, 29 insertions(+), 28 deletions(-) diff --git a/napi/index.d.ts b/napi/index.d.ts index d5d62b76..0f6d8b56 100644 --- a/napi/index.d.ts +++ b/napi/index.d.ts @@ -490,8 +490,8 @@ export interface ConnectionOptions { * An **ordered list** of `(name, value)` pairs, mirroring the kernel * core's `Vec<(String, String)>` and the pyo3 binding's * `http_headers` — order is preserved and duplicate names are - * allowed (the kernel emits each entry, and for `User-Agent` folds - * the **last** one into its base UA). + * allowed (the kernel emits each entry, and uses the **last** + * `User-Agent` as its effective UA). * * Three names are handled specially by the kernel: * - `Authorization` / `x-databricks-org-id` are **reserved** — a @@ -499,10 +499,9 @@ export interface ConnectionOptions { * auth and multi-tenant routing can't be hijacked by a custom * header. (The NodeJS driver also drops these before they cross * the FFI, matching the Python connector's double-wall.) - * - `User-Agent` is **appended** to the kernel base UA (rather than - * replacing it), preserving the `DatabricksJDBCDriverOSS/...` - * token the SEA server keys on while still surfacing the caller's - * identity. The NodeJS driver folds its `userAgentEntry` into a + * - `User-Agent` **replaces** the `DatabricksSQLKernel/...` base. + * Its leading prefix must therefore be allow-listed by the SEA + * server. The NodeJS driver folds its `userAgentEntry` into a * `User-Agent` entry here. */ customHeaders?: Array diff --git a/napi/src/database.rs b/napi/src/database.rs index 3e008204..c6fab22b 100644 --- a/napi/src/database.rs +++ b/napi/src/database.rs @@ -362,8 +362,8 @@ pub struct ConnectionOptions { /// An **ordered list** of `(name, value)` pairs, mirroring the kernel /// core's `Vec<(String, String)>` and the pyo3 binding's /// `http_headers` — order is preserved and duplicate names are - /// allowed (the kernel emits each entry, and for `User-Agent` folds - /// the **last** one into its base UA). + /// allowed (the kernel emits each entry, and uses the **last** + /// `User-Agent` as its effective UA). /// /// Three names are handled specially by the kernel: /// - `Authorization` / `x-databricks-org-id` are **reserved** — a @@ -371,10 +371,9 @@ pub struct ConnectionOptions { /// auth and multi-tenant routing can't be hijacked by a custom /// header. (The NodeJS driver also drops these before they cross /// the FFI, matching the Python connector's double-wall.) - /// - `User-Agent` is **appended** to the kernel base UA (rather than - /// replacing it), preserving the `DatabricksJDBCDriverOSS/...` - /// token the SEA server keys on while still surfacing the caller's - /// identity. The NodeJS driver folds its `userAgentEntry` into a + /// - `User-Agent` **replaces** the `DatabricksSQLKernel/...` base. + /// Its leading prefix must therefore be allow-listed by the SEA + /// server. The NodeJS driver folds its `userAgentEntry` into a /// `User-Agent` entry here. pub custom_headers: Option>, diff --git a/src/client/http.rs b/src/client/http.rs index 8ad32bd2..f164215a 100644 --- a/src/client/http.rs +++ b/src/client/http.rs @@ -298,11 +298,10 @@ impl Default for HttpClientConfig { connect_timeout: Duration::from_secs(30), read_timeout: Duration::from_secs(60), max_connections_per_host: 100, - // TODO: Update user agent to properly identify as Rust ADBC driver. - // Currently using JDBC user agent to enable INLINE_OR_EXTERNAL_LINKS disposition - // which returns all chunk links in a single response, enabling true parallel downloads. - // See: https://github.com/databricks-eng/universe/pull/909153 - user_agent: format!("DatabricksJDBCDriverOSS/{}", env!("CARGO_PKG_VERSION")), + // This kernel-specific prefix is allow-listed by + // databricks.sqlexecapi.known_driver_prefixes, which enables + // INLINE_OR_EXTERNAL_LINKS while preserving accurate attribution. + user_agent: format!("DatabricksSQLKernel/{}", env!("CARGO_PKG_VERSION")), proxy: ProxyConfig::default(), tls: TlsConfig::default(), org_id: None, @@ -402,7 +401,7 @@ impl DatabricksHttpClient { // A caller `User-Agent` **replaces** the kernel's base UA // entirely: the effective UA becomes the caller string verbatim // (e.g. the connector's composed `PyDatabricksSqlConnector/x - // (entry)`), with no `DatabricksJDBCDriverOSS/...` prefix. This is + // (entry)`), with no `DatabricksSQLKernel/...` prefix. This is // intentional — it gives the SEA server an accurate driver // identity for query-source attribution (the appended-prefix shape // matched none of the gateway's `parseUserAgent` patterns and was @@ -416,7 +415,7 @@ impl DatabricksHttpClient { // of that flag; a UA whose prefix is not allow-listed is rejected // with HTTP 400 "not a supported disposition" / redirected to // Thrift. `PyDatabricksSqlConnector` is allow-listed for this - // reason. The base UA below remains `DatabricksJDBCDriverOSS/...` + // reason. The base UA below remains `DatabricksSQLKernel/...` // so requests with NO caller UA still pass the gate. // // Last UA wins if a caller somehow set several. @@ -1053,6 +1052,10 @@ mod tests { assert_eq!(config.connect_timeout, Duration::from_secs(30)); assert_eq!(config.read_timeout, Duration::from_secs(60)); assert_eq!(config.max_connections_per_host, 100); + assert_eq!( + config.user_agent, + format!("DatabricksSQLKernel/{}", env!("CARGO_PKG_VERSION")) + ); } #[tokio::test] @@ -1161,7 +1164,7 @@ mod tests { // from the custom-header list (so it isn't re-applied per request; // it becomes reqwest's default UA instead). let config = HttpClientConfig { - user_agent: "DatabricksJDBCDriverOSS/9.9".to_string(), + user_agent: "DatabricksSQLKernel/9.9".to_string(), custom_headers: vec![ ("x-keep".to_string(), "v".to_string()), ( @@ -1196,24 +1199,24 @@ mod tests { fn test_empty_caller_user_agent_keeps_base() { // A whitespace-only caller UA is ignored — the base UA stays so // the request still carries an identity (and the - // disposition-gating prefix when the base is the JDBC token). + // disposition-gating prefix when the base is allow-listed). let config = HttpClientConfig { - user_agent: "DatabricksJDBCDriverOSS/9.9".to_string(), + user_agent: "DatabricksSQLKernel/9.9".to_string(), custom_headers: vec![("User-Agent".to_string(), " ".to_string())], ..HttpClientConfig::default() }; let client = DatabricksHttpClient::new(config, default_retry_configs()).unwrap(); - assert_eq!(client.config().user_agent, "DatabricksJDBCDriverOSS/9.9"); + assert_eq!(client.config().user_agent, "DatabricksSQLKernel/9.9"); } #[test] fn test_no_caller_user_agent_keeps_base() { let config = HttpClientConfig { - user_agent: "DatabricksJDBCDriverOSS/9.9".to_string(), + user_agent: "DatabricksSQLKernel/9.9".to_string(), ..HttpClientConfig::default() }; let client = DatabricksHttpClient::new(config, default_retry_configs()).unwrap(); - assert_eq!(client.config().user_agent, "DatabricksJDBCDriverOSS/9.9"); + assert_eq!(client.config().user_agent, "DatabricksSQLKernel/9.9"); } #[test] @@ -1223,7 +1226,7 @@ mod tests { let mut ua = "x".repeat(1023); ua.push('é'); // 2 bytes straddling the 1024-byte limit let config = HttpClientConfig { - user_agent: "DatabricksJDBCDriverOSS/9.9".to_string(), + user_agent: "DatabricksSQLKernel/9.9".to_string(), custom_headers: vec![("User-Agent".to_string(), ua)], ..HttpClientConfig::default() }; diff --git a/src/config.rs b/src/config.rs index 6a04ac68..3e88473c 100644 --- a/src/config.rs +++ b/src/config.rs @@ -799,7 +799,7 @@ pub struct HttpConfig { /// removed from this list. This gives the SEA server an accurate /// driver identity for query-source attribution (e.g. the connector's /// `PyDatabricksSqlConnector/x (entry)`), instead of the - /// `DatabricksJDBCDriverOSS/...` base. + /// `DatabricksSQLKernel/...` base. /// /// PRECONDITION: the caller UA's leading prefix MUST be in the /// gateway's `databricks.sqlexecapi.known_driver_prefixes` SAFE flag. @@ -808,7 +808,7 @@ pub struct HttpConfig { /// `startsWith` prefix match of that flag; a non-allow-listed prefix /// is rejected (HTTP 400 / Thrift redirect). `PyDatabricksSqlConnector` /// is allow-listed for this reason. When NO caller `User-Agent` is - /// supplied, the base UA stays `DatabricksJDBCDriverOSS/...` so the + /// supplied, the base UA stays `DatabricksSQLKernel/...` so the /// gate still passes. /// /// **All other headers are sent as supplied.** A `Vec` (not a map)