Repository navigation
feat(config): accept a connection port and fold it into the host - #505
Conversation
Bindings each folded a port into the host string themselves, with different rules. The kernel now does it once. ConnectionConfig::with_port applies a port (0 and the scheme default are no-ops and are not validated). Anything else is written as scheme://host:port. It is rejected with InvalidArgument for userinfo, an empty host, a path, query or fragment, or an embedded port outside 1-65535. An embedded port already in the host wins, with a warning when it differs. Error and log text redact credentials. The C ABI gains kernel_session_config_set_port. It validates eagerly against the host set so far, and the host setters re-check it, so a bad combination fails at config time. pyo3 Session gains an optional port kwarg, and napi ConnectionOptions gains an optional port field. Both validate the value type and range before any network I/O. Connection telemetry reports the applied port as host_info.port. Signed-off-by: cat23123 <58714163+cat23123@users.noreply.github.com> Co-authored-by: Isaac <no-reply@databricks.com>
There was a problem hiding this comment.
🔀 Cross-reviewed: two independent reviews (Claude Opus 5.5 · GPT-6.1 Sol), checked by a judge model (Claude Sonnet 5.5).
Verdict: 2 Low · 2 Nit
Looks good, with 3 low concerns. The fold rules, the eager C ABI checks, credential redaction and the binding wiring are all consistent, and tests at each tier cover them.
This overview is Claude Opus 5.5's initial take; some of its points were set aside by the cross-check judge and GPT-6.1 Sol added findings it doesn't mention — see the findings below.
Other findings
- ⚪ Nit — The comment says the reported port is never a default, but
with_port(443)recordsSome(443)and a test asserts this. Reword the comment to say only an explicitly applied port is reported. (Found by Claude Opus 5.5 · confirmed by the judge) - ⚪ Nit — Catching any
Exceptionlets the test pass on an unrelated failure, so it does not show the promised InvalidArgument rejection. Requirek.KernelError, assert its code is InvalidArgument, and keep the redaction assertion. (Found by GPT-6.1 Sol · confirmed by the judge)
🔀 1 finding considered and dismissed by the judge
- 🔵 Low
pyo3/src/session.rs:160— Wrong-typeportvalues (True,8443.0,"8443") raiseValueError, but Python convention, and PyO3's own extraction, raiseTypeErrorfor a wrong type.
Judge's evidence:return Err(pyo3::exceptions::PyValueError::new_err(INVALID));
URL parsers treat `\` as a path separator for http(s), so `https://h\path` with a port was folded to `https://h\path:8443` and connected to the default port. `\` now ends the authority like `/`, so such a host is rejected with a port. With the default port, a host with userinfo is left unvalidated, and a `:` in the userinfo made the reported telemetry port fall back to 443. The effective port is now read after the last `@`. Also reword the telemetry port comment (an explicitly applied default port is reported), and have the pyo3 credential test require a KernelError with code InvalidArgument instead of any exception. Signed-off-by: cat23123 <58714163+cat23123@users.noreply.github.com> Co-authored-by: Isaac <no-reply@databricks.com>
The driver no longer folds `port` into the host. It passes the host through and sends `port` to the napi binding, which folds it (kernel databricks/databricks-sql-kernel#505, KERNEL_REV b5aac45d54bb4842b7e04dd7fbf2368216b6de4e). The driver keeps `explicitPort()` validation (falsy means default, numeric strings accepted, invalid throws HiveDriverError) and the `https: false` scheme handling (sends `http://host`). It omits `port` when it is the default for the scheme it sends (443 over HTTPS, 80 over HTTP), since the kernel treats the default as a no-op. Removed from the driver: embedded-port detection and conflict warning, IPv6 bracketing, userinfo handling, redactHost, and the path checks. native/kernel/index.d.ts regenerated with `npm run build:native` against KERNEL_REV; only the typed `port` field changed. Signed-off-by: Cathleen Yan <58714163+cathleeny@users.noreply.github.com> Co-authored-by: Isaac <no-reply@databricks.com>
There was a problem hiding this comment.
🔀 Cross-reviewed: two independent reviews (Claude Opus 5.5 · GPT-6.1 Sol), checked by a judge model (Claude Sonnet 5.5).
Verdict: 1 Low
Looks good, with 1 low concern. The port-folding rules live in one place and are covered by tests, credential redaction is careful, and the C ABI, pyo3 and napi surfaces were updated together.
There was a problem hiding this comment.
🔀 Cross-reviewed: two independent reviews (Claude Opus 5.5 · GPT-6.1 Sol), checked by a judge model (Claude Sonnet 5.5).
Verdict: 1 Low
Looks good, with 1 low concern: there is no end-to-end test that the folded port is used for the connection. The folding rules, credential redaction, the C ABI's eager validation in either setter order, and the binding range checks all match across Rust, C, pyo3 and napi.
pyo3 and napi each range-checked their own port value with their own message. The kernel now owns the rule: a binding maps its language's value onto `config::PortValue` (an integer, a float, or unsupported) and `config::port_from_value` decides, so `8443.5`, `NaN`, out-of-range values and non-numbers are rejected the same way everywhere. pyo3 still raises ValueError like its other argument checks, and napi still gives InvalidArgument; both now carry the kernel's message. The C ABI already takes a `uint16_t`, so it is unchanged. Signed-off-by: cat23123 <58714163+cat23123@users.noreply.github.com> Co-authored-by: Isaac <no-reply@databricks.com>
There was a problem hiding this comment.
🔀 Cross-reviewed: two independent reviews (Claude Opus 5.5 · GPT-6.1 Sol), checked by a judge model (Claude Sonnet 5.5).
Verdict: 3 Low
Looks good, with 1 low concern. Port folding is centralised with consistent validation and redaction. The C ABI checks are eager and leave the config unchanged on error, and the bindings pass their values to the shared port_from_value.
This overview is Claude Opus 5.5's initial take; GPT-6.1 Sol added findings it doesn't mention — see the findings below.
… ABI port Replace the hand-written authority parsing (split_authority, parse_embedded_port, IPv6 bracketing, redact_host) with the URL parser the transport already uses. Behavior changes for a non-default port: an IPv6 address must be bracketed, and a default port written in the host (`h:443`) counts as no port, so the requested port is used. Errors and the conflicting-port warning no longer repeat the host, so a credential or token in it never reaches error or log text; the warning now goes through klog like other kernel warnings. kernel_session_config_set_port takes an int64_t, so C callers pass their own integer as is and the kernel range-checks it with port_from_value. Docs updated, and redundant unit tests removed. Signed-off-by: cat23123 <58714163+cat23123@users.noreply.github.com> Co-authored-by: Isaac <no-reply@databricks.com>
There was a problem hiding this comment.
🔀 Cross-reviewed: two independent reviews (Claude Opus 5.5 · GPT-6.1 Sol), checked by a judge model (Claude Sonnet 5.5).
Verdict: 1 Low · 1 Nit
Looks good, with 1 low concern. Port folding, the eager C ABI validation and the binding mappings are consistent and well tested. Nit: the port paragraph in the pyo3 Session docstring has one overlong line (around 'logs a warning when they differ. A bad host/port…') that should be re-wrapped.
This overview is Claude Opus 5.5's initial take; GPT-6.1 Sol added findings it doesn't mention — see the findings below.
Other findings
- ⚪ Nit — The public
PortValueenum is exhaustive, unlike the module's other public enums, so adding a variant later would break downstream code. Mark it#[non_exhaustive]. Bindings only construct its variants, so this costs them nothing. (Found by Claude Opus 5.5 · confirmed by the judge)
…lisation The path check ran on the parsed URL, which normalises dot segments, so `https://h/private/..` passed with a custom port and lost its path. The check now runs on the raw text after `scheme://`: any `/`, `?`, `#` or `\` is a path, query or fragment. Also mark `PortValue` `#[non_exhaustive]` and re-wrap the pyo3 `Session` docstring. Signed-off-by: cat23123 <58714163+cat23123@users.noreply.github.com> Co-authored-by: Isaac <no-reply@databricks.com>
There was a problem hiding this comment.
🔀 Cross-reviewed: two independent reviews (Claude Opus 5.5 · GPT-6.1 Sol), checked by a judge model (Claude Sonnet 5.5).
Verdict: 1 Nit
Looks good: 2 low concerns. The fold rules, eager validation in the C ABI, credential-safe error text and binding mappings are consistent and well tested at the unit level.
This overview is Claude Opus 5.5's initial take; some of its points were set aside by the cross-check judge — see the findings below.
Other findings
- ⚪ Nit —
applied_portis crate-private and set only inwith_port, buthostis a public field, so a Rust caller who editshostafterwards makes telemetry report a stale port. Compute the port fromhostwhen telemetry is built, or document thathostmust not change afterwith_port. (Found by Claude Opus 5.5 · confirmed by the judge)
🔀 1 finding considered and dismissed by the judge
- 🔵 Low
src/c_abi/session.rs:1762— Every new test checks the foldedhoststring, but no test confirms that a session built this way actually sends requests tohost:port. Add a wiremock test t
Judge's evidence:let connection = connection_config(connection, port)?;
vuanhphung
left a comment
There was a problem hiding this comment.
(src/auth/oauth/azure.rs:59):
Not in the diff, but this PR makes it reachable: host_authority keeps :port, so https://adb-1.dev.azuredatabricks.net:8443 fails the .dev.azuredatabricks.net suffix check and Azure SP M2M asks for the prod app's .default scope on dev/staging. Could you strip the port here (e.g. Url::parse(..).host_str(), as federation's host_of does) and add a :8443 case to effective_app_id_is_host_specific?
…e dev hosts with a port Folding a port no longer lowercases or normalises the host: the port is appended to the host as written, and a host with its own non-default port is returned unchanged. This keeps the U2M token cache key the same as the drivers' own folding produced. The Azure dev/staging app id lookup now strips the port before the suffix match, so `https://adb-1.dev.azuredatabricks.net:8443` gets the dev scope. Signed-off-by: cat23123 <58714163+cat23123@users.noreply.github.com> Co-authored-by: Isaac <no-reply@databricks.com>
|
@vuanhphung re |
There was a problem hiding this comment.
🔀 Cross-reviewed: two independent reviews (Claude Opus 5.5 · GPT-6.1 Sol), checked by a judge model (Claude Sonnet 5.5).
Verdict: 1 Low · 1 Nit
Looks good, with 2 low concerns. The port folding, the eager C ABI checks in either call order, redacted error text and the per-binding mapping are consistent and well tested.
This overview is Claude Opus 5.5's initial take; some of its points were set aside by the cross-check judge and GPT-6.1 Sol added findings it doesn't mention — see the findings below.
Other findings
- ⚪ Nit —
applied_portis computed once inwith_port, whilehostis a public field. Reassigninghostafterwards would make telemetry report a stale port. This is unlikely in practice. Derive the port from the final host when building telemetry, or document the constraint. (Found by Claude Opus 5.5 · confirmed by the judge)
🔀 1 finding considered and dismissed by the judge
- 🔵 Low
pyo3/src/session.rs:156—parse_portonly accepts exactintinstances, so integer-like values such asnumpy.int64raiseValueErroreven though Python treats them as ints via__i<br>Judge's evidence:/// an 'int' is an integer, and anything else (including 'bool', an 'int'`
…host The URL parser ignores trailing spaces and control characters, so a host such as `https://h ` passed validation and then became `https://h :8443`. Trim them before appending the port. Signed-off-by: cat23123 <58714163+cat23123@users.noreply.github.com> Co-authored-by: Isaac <no-reply@databricks.com>
There was a problem hiding this comment.
🔀 Cross-reviewed: two independent reviews (Claude Opus 5.5 · GPT-6.1 Sol), checked by a judge model (Claude Sonnet 5.5).
Verdict: 1 Low
Looks good: 3 low concerns, no blockers. The folding rules, the eager C ABI validation and the redaction of the host from errors are consistent across the Rust API, C ABI, pyo3 and napi, and each has tests.
This overview is Claude Opus 5.5's initial take; some of its points were set aside by the cross-check judge and GPT-6.1 Sol added findings it doesn't mention — see the findings below.
🔀 3 findings considered and dismissed by the judge
- 🔵 Low
src/telemetry/runtime.rs:413—with_port(443)onhttps://hsetsapplied_port = Some(443), so telemetry reports a port that the docs call 'treated as unset'. BecauseConnectionConfig.ho<br>Judge's evidence:port: connection.applied_port.map(i32::from),` - 🔵 Low
src/config.rs:152— The tests only compare the foldedhoststring. Nothing checks that a session built withwith_portactually connects to that port. Add a wiremock test that p
Judge's evidence:assert_eq!(c.host, "https://h:8443"); - 🔵 Low
pyo3/src/session.rs:157—parse_portonly accepts exactPyIntinstances, sonumpy.int64(8443)or any other object that implements__index__is reported asValueErrorwith the m
Judge's evidence:if obj.is_instance_of::<PyBool>() || !obj.is_instance_of::<PyInt>() {
A host with its own non-default port was returned untrimmed, so `https://h:9000 ` kept the space. Trim once before validation so both branches use the trimmed host. Signed-off-by: cat23123 <58714163+cat23123@users.noreply.github.com> Co-authored-by: Isaac <no-reply@databricks.com>
There was a problem hiding this comment.
🔀 Cross-reviewed: two independent reviews (Claude Opus 5.5 · GPT-6.1 Sol), checked by a judge model (Claude Sonnet 5.5).
Verdict: 1 Low
Looks good, with 2 low concerns. Port folding, eager validation in the C ABI and the binding mappings all hold up. Errors don't repeat the host, so credentials stay out of error text. Ordering is covered in both directions.
This overview is Claude Opus 5.5's initial take; some of its points were set aside by the cross-check judge — see the findings below.
🔀 1 finding considered and dismissed by the judge
- 🔵 Low
src/auth/oauth/azure.rs:61—host_namenow goes throughhost_of(Url::parse), so a host the parser rejects becomes "" and quietly falls back to the prod Azure app id. The old string-s
Judge's evidence:super::federation::host_of(host) .map(|name| name.trim_end_matches('.').to_owned()) .unwrap_or_default()
Summary
Adds a connection
portto the kernel so drivers stop folding a port into the host string themselves. Today Python, Node, Go and ODBC each do this with slightly different rules. Drivers now just pass the port.ConnectionConfig::with_port(self, port: u16) -> Result<Self>.kernel_session_config_set_port(config, int64_t port), for Go and ODBC. It takes a wide integer so a caller passes its own value as is, and the kernel range-checks it. Validation is eager: a bad value or host/port combination fails at config time.Session(..., port=None). napi:ConnectionOptions.port?: number. Each maps its language's value ontoconfig::PortValue, and one kernel function,config::port_from_value, decides: an integer in0..=65535, and for a JS number also whole and finite.host_info.port.Rules (
fold_host_portinsrc/config.rs, on the transport's own URL parser,reqwest::Url)0, or the scheme's default (443 for https, 80 for http): the host is unchanged and not validated, as today.scheme://host:port.h:443) counts as no port.InvalidArgumentfor credentials, a path, query or fragment, or a host the parser rejects (empty, bad port, IPv6 without brackets).Testing
cargo test,cargo clippy --all-targets -D warnings(also withtls-rustls),cargo fmt --checkandmake c-abi-testpass.cargo testand napicargo test --features dyn-symbolspass.:8443to the workspace's:443.Follow-up
The Python (databricks-sql-python#1071), Node (databricks-sql-nodejs#636) and Go (databricks-sql-go#581) port PRs pass their port straight to this input. ODBC's
FoldPortIntoHostcan move the same way.This pull request and its description were written by Isaac.