diff --git a/CONNECTION_PARAMETERS.md b/CONNECTION_PARAMETERS.md index e3242acc..2d312a49 100644 --- a/CONNECTION_PARAMETERS.md +++ b/CONNECTION_PARAMETERS.md @@ -195,33 +195,14 @@ Default: `SeaRest`. `session_conf: HashMap` carries **server-bound** SQL / Spark configuration, forwarded to SEA `session_confs` and applied for -every statement on the session. Keys are matched **case-insensitively** -against an allowlist and **uppercased** before being sent; keys not in -the allowlist are **dropped with a warning**. +every statement on the session. The kernel does not validate, +normalize, uppercase, or drop server-bound keys; caller-supplied entries +are forwarded unchanged. Server-side validation errors, if any, come +from Databricks. -Allowlisted keys (see the [Databricks SQL configuration-parameters +See the [Databricks SQL configuration-parameters reference](https://docs.databricks.com/aws/en/sql/language-manual/sql-ref-parameters) -for per-parameter meaning and accepted values): - -| Key | Notes | -|-----|-------| -| `ANSI_MODE` | Enable/disable ANSI SQL behaviour. | -| `COLLATION` | Default collation. | -| `ENABLE_PHOTON` | Toggle the Photon engine. | -| `LEGACY_TIME_PARSER_POLICY` | Legacy datetime parsing behaviour. | -| `MAX_FILE_PARTITION_BYTES` | Max bytes per file partition. | -| `QUERY_TAGS` | Query tags (comma-separated `key:value`). | -| `READ_ONLY_EXTERNAL_METASTORE` | Treat the external metastore as read-only. | -| `STATEMENT_TIMEOUT` | Server-side per-statement timeout (seconds). This is the real query-timeout knob. | -| `TIMEZONE` | Session time zone, e.g. `UTC`. | -| `USE_CACHED_RESULT` | Toggle result caching. | - -Dotted `spark.*` confs are matched case-insensitively but sent -**verbatim** (Spark conf keys are case-sensitive): - -| Key | Notes | -|-----|-------| -| `spark.sql.thriftserver.metadata.metricview.enabled` | When `"true"`, `SHOW TABLES` returns `METRIC_VIEW` rows and `getColumns` surfaces `measure` columns. Mirrors JDBC `EnableMetricViewMetadata` (default off). | +for supported SQL parameter names and accepted values. Boolean-valued keys should use the exact strings `"true"` / `"false"`; the kernel does not pre-validate values and forwards them as-is. @@ -231,11 +212,10 @@ the kernel does not pre-validate values and forwards them as-is. Some keys carried in the same `session_conf` map are **client-side** tuning knobs: the kernel reads them at session creation, applies them to the typed config above, and then strips them so they never reach the SEA -wire (they are deliberately *not* in the allowlist). They exist so C ABI -(Go / ODBC) consumers can set them through the existing -`session_conf` entry point without a dedicated symbol. +wire. They exist so C ABI (Go / ODBC) consumers can set them through the +existing `session_conf` entry point without a dedicated symbol. -Each key mirrors a field of [`ResultConfig`](#resultconfig--result-handling-optional) and is matched **case-insensitively**. Boolean keys accept exactly `"true"` / `"false"` (case-insensitive); the integer window keys require a positive integer. An unrecognised value is rejected with `InvalidArgument` at session creation. +Each key mirrors a field of [`ResultConfig`](#resultconfig--result-handling-optional) and is matched **case-insensitively**. Boolean keys accept exactly `"true"` / `"false"` (case-insensitive); the integer window keys require a positive integer. When supplied through `session_conf`, an invalid value is ignored with a warning and the key is still stripped from the wire. The typed client-conf setters reject invalid values with `InvalidArgument`. | Key | Description | Default | |-----|-------------|---------| diff --git a/include/databricks_kernel.h b/include/databricks_kernel.h index 001f4c17..4817ee23 100644 --- a/include/databricks_kernel.h +++ b/include/databricks_kernel.h @@ -317,7 +317,7 @@ kernel_session_config_set_oauth_scopes(KernelSessionConfig* config, const char* scopes); /* Add (or overwrite) one session-conf entry. Keys are normally server SET - * parameters forwarded on the SEA wire (allowlist-filtered). A small set of + * parameters forwarded unchanged on the SEA wire. A small set of * reserved keys are instead CLIENT-ONLY: they tune the kernel locally, are * consumed before session creation, and NEVER reach the wire. Client-only keys * (matched case-insensitively): diff --git a/src/c_abi/session.rs b/src/c_abi/session.rs index a1944c9b..c80d6bb8 100644 --- a/src/c_abi/session.rs +++ b/src/c_abi/session.rs @@ -981,9 +981,8 @@ pub unsafe extern "C" fn kernel_init_logging_callback( } } -/// Add (or overwrite) one server-bound session-conf entry. Unknown keys -/// are filtered against the kernel allowlist at `open()` time, matching -/// the Rust-crate path. +/// Add (or overwrite) one server-bound session-conf entry. Entries pass +/// through unchanged at `open()` time, matching the Rust-crate path. /// /// # Safety /// `config` must be a live config handle; `key` / `value` must be diff --git a/src/config.rs b/src/config.rs index 21e35bdc..4ec10bfa 100644 --- a/src/config.rs +++ b/src/config.rs @@ -1245,9 +1245,9 @@ impl ResultConfig { /// /// Unlike the server `session_conf` map, these knobs are **client-side** /// and never reach the SEA wire — so this deliberately does NOT accept - /// server conf keys (`ANSI_MODE`, `TIMEZONE`, …); those go through - /// [`filter_session_conf`] instead. Keeping the two channels separate is - /// the point (see #226). + /// server conf keys (`ANSI_MODE`, `TIMEZONE`, …); those remain in + /// `session_conf` and pass through unchanged. Keeping the two channels + /// separate is the point (see #226). /// /// # Errors /// Returns `ErrorCode::InvalidArgument` when: @@ -1482,9 +1482,7 @@ pub struct SessionConfig { /// Thrift `configuration`. Typed sub-structs above translate /// the *client-side* knobs; this map carries everything else. /// - /// The kernel passes user-supplied entries through unchanged, - /// after filtering them against the kernel allowlist (see - /// [`filter_session_conf`] / [`SESSION_CONF_ALLOWLIST`]). The + /// The kernel passes user-supplied entries through unchanged. The /// kernel does not synthesise any entries here from typed /// client-side knobs. /// @@ -1494,8 +1492,9 @@ pub struct SessionConfig { /// ExecuteStatement with `CONFIG_NOT_AVAILABLE`, issue #196). /// CloudFetch-disable is instead applied per-statement via the SEA /// `disposition` field, matching the JDBC / Thrift reference - /// drivers. A stray caller-supplied `can_cloud_download` is dropped - /// by [`filter_session_conf`] (it is not allowlisted). + /// drivers. A caller-supplied `can_cloud_download` is still forwarded + /// unchanged because the kernel does not validate server-bound + /// `session_conf` keys. /// /// **Boolean-valued conf keys** should use the exact strings /// `"true"` / `"false"`. SEA accepts these literally; other forms @@ -1516,96 +1515,6 @@ pub struct SessionConfig { pub transport: Option, } -// ─── session_conf allowlist ───────────────────────────────────────────────── - -/// Known session-conf keys, sourced from -/// -/// plus the additional keys the Java driver accepts (`ENABLE_PHOTON`, -/// `QUERY_TAGS`). Keys are matched case-insensitively against this list -/// and uppercased before being sent. -pub(crate) const SESSION_CONF_ALLOWLIST: &[&str] = &[ - "ANSI_MODE", - // NOTE: `CAN_CLOUD_DOWNLOAD` is deliberately NOT allowlisted. SEA has - // no such session conf — it is accepted at CreateSession but rejected - // at the first ExecuteStatement with `CONFIG_NOT_AVAILABLE` (issue - // #196). CloudFetch-disable is expressed per-statement via the SEA - // `disposition` (see `SeaRestTransport::call_execute_api` and - // `TransportConfig::cloudfetch_enabled`), matching both the JDBC and - // Thrift reference drivers. A stray caller-supplied `can_cloud_download` - // is therefore dropped by `filter_session_conf` (with a warn) rather - // than forwarded to the wire where it would break the session. - "COLLATION", - "ENABLE_PHOTON", - "LEGACY_TIME_PARSER_POLICY", - "MAX_FILE_PARTITION_BYTES", - "QUERY_TAGS", - "READ_ONLY_EXTERNAL_METASTORE", - "STATEMENT_TIMEOUT", - "TIMEZONE", - "USE_CACHED_RESULT", -]; - -/// Case-sensitive session-conf keys that must be sent **verbatim** -/// rather than uppercased. These are dotted `spark.*` Spark confs (as -/// opposed to the short SET-style SQL parameters in -/// [`SESSION_CONF_ALLOWLIST`], which Databricks echoes uppercase). -/// Spark stores `SQLConf` entries under their exact registered -/// lowercase-dotted key, so uppercasing would address the wrong entry. -/// -/// Each tuple is `(uppercased_lookup_key, canonical_verbatim_key)`: -/// callers are matched case-insensitively (via the uppercased lookup) -/// but the canonical form is what we send on the wire. -/// -/// `spark.sql.thriftserver.metadata.metricview.enabled` enables UC -/// Metric View metadata — when set to `"true"`, `SHOW TABLES` -/// (`Metadata::tables`) returns `METRIC_VIEW` rows and `getColumns` -/// surfaces `measure` columns. Opt-in: the connector sets it from its -/// `enable_metric_view_metadata` kwarg (default off), matching the -/// JDBC driver's `EnableMetricViewMetadata` (default `0`). The kernel -/// already lists `METRIC_VIEW` among its table types; this lets the -/// enabling conf through so the server actually emits the rows. -pub(crate) const SESSION_CONF_CASE_SENSITIVE_ALLOWLIST: &[(&str, &str)] = &[( - "SPARK.SQL.THRIFTSERVER.METADATA.METRICVIEW.ENABLED", - "spark.sql.thriftserver.metadata.metricview.enabled", -)]; - -/// Filter a caller-supplied `session_conf` map against the allowlists. -/// Unknown keys are dropped with a `tracing::warn!`. -/// -/// - Keys in [`SESSION_CONF_ALLOWLIST`] are normalized to **uppercase** -/// (the server echoes uppercase for these SET-style params, so -/// SET-readback matches). -/// - Keys in [`SESSION_CONF_CASE_SENSITIVE_ALLOWLIST`] (dotted -/// `spark.*` confs) are matched case-insensitively but emitted in -/// their **canonical verbatim** form — Spark conf keys are -/// case-sensitive and must not be uppercased. -pub(crate) fn filter_session_conf( - raw: std::collections::HashMap, -) -> std::collections::HashMap { - use std::collections::HashMap; - let mut out: HashMap = HashMap::with_capacity(raw.len()); - for (k, v) in raw { - let upper = k.to_ascii_uppercase(); - if SESSION_CONF_ALLOWLIST.contains(&upper.as_str()) { - out.insert(upper, v); - } else if let Some((_, canonical)) = SESSION_CONF_CASE_SENSITIVE_ALLOWLIST - .iter() - .find(|(lookup, _)| *lookup == upper.as_str()) - { - // Send the canonical lowercase-dotted form verbatim, not - // the caller's casing and not uppercased. - out.insert((*canonical).to_string(), v); - } else { - crate::klog::warn!( - key = %k, - "dropping unknown session_conf key (not in kernel allowlist); \ - see https://docs.databricks.com/aws/en/sql/language-manual/sql-ref-parameters" - ); - } - } - out -} - #[cfg(test)] mod tests { use super::*; @@ -1713,120 +1622,6 @@ mod tests { assert_eq!(cfg.resolve(), None); } - // ─── session_conf allowlist ──────────────────────────────────── - - #[test] - fn session_conf_filter_keeps_known_keys_uppercased() { - let mut raw = std::collections::HashMap::new(); - raw.insert("use_cached_result".to_string(), "false".to_string()); - raw.insert("ANSI_MODE".to_string(), "true".to_string()); - let out = filter_session_conf(raw); - assert_eq!( - out.get("USE_CACHED_RESULT").map(String::as_str), - Some("false") - ); - assert_eq!(out.get("ANSI_MODE").map(String::as_str), Some("true")); - assert_eq!(out.len(), 2); - } - - #[test] - fn session_conf_filter_drops_unknown_keys() { - let mut raw = std::collections::HashMap::new(); - raw.insert("ANSI_MOD".to_string(), "true".to_string()); // typo - raw.insert("NOT_A_REAL_PARAM".to_string(), "x".to_string()); - raw.insert("TIMEZONE".to_string(), "UTC".to_string()); - let out = filter_session_conf(raw); - assert_eq!(out.len(), 1); - assert_eq!(out.get("TIMEZONE").map(String::as_str), Some("UTC")); - } - - #[test] - fn session_conf_filter_drops_can_cloud_download() { - // Regression tripwire for issue #196: `can_cloud_download` is NOT a - // valid SEA session conf (the server rejects it at ExecuteStatement - // with CONFIG_NOT_AVAILABLE). It must be dropped by the allowlist - // filter — never forwarded to the wire — regardless of casing. - // CloudFetch-disable is applied per-statement via the SEA - // disposition instead. If someone re-adds it to the allowlist, this - // test flips RED. - for spelling in [ - "can_cloud_download", - "CAN_CLOUD_DOWNLOAD", - "Can_Cloud_Download", - ] { - let mut raw = std::collections::HashMap::new(); - raw.insert(spelling.to_string(), "false".to_string()); - let out = filter_session_conf(raw); - assert!( - out.is_empty(), - "can_cloud_download ({spelling:?}) must be dropped, got {out:?}" - ); - } - } - - #[test] - fn session_conf_filter_passes_metricview_conf_verbatim() { - // The metric-view conf is a dotted spark.* key: it must survive - // the allowlist AND be emitted lowercase-verbatim (NOT - // uppercased like the SET-style params), because Spark conf - // keys are case-sensitive. - let mut raw = std::collections::HashMap::new(); - raw.insert( - "spark.sql.thriftserver.metadata.metricview.enabled".to_string(), - "true".to_string(), - ); - let out = filter_session_conf(raw); - assert_eq!( - out.get("spark.sql.thriftserver.metadata.metricview.enabled") - .map(String::as_str), - Some("true"), - ); - // It must NOT have been uppercased. - assert!(!out.contains_key("SPARK.SQL.THRIFTSERVER.METADATA.METRICVIEW.ENABLED")); - assert_eq!(out.len(), 1); - } - - #[test] - fn session_conf_filter_metricview_match_is_case_insensitive() { - // A caller passing the key in any casing is recognised, but the - // canonical lowercase form is always what we send. - let mut raw = std::collections::HashMap::new(); - raw.insert( - "SPARK.SQL.THRIFTSERVER.METADATA.METRICVIEW.ENABLED".to_string(), - "true".to_string(), - ); - let out = filter_session_conf(raw); - assert_eq!( - out.get("spark.sql.thriftserver.metadata.metricview.enabled") - .map(String::as_str), - Some("true"), - ); - assert_eq!(out.len(), 1); - } - - #[test] - fn session_conf_allowlist_covers_jdbc_set() { - // Parity check: every key the Java driver accepts must be - // accepted here too (we add COLLATION which JDBC currently - // lacks but the docs list). - for jdbc_key in [ - "ANSI_MODE", - "ENABLE_PHOTON", - "LEGACY_TIME_PARSER_POLICY", - "MAX_FILE_PARTITION_BYTES", - "READ_ONLY_EXTERNAL_METASTORE", - "STATEMENT_TIMEOUT", - "TIMEZONE", - "USE_CACHED_RESULT", - "QUERY_TAGS", - ] { - assert!( - SESSION_CONF_ALLOWLIST.contains(&jdbc_key), - "missing JDBC-compatible key: {jdbc_key}" - ); - } - } - // ─── AuthConfig validating constructors ─────────────────────── #[test] diff --git a/src/session.rs b/src/session.rs index 1f990c85..ae7f1de6 100644 --- a/src/session.rs +++ b/src/session.rs @@ -301,7 +301,8 @@ impl Session { // Fold client-only result knobs (e.g. cloudfetch_max_chunks_in_memory) // carried in session_conf into the typed ResultConfig and strip them // from session_conf, before either the reader factory reads - // config.result (below) or filter_session_conf runs on the wire body. + // config.result (below) or the remaining server-bound session_conf + // is sent on the wire. apply_client_result_overrides(&mut config); let host = config.connection.host.clone(); @@ -363,18 +364,15 @@ impl Session { ); // CloudFetch-disable is expressed per-statement via the SEA - // `disposition` (threaded onto `TransportConfig` above), NOT via a - // session conf: SEA has no `CAN_CLOUD_DOWNLOAD` conf — sending one - // is accepted at CreateSession but rejected at the first - // ExecuteStatement with `CONFIG_NOT_AVAILABLE` (issue #196). So the - // user's `session_conf` flows to CreateSession untouched; the - // kernel synthesises nothing here. + // `disposition` (threaded onto `TransportConfig` above), not via a + // session conf. The kernel synthesises no session_conf entries; + // caller-supplied server-bound entries pass through unchanged. let create_started = Instant::now(); let session_info = transport .create_session( defaults.catalog.as_deref(), defaults.schema.as_deref(), - crate::config::filter_session_conf(config.session_conf.clone()), + config.session_conf.clone(), ) .await?; let create_elapsed = create_started.elapsed(); @@ -1077,8 +1075,7 @@ fn build_retry_configs_for_session( /// `cloudfetch_max_chunks_in_memory` in there and have it applied. Any key /// recognised by [`ResultConfig::apply_client_conf`] (see /// [`ClientConfKey`](crate::config::ClientConfKey)) is consumed here; -/// unrecognised keys are left for [`filter_session_conf`] to handle as -/// server confs. +/// unrecognised keys are left in `session_conf` as server-bound confs. /// /// **Best-effort, never fatal.** A recognised key with an unparseable value /// is logged at `warn` and skipped (the field keeps its current value) @@ -1087,7 +1084,7 @@ fn build_retry_configs_for_session( /// *does* reject bad values, because there the caller asked for that key /// explicitly; here the key is ambient in a mixed bag.) Every recognised /// key is removed regardless of parse outcome, so no client-only key -/// survives into `filter_session_conf` / the wire. +/// survives onto the wire. /// /// Matched case-insensitively. If a host sets two spellings of the same key /// differing only in case, the lexicographically-last spelling wins @@ -1684,7 +1681,7 @@ mod retry_config_tests { "cloudfetch_max_chunks_in_memory".to_string(), "200".to_string(), ), - // A benign, allowlisted server param that must NOT be removed. + // A benign server param that must NOT be removed. ("ansi_mode".to_string(), "true".to_string()), ])); apply_client_result_overrides(&mut cfg); @@ -1826,24 +1823,6 @@ mod retry_config_tests { ); assert_eq!(cfg.session_conf.len(), 1, "got {:?}", cfg.session_conf); } - - /// The client knob is NOT in the server allowlist, so even if it were - /// left in session_conf it would be filtered before the wire. This - /// pins that invariant so a future allowlist edit can't accidentally - /// promote it to a server SET parameter. - #[test] - fn cloudfetch_max_chunks_key_is_not_server_allowlisted() { - let filtered = crate::config::filter_session_conf(HashMap::from([( - crate::config::ClientConfKey::CloudfetchMaxChunksInMemory - .as_str() - .to_string(), - "4".to_string(), - )])); - assert!( - filtered.is_empty(), - "client knob must not survive the server allowlist, got {filtered:?}", - ); - } } #[cfg(test)] diff --git a/tests/v0_session_wiremock.rs b/tests/v0_session_wiremock.rs index b3452c97..997fc55d 100644 --- a/tests/v0_session_wiremock.rs +++ b/tests/v0_session_wiremock.rs @@ -354,9 +354,8 @@ async fn open_session_with_result_cfg( /// Assert that the recorded CreateSession request carries no /// `can_cloud_download`-shaped key under any casing. Shared by the tests -/// below, which each drive a different `cloudfetch_enabled` / -/// `session_conf` combination — all of which must keep this key off the -/// CreateSession wire (issue #196: SEA has no such session conf). +/// below which prove the typed CloudFetch toggle does not synthesize this +/// session conf. async fn assert_no_can_cloud_download_on_create(server: &MockServer) { let recorded = server .received_requests() @@ -381,6 +380,18 @@ async fn assert_no_can_cloud_download_on_create(server: &MockServer) { } } +async fn create_session_body(server: &MockServer) -> serde_json::Value { + let recorded = server + .received_requests() + .await + .expect("server must have request log enabled"); + let create = recorded + .iter() + .find(|r| r.url.path() == "/api/2.0/sql/sessions" && r.method.as_str() == "POST") + .expect("a POST /sessions request was made"); + serde_json::from_slice(&create.body).expect("create-session body must be valid JSON") +} + #[tokio::test] async fn create_session_with_cloudfetch_disabled_omits_can_cloud_download() { // Regression test for issue #196. Disabling CloudFetch @@ -413,12 +424,10 @@ async fn create_session_with_cloudfetch_disabled_omits_can_cloud_download() { } #[tokio::test] -async fn create_session_drops_user_supplied_can_cloud_download() { - // A caller-supplied `can_cloud_download` (any value, any casing) is - // NOT a valid SEA session conf, so `filter_session_conf` drops it — - // it must never reach the CreateSession wire where it would poison - // every subsequent ExecuteStatement (issue #196). The session still - // opens; the stray key is silently dropped with a warn. +async fn create_session_forwards_user_supplied_session_conf_unchanged() { + // Caller-supplied server-bound session_conf is no longer filtered or + // normalized by the kernel. Even keys the server may reject later pass + // through unchanged; validation belongs to the server. let server = MockServer::start().await; Mock::given(method("POST")) .and(path("/api/2.0/sql/sessions")) @@ -431,8 +440,8 @@ async fn create_session_drops_user_supplied_can_cloud_download() { .await; let mut session_conf = std::collections::HashMap::new(); - // Non-canonical casing to also exercise the case-insensitive match. session_conf.insert("Can_Cloud_Download".to_string(), "true".to_string()); + session_conf.insert("unknown.MixedCase".to_string(), "value".to_string()); let session = Session::builder() .connection( ConnectionConfig::from_http_path(server.uri(), "/sql/1.0/warehouses/test_wh") @@ -445,10 +454,22 @@ async fn create_session_drops_user_supplied_can_cloud_download() { .session_conf(session_conf) .open() .await - .expect("session must open even with a stray can_cloud_download"); + .expect("session must open with caller-supplied session_conf"); assert_eq!(session.session_id(), "sess-dropped"); - assert_no_can_cloud_download_on_create(&server).await; + let body = create_session_body(&server).await; + let obj = body + .get("session_confs") + .and_then(|v| v.as_object()) + .expect("session_confs object"); + assert_eq!( + obj.get("Can_Cloud_Download").and_then(|v| v.as_str()), + Some("true") + ); + assert_eq!( + obj.get("unknown.MixedCase").and_then(|v| v.as_str()), + Some("value") + ); } #[tokio::test]