You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit a29235c
Browse filesBrowse the repository at this point in the historyBrowse files
feat(client): support SOCKS4/4a/5/5h proxies (#518)
## Summary
Adds SOCKS proxy support to the kernel's shared HTTP client, so SQL
requests, CloudFetch downloads and OAuth use the same tunnel.
- `ProxyConfig.url`, the Rust ADBC driver's `adbc.databricks.proxy.url`,
and `HTTPS_PROXY`/`ALL_PROXY` accept `socks4://`, `socks4a://`,
`socks5://` and `socks5h://` next to `http(s)://`. `socks5`/`socks4`
resolve the target host locally; `socks5h`/`socks4a` let the proxy
resolve it.
- An explicit URL with any other scheme, including bare `socks://`,
fails with `InvalidArgument`. In environment variables, an unsupported
scheme is ignored, so reqwest falls back to `ALL_PROXY` or connects
directly.
- SOCKS5 credentials use RFC 1929. When credentials are set, only
username/password authentication is offered, and a rejected login fails
at once without resending the credentials.
- SOCKS4 ignores credentials: it has no password, and the user ID isn't
sent yet, because hyper-util always sends an empty one.
- An unreachable proxy or rejected credentials fail the request, with no
direct fallback. TLS is verified against the target host through the
tunnel.
- Proxy credentials are redacted from proxy URLs in errors, logs and
`Debug` output.
`ProxyConfig` fields, defaults and the C ABI are unchanged.
## Dependencies
- reqwest's `socks` feature is implemented by hyper-util, which is
already a dependency, so there's no new crate.
- hyper-util goes from 0.1.20 to 0.1.21 in the root, `napi/` and `pyo3/`
lockfiles, because 0.1.20 writes a malformed SOCKS4/4a CONNECT request.
`Cargo.toml` now requires `hyper-util >= 0.1.21`, so downstream
lockfiles get the fix too.
- The bump adds `base64 v0.23.1` (MIT OR Apache-2.0) next to 0.22.1.
0.1.21 also validates HTTP proxy CONNECT responses more strictly; the
existing HTTP-proxy tests pass.
- The Node.js, Go, Python and ODBC changes depend on this one and on its
release: databricks/databricks-sql-nodejs#653,
databricks/databricks-sql-go#607, databricks/databricks-sql-python#1082
and databricks/databricks-odbc#525.
## Validation
- Tests on both TLS backends against a loopback SOCKS4/4a/5 fixture that
records each handshake:
- the scheme allow-list and the DNS mode per scheme;
- RFC 1929 credentials;
- dead proxies and refused CONNECTs failing closed;
- bypass hosts, and environment proxies tested in a child process;
- CloudFetch downloads through the tunnel, and TLS hostname verification
through the tunnel;
- redaction in errors and logs.
- ADBC config tests cover the new schemes, and the C ABI smoke test
covers SOCKS URLs.
- `cargo fmt` and `clippy -D warnings` pass on both backends, as do the
workspace, `napi/`, `pyo3/` and `adbc/` tests and `cargo deny`.
- Live against staging DBSQL and Reyden warehouses through the fixture:
- all four schemes, credentials, a dead proxy, `NO_PROXY` and
`bypass_hosts`, and a 200,000-row CloudFetch query;
- an HTTP CONNECT proxy still works;
- `SELECT 1` through `socks5h` was within 50 ms of direct.
This pull request and its description were written by Isaac.
Signed-off-by: cat23123 <58714163+cat23123@users.noreply.github.com>
Co-authored-by: cat23123 <58714163+cat23123@users.noreply.github.com>
Co-authored-by: Isaac <no-reply@databricks.com>
|[`TlsConfig`](#tlsconfig--tls--ssl-optional)| cert validation, custom CA, mTLS |
17
17
|[`ResultConfig`](#resultconfig--result-handling-optional)| CloudFetch tuning, type rendering |
18
18
|[`geospatial_result_representation`](#geospatial_result_representation--geospatial-result-encoding-optional)| GEOMETRY / GEOGRAPHY result encoding |
@@ -178,13 +178,30 @@ until implemented) and `External` (a caller-supplied `TokenProvider`).
178
178
## `ProxyConfig` — HTTP/HTTPS proxy (optional)
179
179
180
180
When `url` is `None`, the kernel does not configure a proxy and
181
-
`reqwest`'s standard `HTTP_PROXY` / `HTTPS_PROXY` / `NO_PROXY` env-var
182
-
behaviour applies. Setting `url`**overrides** those env vars.
181
+
`reqwest`'s standard `HTTP_PROXY` / `HTTPS_PROXY` / `ALL_PROXY` / `NO_PROXY`
182
+
env-var behaviour applies. Those variables are used only with the `http`,
183
+
`https`, `socks4`, `socks4a`, `socks5` and `socks5h` schemes. A value with
184
+
any other scheme, such as bare `socks://`, is ignored, so the kernel falls
185
+
back to `ALL_PROXY` or connects directly. Setting `url`**overrides** those
186
+
env vars, and an unsupported scheme in `url` fails with `InvalidArgument`.
187
+
188
+
SOCKS: `socks5://` and `socks4://` resolve the target host locally;
189
+
`socks5h://` and `socks4a://` let the proxy resolve it. SOCKS5 credentials
190
+
use RFC 1929 username/password authentication. When credentials are set,
191
+
that is the only method offered, so a proxy that allows only
192
+
unauthenticated access rejects the connection. SOCKS4 has no password, and
193
+
the kernel does not yet send a SOCKS4 user ID, so a SOCKS4 proxy that checks
194
+
the user ID refuses the connection. An unreachable proxy fails the request
195
+
after the retry policy's attempts; a rejected SOCKS5 authentication fails it
196
+
at once, without resending the credentials. The kernel never falls back to a
197
+
direct connection. TLS is still negotiated with, and verified against, the target
198
+
host through the tunnel. Proxy URLs are logged and reported in errors with
199
+
userinfo replaced by `***`.
183
200
184
201
| Field | Description | Default |
185
202
|-------|-------------|---------|
186
-
|`url`| Proxy endpoint, e.g. `http://proxy.corp.example.com:8080`. Must be `http://`or `https://`. |`None` (env-var behaviour) |
187
-
|`username`| Proxy basic-auth username. Overrides credentials embedded in `url`. |`None`|
203
+
|`url`| Proxy endpoint, e.g. `http://proxy.corp.example.com:8080` or `socks5h://proxy.corp.example.com:1080`. Scheme must be `http`, `https`, `socks4`, `socks4a`, `socks5`or `socks5h`. |`None` (env-var behaviour) |
0 commit comments