Skip to content

fix(http): overwrite base User-Agent with caller UA for accurate query-source attribution - #151

Merged
vikrantpuppala merged 1 commit into
mainfrom
feat/kernel-ua-overwrite
Jun 9, 2026
Merged

vikrantpuppala merged 1 commit into
mainfrom
feat/kernel-ua-overwrite

Conversation

@vikrantpuppala

Copy link
Copy Markdown
Collaborator

What

When a wrapper (the Python connector) supplies a User-Agent via a custom header, the kernel now replaces its base UA with the caller's UA verbatim, instead of appending it.

  • Before: DatabricksJDBCDriverOSS/<ver> PyDatabricksSqlConnector/<ver> (entry)
  • After: PyDatabricksSqlConnector/<ver> (entry)

When no caller UA is supplied, the base UA stays DatabricksJDBCDriverOSS/<ver> (unchanged).

Why

The base UA is a JDBC masquerade — the SEA server enables the INLINE_OR_EXTERNAL_LINKS result disposition only for "known drivers", gated on a startsWith prefix match against the databricks.sqlexecapi.known_driver_prefixes SAFE flag (default DatabricksJDBCDriverOSS).

The appended shape matched none of the gateway's QuerySourceHelper.parseUserAgent patterns, so kernel-originated queries were attributed as driver="other", and the connector's identity + any partner user_agent_entry were dropped from query-source attribution entirely.

Overwriting with the clean caller UA lets the gateway's anchored pythonConnectorPattern (^(?i)(PyDatabricksSqlConnector)/...$) match correctly, restoring accurate attribution.

Rollout dependency — MERGE ORDER MATTERS

This is only safe once PyDatabricksSqlConnector is allow-listed in databricks.sqlexecapi.known_driver_prefixes.

Until that flag is ramped where kernel traffic runs, external use_kernel requests asking for INLINE_OR_EXTERNAL_LINKS would fail the known-driver prefix check, returning InlineOrExternalLinksNotSupported (HTTP 400) / Thrift redirect, breaking parallel result fetching.

Required order: flag rollout (allowlist PyDatabricksSqlConnector, ramped) -> then this kernel change.

Also in this PR

  • Hardened the 1 KiB UA truncation to cut on a UTF-8 char boundary (the prior byte slice could panic mid-codepoint).
  • Updated the custom_headers doc comments (struct field + HttpConfig) to document the replace semantics and the allow-list precondition.
  • Added unit tests: replace + folded-out-of-headers, empty-keeps-base, no-UA-keeps-base, oversized-UTF-8-truncation. Updated the existing wiremock test to assert replacement.

Test

cargo test --lib client::http::tests -> 60 passed. cargo clippy --lib --tests clean.

…y-source attribution

The kernel's base User-Agent is `DatabricksJDBCDriverOSS/<ver>` (a JDBC
masquerade so the SEA server enables the INLINE_OR_EXTERNAL_LINKS result
disposition, gated on a `startsWith` prefix match of the
`databricks.sqlexecapi.known_driver_prefixes` flag). A caller-supplied
`User-Agent` (the connector's composed `PyDatabricksSqlConnector/x (entry)`)
was previously *appended* to that base.

The appended shape (`DatabricksJDBCDriverOSS/x PyDatabricksSqlConnector/y (entry)`)
matched none of the gateway's `QuerySourceHelper.parseUserAgent` patterns
and was recorded as driver="other", dropping the connector's identity and
any partner `user_agent_entry` from attribution.

Switch to *replacing* the base UA with the caller UA verbatim, so the SEA
server sees an accurate driver identity (e.g. matches the anchored
`pythonConnectorPattern`). When no caller UA is supplied, the base stays
`DatabricksJDBCDriverOSS/...` so unattributed requests still pass the gate.

PRECONDITION: the caller UA's prefix must be allow-listed in
`databricks.sqlexecapi.known_driver_prefixes`, or external
INLINE_OR_EXTERNAL_LINKS requests are rejected (HTTP 400 / Thrift redirect).
`PyDatabricksSqlConnector` is being added to that flag; this kernel change
must land *after* that flag rollout is ramped.

Also hardens the 1 KiB UA truncation to cut on a UTF-8 char boundary
(the prior byte slice could panic mid-codepoint), and adds unit tests for
replace / empty-keeps-base / no-UA-keeps-base / oversized-truncation.

Signed-off-by: Vikrant Puppala <vikrant.puppala@databricks.com>
@vikrantpuppala
vikrantpuppala added this pull request to the merge queue Jun 9, 2026
Merged via the queue into main with commit 6113402 Jun 9, 2026
14 of 15 checks passed

This branch was previously deployed

1 inactive deployment
azure-prod — 47842b74 Deployed Jun 9, 2026 by vikrantpuppala via v0 TLS (mitmproxy) #161
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants