Repository navigation
Support proxy credentials from http_proxy/https_proxy environment variables - #123069
Conversation
EnvironmentProxyConfigurationResolver read only host, scheme and port from the proxy URI, so credentials in http_proxy/https_proxy were silently discarded and ClickHouse could not authenticate to a proxy. Parse the userinfo component, splitting on the first colon so passwords may contain colons, and percent-decode each half afterwards. Carry the values on ProxyConfiguration and copy them into Poco's ProxyConfig, which performs the Basic authentication itself. Closes ClickHouse#71294
|
I would consider adding an integration test - I have written a few for the proxy feature in the past. |
ac5f2c5 to
93881ad
Compare
…erbatim The existing proxy test containers do not require authentication, so a test that merely puts credentials in http_proxy would pass with or without the fix. Run a proxy that demands Basic auth and point four nodes at it: credentials correct, wrong, absent, and correct-but-sent-to-a-proxy-that-ignores-them. Against an unpatched binary only the first fails, which is what makes the test meaningful. Also stop decoding from throwing. Poco::URI::decode raises URISyntaxException on malformed percent-encoding, and a password containing a literal '%' is a common mistake, so a previously working configuration would have started failing. Fall back to the raw value instead, which is what curl does with the same input.
|
Added an integration test. The existing proxy containers don't require auth, so Also made decoding fall back instead of throwing: Poco::URI::decode raises on One design question on the other two resolvers. They have the same gap but not So rather than parsing userinfo in one and inventing something else for the Happy to do that as a follow-up, or fold it in here. Any preference on naming, |
|
Workflow [PR], commit [8fdec7c] Summary: ✅
AI ReviewSummaryThis PR threads proxy credentials from Findings❌ Blockers
Final Verdict
LLVM Coverage ReportMeasured on commit 8fdec7c.
Changed lines: Changed C/C++ lines covered: 55/60 (91.67%) · Uncovered code |
…proxy readiness probe Include `ProxyConfiguration::username` and `password` in `EndpointPoolKey` equality and hash, so sessions to the same proxy with different credentials are not shared. The readiness probe in the integration test relied on the exit code, but `exec_in_container` returns only stdout, so it always succeeded immediately. Print the `connect_ex` result and wait for `0`. Co-Authored-By: Claude Opus 5.5 <[email protected]>
… a file The auth proxy is started with a detached `docker exec`, so its stdout never reaches the container logs, and the `ALLOWED` check always failed although the queries through the proxy succeeded. Write the events to a file and read it. CI report: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=123069&sha=402fec94762308dedd8f7430faa85085ed96a54b&name_0=PR&name_1=Integration%20tests%20%28amd_asan_ubsan%2C%20flaky%29 PR: ClickHouse#123069 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Compile time of recompiled translation units155 translation units recompiled, 1192 s compile time in total, 155 of them have a recent master baseline. Median compile-time ratio to the baselines is ×1.11 (machine-speed difference or a change affecting every TU); per-TU deltas below are relative to that ratio. |
|
🕵 Regarding the AI review's metadata note ( |
|
🕵 @groeneai, investigate the failure: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=123069&sha=1923792747b19804063d26a067dfaffe0e5f50ad&name_0=PR&name_1=Upgrade%20check%20%28amd_release%29 and provide a fix in a separate PR. If the fix is already in progress, link it here. The new drain step from #123376 fails with |
|
Acknowledged, this one is mine: the drain step from #123376 gives a false red here. |
|
Fixing PR: #123841 |
|
🕵 Merged the latest |
|
🕵 @groeneai, investigate the failure: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=123069&sha=ba9b1561b4468e782ff6dec72f649f6a62f4cc2e&name_0=PR&name_1=Integration%20tests%20%28amd_llvm_coverage%2C%206%2F8%29 and provide a fix in a separate PR. If the fix is already in progress, link it here. All 14 |
|
Acknowledged. I am investigating the |
`EnvironmentProxyConfigurationResolver` splits the userinfo on the first colon and then percent-decodes the username and the password. This is correct only because `Poco::URI` (ClickHouse's fork, `URI::parseAuthority`) stores the userinfo without decoding it, so the credentials are decoded exactly once. Pin this with a test, using a password that contains an encoded `%` and an encoded colon. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Fixing PR: #124184 (the startup access checks of the two servers race in one empty MinIO prefix, not MinIO readiness). |
…equests `HTTPSClientSession::proxyAuthenticate` was a no-op, so for an `https://` proxy (or an `http` proxy with tunneling disabled) the request went to the proxy without a `Proxy-Authorization` header and an authenticating proxy answered 407. In that path `connect` establishes TLS with the proxy itself, so it is safe to send the credentials there. Call `proxyAuthenticateImpl`, which does nothing when no username is configured. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
🕵 Pushed 8fdec7c, which addresses the review: proxy credentials are now also sent on the non-tunneled |
Both servers of the module (`instance` and `instance_local_metadata`, the second added in 88a9fbd) load `configs/backups.xml` and run the `IDisk::startup` access check of `backup_disk_s3_plain` (PUT, GET, DELETE of `clickhouse_access_check_<uuid>`) at the same time, in the same fresh MinIO prefix `root/data/disks/disk_s3_plain/` that holds nothing but the two probes. MinIO's DELETE removes the object directory and then every now-empty parent (`cmd/xl-storage.go`, `deleteFile`), while the other server's PUT creates the same parents in `RenameData -> renameAll -> reliableRename -> reliableMkdirAll` (`cmd/os-reliable.go`). When a parent is removed between its EEXIST and the child's mkdir, `os.Mkdir` returns an ENOENT PathError, and `renameAll` classifies it with `isSysErrPathNotFound` (non-Windows branch is `pathErr.Err == ENOENT`, `cmd/xl-storage-errors.go`) as `errFileAccessDenied`, i.e. `403 AccessDenied`, even for the root user. The code is unchanged in the latest pgsty/silo release. In the failing job (PR ClickHouse#123069, amd_llvm_coverage 6/8) the denied PUT was sent at 14:11:26.619465 and failed at .624049, 0.47 ms after `instance`'s DELETE of its own probe completed (.622793-.623583); the server exited and all 14 tests failed in `start_cluster`. Two clients doing the same PUT/GET/DELETE against the same MinIO image locally got 7 and 13 AccessDenied PUTs in two 120 s runs with an empty prefix, and 0 of 49876 with one extra object keeping the prefix non-empty. With `skip_access_check` neither server writes to MinIO at startup; the disk is still used by every BACKUP/RESTORE in the module. Same remedy as ClickHouse#110300 and ClickHouse#110592. Co-Authored-By: Claude Opus 5.5 <[email protected]>
`HTTPClientSession::sendRequest` calls `proxyAuthenticate` for every request when a proxy is configured, including requests sent inside a `CONNECT` tunnel. After ClickHouse#123069 the `HTTPSClientSession` override adds `Proxy-Authorization`, so for an `https` target through an `http` proxy with tunneling (the default) the request inside the TLS tunnel carried the proxy credentials to the target server. Skip it when `isProxyTunnel`; the credentials are already sent with `CONNECT`. Related: ClickHouse#123069 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Closes: #71294
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Support proxy credentials in the
http_proxyandhttps_proxyenvironment variables. Previously the userinfo part of the proxy URI was discarded, so ClickHouse could not use an authenticating proxy.Documentation entry for user-facing changes
Problem
EnvironmentProxyConfigurationResolverparses the proxy URI withPoco::URIbut readsonly host, scheme and port —
getUserInfo()is never called.ProxyConfigurationhas nofield to carry credentials either, so no
Proxy-Authorizationheader can be produced onthis path. ClickHouse therefore cannot reach object storage through an authenticating proxy.
Reported in #71294 (open since 2024-10-31). I hit it in production on 26.1.3.52 and have
now reproduced it on 26.9.6.6, so nothing has fixed it in the meantime.
Reproduction on 26.9.6.6
clickhouse/clickhouse-server:latestwith credentials in the environment:ClickHouse's own resolver logs them away:
The proxy never receives an auth header:
and the query fails:
Changes
ProxyConfiguration— addedusername/password, plus a staticparseUserInfo()helper that splits a userinfo component on the first
:(a password may legallycontain colons).
EnvironmentProxyConfigurationResolver— parse the userinfo, then percent-decode eachhalf. The order matters: decoding first would make an encoded
%3Aindistinguishablefrom the real separator.
proxyConfigurationToPocoProxyConfig— copy the credentials into Poco'sProxyConfig.Poco already performs the authentication once those fields are populated
(
proxyAuthenticateImplbuildsHTTPBasicCredentialswhenusernameis non-empty, andis called from
proxyConnect(), so this covers the CONNECT tunnel used for HTTPS/S3).Nothing new is introduced on the ClickHouse side beyond carrying the values across.
The
LOG_TRACEline is built fromscheme,hostandportas separate arguments, soit never logged credentials and still does not.
Percent-decoding
Poco::URI::getUserInfo()does not decode — it returnsp%40ssverbatim. Since@must be percent-encoded in a URI userinfo, decoding is required or the literal encoded
string would be sent as the password. This also answers @TimLampen12's question on the
issue about special characters such as
&.Tests
gtest_proxy_credentials.cpp(new) —parseUserInfo()against empty input,user+password, username-only, trailing separator, and a password containing colons.
Deliberately independent of the environment, because
resolve()caches itsgetenvresults instaticlocals for the process lifetime.gtest_proxy_environment_configuration.cpp— extended to assert the parsed username andpassword, with
%40in the fixture so the decoding path is exercised end to end.Verified outside the test suite
I could not build ClickHouse locally (insufficient disk), so I am relying on CI for the
compile and gtest run. To avoid submitting something unverified, I validated the logic
and the Poco integration standalone:
Poco::URI— percent-encoded@,&,:, literalcolons in passwords, username-only, and no credentials at all;
Proxy-Authorization: Basic dXNlcjpwQHNzd29yZA==→user:p@ssword;CONNECTtunnel through an authenticating proxy to a real S3 object —407with no credentials,200 OKwith them.Not in this PR
ProxyListConfigurationResolverandRemoteProxyConfigurationResolverhave the samegap. Happy to follow up once the shape here is agreed.
407is classified as retryable —S3ClientRetryStrategy: Attempt 44/501 failed—against an error that cannot succeed without new credentials. Separate issue.
retryable error: 18446744073709551615(UINT64_MAX, a-1wrapped unsigned). Also separate; happy to raise both.
Workflow [PR]
Sync PR [sync-upstream/pr/123069]
Version info
26.10.1.1724-master(included in26.10and later)