From 3c232461fb8803f4d562322dba321873b30c223d Mon Sep 17 00:00:00 2001 From: Vu Anh Phung Date: Mon, 16 Nov 2026 01:29:48 +0000 Subject: [PATCH 1/2] fix(logging): drop presigned query from request errors and debug URLs reqwest's error Display prints the request URL, so a timed-out or reset CloudFetch download put the SAS/S3 signature into the retry warning and the returned error. Strip the query from the URL inside the reqwest error, log each request's URL only up to `?`, and drop the URL from the chunk download debug line. Signed-off-by: Vu Anh Phung Co-authored-by: Isaac --- NEXT_CHANGELOG.md | 1 + src/client/http.rs | 67 ++++++++++++++++++++++- src/reader/cloudfetch/chunk_downloader.rs | 4 +- 3 files changed, 68 insertions(+), 4 deletions(-) diff --git a/NEXT_CHANGELOG.md b/NEXT_CHANGELOG.md index 6aa75289..3964deb0 100644 --- a/NEXT_CHANGELOG.md +++ b/NEXT_CHANGELOG.md @@ -26,6 +26,7 @@ changes go in their respective binding's NEXT_CHANGELOG. ### Fixed - `Session::open` authenticates once before resolving feature flags. A failed OAuth token request now fails the open immediately instead of being sent a second time by CreateSession. +- A timed-out or reset CloudFetch download no longer writes the presigned URL's signature (`sig=`, `X-Amz-Signature`) to the log or the returned error. The request URL in those messages now ends at the path, and debug request lines stop at `?`. --- *Note: When making changes, please add your change under the appropriate diff --git a/src/client/http.rs b/src/client/http.rs index e5f9ad0b..049b2661 100644 --- a/src/client/http.rs +++ b/src/client/http.rs @@ -933,7 +933,11 @@ impl DatabricksHttpClient { debug!( "{:?}: {} {} (attempt {}/{})", - request_type, method, url, attempts, max_attempts + request_type, + method, + url.as_str().split('?').next().unwrap_or_default(), + attempts, + max_attempts ); match self.client.execute(request).await { @@ -1015,7 +1019,11 @@ impl DatabricksHttpClient { format_args!("HTTP {}", status.as_u16()), )); } - Err(e) => { + Err(mut e) => { + // reqwest's Display prints the request URL; a presigned URL's query is its credential. + if let Some(url) = e.url_mut() { + url.set_query(None); + } let mut causes = super::error_chain(&e) .map(ToString::to_string) .collect::>(); @@ -1888,6 +1896,61 @@ lGrv15pBcePj ); } + #[derive(Clone, Default)] + struct CapturedLogs(Arc>>); + + impl std::io::Write for CapturedLogs { + fn write(&mut self, buf: &[u8]) -> std::io::Result { + self.0.lock().unwrap().extend_from_slice(buf); + Ok(buf.len()) + } + fn flush(&mut self) -> std::io::Result<()> { + Ok(()) + } + } + + #[tokio::test] + async fn test_request_error_and_logs_drop_presigned_query() { + let logs = CapturedLogs::default(); + let writer = logs.clone(); + let _guard = tracing::subscriber::set_default( + tracing_subscriber::fmt() + .with_max_level(tracing::Level::DEBUG) + .with_ansi(false) + .with_writer(move || writer.clone()) + .finish(), + ); + let listener = TcpListener::bind("127.0.0.1:0").await.unwrap(); + let address = listener.local_addr().unwrap(); + drop(listener); + + let client = + test_client_with_http_config(fast_retry_config(1), HttpClientConfig::default()); + let request = client + .inner() + .get(format!( + "http://{address}/results_0?sig=SECRET&X-Amz-Signature=SECRET" + )) + .build() + .unwrap(); + + let error = client + .execute_without_auth(request, RequestType::CloudFetchDownload) + .await + .expect_err("closed port must fail"); + assert!(!error.to_string().contains("SECRET"), "{error}"); + assert!( + error + .message + .contains(&format!("http://{address}/results_0)")), + "{error}" + ); + let logs = String::from_utf8(logs.0.lock().unwrap().clone()).unwrap(); + assert!(logs.contains("before retry"), "{logs}"); + assert!(logs.contains("/results_0 (attempt 2/2)"), "{logs}"); + assert!(!logs.contains("SECRET"), "{logs}"); + } + #[tokio::test] async fn test_connection_closed_before_response_is_retried() { let listener = TcpListener::bind("127.0.0.1:0").await.unwrap(); diff --git a/src/reader/cloudfetch/chunk_downloader.rs b/src/reader/cloudfetch/chunk_downloader.rs index 518a5a8d..f22de8b9 100644 --- a/src/reader/cloudfetch/chunk_downloader.rs +++ b/src/reader/cloudfetch/chunk_downloader.rs @@ -89,8 +89,8 @@ impl ChunkDownloader { let start = Instant::now(); debug!( - "Downloading chunk {} from {} ({} bytes expected, attempt_timeout {:?})", - link.chunk_index, link.url, link.byte_count, attempt_timeout + "Downloading chunk {} ({} bytes expected, attempt_timeout {:?})", + link.chunk_index, link.byte_count, attempt_timeout ); // Build request with custom headers from the link From aa94609268b8edaf54ac409a76cbc851a6077390 Mon Sep 17 00:00:00 2001 From: Vu Anh Phung Date: Mon, 16 Nov 2026 03:12:05 +0000 Subject: [PATCH 2/2] test(logging): run the presigned-URL log test in its own binary The log-capturing test failed about one in three full runs (and every run of the client::http subset): tests in the unit-test binary that open a session install a process-global tracing subscriber, and the test's thread-local capture then missed the retry warning and request lines. Move it to tests/presigned_url_logging.rs, where it is the only test and installs the global subscriber itself, like tests/klog_bridge.rs. Signed-off-by: Vu Anh Phung Co-authored-by: Isaac --- src/client/http.rs | 55 ------------------- tests/presigned_url_logging.rs | 97 ++++++++++++++++++++++++++++++++++ 2 files changed, 97 insertions(+), 55 deletions(-) create mode 100644 tests/presigned_url_logging.rs diff --git a/src/client/http.rs b/src/client/http.rs index 049b2661..cac2243b 100644 --- a/src/client/http.rs +++ b/src/client/http.rs @@ -1896,61 +1896,6 @@ lGrv15pBcePj ); } - #[derive(Clone, Default)] - struct CapturedLogs(Arc>>); - - impl std::io::Write for CapturedLogs { - fn write(&mut self, buf: &[u8]) -> std::io::Result { - self.0.lock().unwrap().extend_from_slice(buf); - Ok(buf.len()) - } - fn flush(&mut self) -> std::io::Result<()> { - Ok(()) - } - } - - #[tokio::test] - async fn test_request_error_and_logs_drop_presigned_query() { - let logs = CapturedLogs::default(); - let writer = logs.clone(); - let _guard = tracing::subscriber::set_default( - tracing_subscriber::fmt() - .with_max_level(tracing::Level::DEBUG) - .with_ansi(false) - .with_writer(move || writer.clone()) - .finish(), - ); - let listener = TcpListener::bind("127.0.0.1:0").await.unwrap(); - let address = listener.local_addr().unwrap(); - drop(listener); - - let client = - test_client_with_http_config(fast_retry_config(1), HttpClientConfig::default()); - let request = client - .inner() - .get(format!( - "http://{address}/results_0?sig=SECRET&X-Amz-Signature=SECRET" - )) - .build() - .unwrap(); - - let error = client - .execute_without_auth(request, RequestType::CloudFetchDownload) - .await - .expect_err("closed port must fail"); - assert!(!error.to_string().contains("SECRET"), "{error}"); - assert!( - error - .message - .contains(&format!("http://{address}/results_0)")), - "{error}" - ); - let logs = String::from_utf8(logs.0.lock().unwrap().clone()).unwrap(); - assert!(logs.contains("before retry"), "{logs}"); - assert!(logs.contains("/results_0 (attempt 2/2)"), "{logs}"); - assert!(!logs.contains("SECRET"), "{logs}"); - } - #[tokio::test] async fn test_connection_closed_before_response_is_retried() { let listener = TcpListener::bind("127.0.0.1:0").await.unwrap(); diff --git a/tests/presigned_url_logging.rs b/tests/presigned_url_logging.rs new file mode 100644 index 00000000..8dc87390 --- /dev/null +++ b/tests/presigned_url_logging.rs @@ -0,0 +1,97 @@ +// Copyright (c) 2026 Databricks, Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +//! A failed CloudFetch request must not print the presigned URL's query (its +//! credential) in the returned error, the retry warning or the debug request +//! line. +//! +//! This is its own test binary because it captures `tracing` output. In the +//! unit-test binary, tests that open a session install a process-global +//! subscriber, which made a thread-local capture there miss events. + +use std::collections::HashMap; +use std::sync::{Arc, Mutex}; +use std::time::Duration; + +use databricks_sql_kernel::client::http::{DatabricksHttpClient, HttpClientConfig}; +use databricks_sql_kernel::client::retry::{build_retry_configs, RequestType, RetryConfig}; + +#[derive(Clone, Default)] +struct CapturedLogs(Arc>>); + +impl std::io::Write for CapturedLogs { + fn write(&mut self, buf: &[u8]) -> std::io::Result { + self.0.lock().unwrap().extend_from_slice(buf); + Ok(buf.len()) + } + fn flush(&mut self) -> std::io::Result<()> { + Ok(()) + } +} + +#[tokio::test] +async fn request_error_and_logs_drop_presigned_query() { + let logs = CapturedLogs::default(); + let writer = logs.clone(); + tracing::subscriber::set_global_default( + tracing_subscriber::fmt() + .with_max_level(tracing::Level::DEBUG) + .with_ansi(false) + .with_writer(move || writer.clone()) + .finish(), + ) + .expect("the only subscriber in this binary"); + + // Nothing listens on a port whose listener was dropped. + let address = std::net::TcpListener::bind("127.0.0.1:0") + .unwrap() + .local_addr() + .unwrap(); + let retry = RetryConfig { + min_wait: Duration::from_millis(10), + max_wait: Duration::from_millis(50), + overall_timeout: Duration::from_secs(10), + max_retries: 1, + override_retryable_codes: None, + }; + let client = DatabricksHttpClient::new( + HttpClientConfig::default(), + build_retry_configs(&retry, &HashMap::new()), + ) + .unwrap(); + let request = client + .inner() + .get(format!( + "http://{address}/results_0?sig=SECRET&X-Amz-Signature=SECRET" + )) + .build() + .unwrap(); + + let error = client + .execute_without_auth(request, RequestType::CloudFetchDownload) + .await + .expect_err("closed port must fail"); + assert!(!error.to_string().contains("SECRET"), "{error}"); + assert!( + error + .message + .contains(&format!("http://{address}/results_0)")), + "{error}" + ); + + let logs = String::from_utf8(logs.0.lock().unwrap().clone()).unwrap(); + assert!(logs.contains("before retry"), "{logs}"); + assert!(logs.contains("/results_0 (attempt 2/2)"), "{logs}"); + assert!(!logs.contains("SECRET"), "{logs}"); +}