Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions NEXT_CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ changes go in their respective binding's NEXT_CHANGELOG.

### Changed

- Rust ADBC requests identify themselves as `RustADBCDatabricksDriver/<version>`
with an optional partner entry from `adbc.databricks.user_agent_entry`
(`adbc.spark.user_agent_entry` is a compatibility alias). `User-Agent` in
`adbc.databricks.http.headers` is now rejected; use the dedicated entry option.

### Updated

### Fixed
Expand Down
103 changes: 103 additions & 0 deletions adbc/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions adbc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ tokio = { version = "1", features = ["rt-multi-thread"] }

[dev-dependencies]
adbc_driver_manager = "0.24"
wiremock = "0.6"

[features]
default = []
Expand Down
7 changes: 7 additions & 0 deletions adbc/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ The main database option families are:
| Family | Options |
| --- | --- |
| Namespace | `adbc.databricks.catalog`, `adbc.databricks.schema` |
| Attribution | `adbc.databricks.user_agent_entry` |
| Session | `adbc.databricks.session_conf.<name>`, `adbc.databricks.ssp_ansi_mode`, `adbc.databricks.ssp_timezone`, `adbc.databricks.query_tags` |
| HTTP | request/overall timeouts, idle pool size, retry limits/backoff, response compression, JSON custom headers |
| Proxy | URL, username, password, bypass hosts |
Expand All @@ -106,6 +107,12 @@ The main database option families are:
| Execution | `adbc.databricks.enable_direct_results` (default `true`); set `false` to use `wait_timeout=0s` and status polling |
| Metadata | `adbc.databricks.metadata.escape_catalog_name` |

The optional user-agent entry is appended to the driver-owned identity as
`RustADBCDatabricksDriver/<version> (<entry>)`. Set it through
`adbc.databricks.user_agent_entry`; `User-Agent` is not accepted in the generic
custom-header option. `adbc.spark.user_agent_entry` is accepted as a
compatibility alias; the canonical option wins when both are set.

Proxy credentials must use the dedicated options; URL userinfo is rejected.
Certificate and key options must be supplied as a pair. File-backed credential
and TLS values are read during database initialization.
Expand Down
75 changes: 67 additions & 8 deletions adbc/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ pub(crate) const WAREHOUSE_ID: &str = "adbc.databricks.warehouse_id";
pub(crate) const ACCESS_TOKEN: &str = "adbc.databricks.auth.token";
pub(crate) const CATALOG: &str = "adbc.databricks.catalog";
pub(crate) const SCHEMA: &str = "adbc.databricks.schema";
pub(crate) const USER_AGENT_ENTRY: &str = "adbc.databricks.user_agent_entry";
const USER_AGENT_ENTRY_ALIAS: &str = "adbc.spark.user_agent_entry";
const AUTH_TYPE: &str = "adbc.databricks.auth.type";
const GRANT_TYPE: &str = "adbc.databricks.oauth.grant_type";
const IDENTITY_FEDERATION_CLIENT_ID: &str = "adbc.databricks.identity_federation_client_id";
Expand Down Expand Up @@ -146,6 +148,7 @@ pub(crate) struct DatabaseConfig {
warehouse_id: Option<String>,
catalog: Preferred<String>,
schema: Preferred<String>,
user_agent_entry: Preferred<String>,
auth_mode: Preferred<AuthMode>,
username: Option<String>,
password: Option<SecretString>,
Expand Down Expand Up @@ -195,6 +198,7 @@ impl std::fmt::Debug for DatabaseConfig {
.field("warehouse_id", &self.warehouse_id)
.field("catalog", &self.catalog.get())
.field("schema", &self.schema.get())
.field("user_agent_entry", &self.user_agent_entry.get())
.field("auth_mode", &self.auth_mode.get())
.field("token", &self.token.get())
.field("oauth_client_secret", &self.oauth_client_secret)
Expand Down Expand Up @@ -228,6 +232,7 @@ pub(crate) struct ResolvedConfig {
pub(crate) warehouse_id: Option<String>,
pub(crate) catalog: Option<String>,
pub(crate) schema: Option<String>,
pub(crate) user_agent_entry: Option<String>,
pub(crate) auth: kernel::AuthConfig,
pub(crate) http: kernel::HttpConfig,
pub(crate) proxy: Option<kernel::ProxyConfig>,
Expand Down Expand Up @@ -284,6 +289,12 @@ impl DatabaseConfig {
.set(SecretString::new(string_value(value, key)?), false),
CATALOG => self.catalog.set(string_value(value, key)?, false),
SCHEMA => self.schema.set(string_value(value, key)?, false),
USER_AGENT_ENTRY => self
.user_agent_entry
.set(user_agent_entry(value, key)?, true),
USER_AGENT_ENTRY_ALIAS => self
.user_agent_entry
.set(user_agent_entry(value, key)?, false),
"adbc.connection.catalog" => self.catalog.set(string_value(value, key)?, true),
"adbc.connection.db_schema" => self.schema.set(string_value(value, key)?, true),
AUTH_TYPE => self
Expand Down Expand Up @@ -521,6 +532,7 @@ impl DatabaseConfig {
WAREHOUSE_ID | "databricks.warehouse_id" => self.warehouse_id.clone(),
CATALOG | "adbc.connection.catalog" => self.catalog.get().cloned(),
SCHEMA | "adbc.connection.db_schema" => self.schema.get().cloned(),
USER_AGENT_ENTRY | USER_AGENT_ENTRY_ALIAS => self.user_agent_entry.get().cloned(),
AUTH_TYPE => self
.auth_mode
.get()
Expand Down Expand Up @@ -588,6 +600,7 @@ impl DatabaseConfig {
warehouse_id,
catalog: self.catalog.get().cloned(),
schema: self.schema.get().cloned(),
user_agent_entry: self.user_agent_entry.get().cloned(),
auth,
http: self.http.clone(),
proxy: self.proxy.url.as_ref().map(|_| self.proxy.clone()),
Expand Down Expand Up @@ -900,6 +913,16 @@ fn string_value(value: OptionValue, key: &str) -> Result<String> {
)),
}
}
fn user_agent_entry(value: OptionValue, key: &str) -> Result<String> {
let value = string_value(value, key)?;
if value.chars().any(char::is_control) {

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 — user_agent_entry only rejects char::is_control. Non-ASCII input like partnér or an emoji still passes set_option, but it ends up in config.user_agent and goes to reqwest's ClientBuilder::user_agent, which only accepts visible ASCII. So the bad value is accepted and echoed back by get_option, and the failure only shows up later in new_connection(), as an HTTP client build error that doesn't name adbc.databricks.user_agent_entry. Since this PR already validates the option up front, it should reject anything outside visible ASCII (!(c == ' ' || c.is_ascii_graphic())). That way the user gets InvalidArguments naming the key at set time. Also worth adding a test case with a non-ASCII value.

return Err(adbc_error(
format!("option {key:?} must not contain control characters"),
Status::InvalidArguments,
));
}
Ok(value)
}
fn bytes_value(value: OptionValue, key: &str) -> Result<Vec<u8>> {
match value {
OptionValue::Bytes(value) => Ok(value),
Expand Down Expand Up @@ -1079,6 +1102,7 @@ fn parse_headers(value: &str) -> Result<Vec<(String, String)>> {
"authorization"
| "host"
| "content-length"
| "user-agent"
| "x-databricks-org-id"
| "x-request-id"
| "traceparent"
Expand Down Expand Up @@ -1627,15 +1651,45 @@ mod tests {

#[test]
fn headers_reject_security_sensitive_names() {
for name in ["Authorization", "User-Agent", "user-agent"] {
let mut config = DatabaseConfig::default();
let value = format!(r#"[{{"name":"{name}","value":"secret"}}]"#);
let error = config
.set_option("adbc.databricks.http.headers", value.into())
.unwrap_err();
assert_eq!(error.status, Status::InvalidArguments);
assert!(!error.message.contains("secret"));
}
}

#[test]
fn user_agent_entry_round_trips() {
let mut config = DatabaseConfig::default();
let error = config
.set_option(
"adbc.databricks.http.headers",
r#"[{"name":"Authorization","value":"secret"}]"#.into(),
)
.unwrap_err();
assert_eq!(error.status, Status::InvalidArguments);
assert!(!error.message.contains("secret"));
set(&mut config, USER_AGENT_ENTRY_ALIAS, "legacy-entry");
set(&mut config, USER_AGENT_ENTRY, "partner+product");
for key in [USER_AGENT_ENTRY, USER_AGENT_ENTRY_ALIAS] {
assert_eq!(config.get_string(key).unwrap(), "partner+product");
}

let mut reverse = DatabaseConfig::default();
set(&mut reverse, USER_AGENT_ENTRY, "partner+product");
set(&mut reverse, USER_AGENT_ENTRY_ALIAS, "legacy-entry");
assert_eq!(
reverse.get_string(USER_AGENT_ENTRY).unwrap(),
"partner+product"
);
}

#[test]
fn user_agent_entry_rejects_control_characters() {
for key in [USER_AGENT_ENTRY, USER_AGENT_ENTRY_ALIAS] {
for value in ["partner\nproduct", "partner\rproduct", "partner\0product"] {
let mut config = DatabaseConfig::default();
let error = config.set_option(key, value.into()).unwrap_err();
assert_eq!(error.status, Status::InvalidArguments, "{key}: {value:?}");
assert!(error.message.contains(key), "{key}: {value:?}");
}
}
}

#[test]
Expand All @@ -1654,9 +1708,14 @@ mod tests {
"adbc.databricks.http.headers",
r#"[{"name":"x-databricks-test","value":"sentinel"}]"#,
);
set(&mut config, USER_AGENT_ENTRY, "partner+product");

let resolved = config.resolve().unwrap();
assert_eq!(resolved.http.pool_max_idle_per_host, 37);
assert_eq!(
resolved.user_agent_entry.as_deref(),
Some("partner+product")
);
assert_eq!(
resolved.http.custom_headers,
vec![("x-databricks-test".into(), "sentinel".into())]
Expand Down
Loading
Loading