Skip to content

Support proxy credentials from http_proxy/https_proxy environment variables - #123069

Merged
alexey-milovidov merged 8 commits into
ClickHouse:masterfrom
Akanshaak:proxy-credentials-from-env
Oct 7, 2026
Merged

alexey-milovidov merged 8 commits into
ClickHouse:masterfrom
Akanshaak:proxy-credentials-from-env

Conversation

@Akanshaak

@Akanshaak Akanshaak commented Sep 30, 2026 •

Copy link
Copy Markdown

Closes: #71294

Changelog category (leave one):

  • Improvement

Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):

Support proxy credentials in the http_proxy and https_proxy environment 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

EnvironmentProxyConfigurationResolver parses the proxy URI with Poco::URI but reads
only host, scheme and port — getUserInfo() is never called. ProxyConfiguration has no
field to carry credentials either, so no Proxy-Authorization header can be produced on
this 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:latest with credentials in the environment:

http_proxy=http://user:p%40ssword@proxy:3128

ClickHouse's own resolver logs them away:

<Trace> EnvironmentProxyConfigurationResolver:
    Use proxy from environment: http://proxy:3128

The proxy never receives an auth header:

CONNECT <bucket>.s3.<region>.amazonaws.com:443   Proxy-Authorization: ABSENT  -> 407

and the query fails:

Poco::Exception. Code: 1000, e.code() = 0, HTTP Exception:
Cannot establish proxy connection: Proxy Authentication Required
(version 26.9.6.6 (official build))

Changes

  • ProxyConfiguration — added username / password, plus a static parseUserInfo()
    helper that splits a userinfo component on the first : (a password may legally
    contain colons).
  • EnvironmentProxyConfigurationResolver — parse the userinfo, then percent-decode each
    half. The order matters: decoding first would make an encoded %3A indistinguishable
    from the real separator.
  • proxyConfigurationToPocoProxyConfig — copy the credentials into Poco's ProxyConfig.

Poco already performs the authentication once those fields are populated
(proxyAuthenticateImpl builds HTTPBasicCredentials when username is non-empty, and
is 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_TRACE line is built from scheme, host and port as separate arguments, so
it never logged credentials and still does not.

Percent-decoding

Poco::URI::getUserInfo() does not decode — it returns p%40ss verbatim. 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 its
    getenv results in static locals for the process lifetime.
  • gtest_proxy_environment_configuration.cpp — extended to assert the parsed username and
    password, with %40 in 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:

  • the parsing pipeline against real Poco::URI — percent-encoded @, &, :, literal
    colons in passwords, username-only, and no credentials at all;
  • that Poco emits the correct header once the fields are set, captured off the wire:
    Proxy-Authorization: Basic dXNlcjpwQHNzd29yZA== → user:p@ssword;
  • an HTTPS CONNECT tunnel through an authenticating proxy to a real S3 object —
    407 with no credentials, 200 OK with them.

Not in this PR

  • ProxyListConfigurationResolver and RemoteProxyConfigurationResolver have the same
    gap. Happy to follow up once the shape here is agreed.
  • A 407 is classified as retryable — S3ClientRetryStrategy: Attempt 44/501 failed —
    against an error that cannot succeed without new credentials. Separate issue.
  • The same log line reports retryable error: 18446744073709551615 (UINT64_MAX, a -1
    wrapped unsigned). Also separate; happy to raise both.

Workflow [PR]
Sync PR [sync-upstream/pr/123069]

Version info

  • Merged into: 26.10.1.1724-master (included in 26.10 and later)

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
@CLAassistant

CLAassistant commented Sep 30, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@arthurpassos

Copy link
Copy Markdown
Contributor

I would consider adding an integration test - I have written a few for the proxy feature in the past.

See https://github.com/ClickHouse/ClickHouse/blob/master/tests/integration/test_s3_table_function_with_https_proxy/test.py as an example

@clickhouse-gh clickhouse-gh Bot added comp-object-storage Object storage connectivity (S3/GCS/Azure) including credentials, retries, multipart, etc. external Author is not a member of the ClickHouse organization labels Sep 30, 2026
@Akanshaak
Akanshaak force-pushed the proxy-credentials-from-env branch from ac5f2c5 to 93881ad Compare October 1, 2026 07:47
…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.
@Akanshaak

Copy link
Copy Markdown
Author

Added an integration test. The existing proxy containers don't require auth, so
a test that just puts credentials in http_proxy would pass either way — this one
runs a proxy that demands Basic auth and covers credentials correct, wrong,
absent, and sent to a proxy that ignores them. Against an unpatched binary only
the first fails.

Also made decoding fall back instead of throwing: Poco::URI::decode raises on
malformed percent-encoding, and a literal '%' in a password is a common mistake,
so it would have broken configurations that work today. It now keeps the raw
value, which is what curl does with the same input.

One design question on the other two resolvers. They have the same gap but not
the same shape: ProxyListConfigurationResolver has a Poco::URI whose userinfo
could be parsed, while RemoteProxyConfigurationResolver only receives a hostname
from its endpoint — there's no URI to put credentials in at all.

So rather than parsing userinfo in one and inventing something else for the
other, would separate / elements make sense for both? That also
sidesteps percent-encoding ambiguity — a password containing a literal %25 can't
be expressed unambiguously in a URI — which is why Maven and the Java proxy
properties take credentials as separate fields.

Happy to do that as a follow-up, or fold it in here. Any preference on naming,
and should it support from_env?

@alexey-milovidov alexey-milovidov added the can be tested Allows running workflows for external contributors label Oct 4, 2026

@alexey-milovidov alexey-milovidov left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good.

@alexey-milovidov alexey-milovidov self-assigned this Oct 4, 2026
@clickhouse-gh

clickhouse-gh Bot commented Oct 4, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [8fdec7c]

Summary: ✅


AI Review

Summary

This PR threads proxy credentials from http_proxy / https_proxy environment variables into ProxyConfiguration, Poco proxy sessions, and the connection-pool key, and it adds unit/integration coverage around the new parsing and auth flows. I found one blocker in the final HTTPSClientSession change: it now adds Proxy-Authorization even on CONNECT-tunneled HTTPS requests, which leaks proxy credentials to the origin server on the common https://... via http_proxy path.

Findings
❌ Blockers
  • [base/poco/NetSSL_OpenSSL/src/HTTPSClientSession.cpp:157] HTTPSClientSession::proxyAuthenticate is no longer restricted to the non-tunneled proxy path. HTTPClientSession::sendRequest invokes it for every proxied request, including after CONNECT has already established the tunnel, so Proxy-Authorization is now forwarded inside the TLS tunnel to the upstream server. That makes authenticated HTTP proxies unsafe for HTTPS/S3 traffic.
    Suggested fix: send the header only when !isProxyTunnel() (or otherwise only for direct proxy requests) and add a regression test that a tunneled request does not carry Proxy-Authorization.
Final Verdict
  • Status: ❌ Block
  • Minimum required actions: stop attaching Proxy-Authorization to tunneled HTTPS requests, and cover the tunnel=true case with a regression test.

LLVM Coverage Report

Measured on commit 8fdec7c.

Metric Baseline Current Δ
Lines 88.20% 88.20% +0.00%
Functions 92.10% 91.80% -0.30%
Branches 79.70% 79.70% +0.00%

Changed lines: Changed C/C++ lines covered: 55/60 (91.67%) · Uncovered code

Full report · Diff report

@clickhouse-gh clickhouse-gh Bot added the pr-improvement Pull request with some product improvements label Oct 4, 2026
Comment thread src/Common/ProxyConfiguration.h Resolved
alexey-milovidov and others added 2 commits October 4, 2026 03:39
…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]>
@clickhouse-gh

clickhouse-gh Bot commented Oct 4, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing 8fdec7c30 with master ad939788c (stripped binary size, per-symbol sizes and ThinLTO time; object sizes against the warmup build of af72d84f3; compile times per translation unit against the most recent warmup build that recompiled it).

✅ No significant changes.

Binary sizes

programs/clickhouse-stripped: smaller than the master baseline by the known offset between the two builds, so the difference is not shown. A delta that differs from the offset by more than 50% of it is shown, in either direction.

The official master build is compiled with -g and a pull request build is not, and XRay counts debug instructions towards its instrumentation threshold, so master instruments thousands of functions more and its binary is ~0.4% larger no matter what the pull request does.

Compile time of recompiled translation units

155 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.
The matched translation units cost +116.5 s (+11%) in total before that adjustment.

Job report

@alexey-milovidov

Copy link
Copy Markdown
Member

🕵 Regarding the AI review's metadata note (Improvement → Bug Fix): keeping Improvement. Credentials in http_proxy / https_proxy were never supported on this code path (ProxyConfiguration had no fields for them), so this adds support that didn't exist before rather than fixing a regression, and it doesn't need to be backported. All review threads are resolved; CI is still running on 1923792.

@alexey-milovidov

Copy link
Copy Markdown
Member

🕵 @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 TABLE_IS_READ_ONLY on SYSTEM SYNC REPLICA test_5.t_lwu_merges PULL (undrained_mutation_errors.txt); this PR only changes proxy credential handling and does not touch replication or mutations.

@groeneai

groeneai commented Oct 4, 2026

Copy link
Copy Markdown
Collaborator

Acknowledged, this one is mine: the drain step from #123376 gives a false red here. SYSTEM RESTART REPLICA test_5.t_lwu_merges timed out after 60 s waiting for the table's WRITE lock (DEADLOCK_AVOIDED, held by a leftover stress-phase merge() SELECT from 01169_old_alter_partition_isolation_stress.sh that was stuck in S3 retries), so the replica stayed read-only and the next SYSTEM SYNC REPLICA ... PULL failed. The MUTATE_PART queue was already empty at that point. I'll fix it in upgrade_runner.sh in a separate PR and link it here.

@groeneai

groeneai commented Oct 4, 2026

Copy link
Copy Markdown
Collaborator

Fixing PR: #123841

@alexey-milovidov

Copy link
Copy Markdown
Member

🕵 Merged the latest master (ba9b156) to restart CI; the proxy-related translation units and unit tests build cleanly. @groeneai, thanks. The Upgrade check (amd_release) drain-step false positive is tracked in #123841, which is not merged yet, so that check may stay red until it lands. The author's open design question (separate <user>/<password> elements for ProxyListConfigurationResolver and RemoteProxyConfigurationResolver) is better handled in a follow-up and needs a maintainer decision (cc @arthurpassos).

@alexey-milovidov

Copy link
Copy Markdown
Member

🕵 @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 test_database_backup failures come from one start_cluster error: instance_local_metadata failed its startup access check for disk backup_disk_s3_plain because MinIO returned Access Denied (S3_ERROR, WriteBufferFromS3::makeSinglepartUpload). instance started fine against the same MinIO, which points to a race in MinIO readiness or user setup, not to this PR. This PR only changes proxy handling when credentials are set in http_proxy/https_proxy. I merged the latest master (a3dfff3) to restart CI.

@groeneai

groeneai commented Oct 6, 2026

Copy link
Copy Markdown
Collaborator

Acknowledged. I am investigating the test_database_backup start_cluster failure (instance_local_metadata startup access check on backup_disk_s3_plain, MinIO Access Denied). I could not find a fix in progress, so I will follow up here with a separate PR (or my findings) shortly.

`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]>
@groeneai

groeneai commented Oct 6, 2026

Copy link
Copy Markdown
Collaborator

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]>
@alexey-milovidov

Copy link
Copy Markdown
Member

🕵 Pushed 8fdec7c, which addresses the review: proxy credentials are now also sent on the non-tunneled https:// proxy path. The only red check on the previous commit, Stateless tests (arm_asan_ubsan, azure, sequential), hit the 9000-second job timeout at test 1153/1167 with no test failures. It is unrelated to this PR. Splitting that job into batches is in progress in #123849. The test_database_backup failure reported earlier is being fixed in #124184.

@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Oct 7, 2026
Merged via the queue into ClickHouse:master with commit a0161a7 Oct 7, 2026
149 checks passed
@robot-ch-test-poll2 robot-ch-test-poll2 added the pr-synced-to-cloud The PR is synced to the cloud repo label Oct 7, 2026
awitten1 pushed a commit to awitten1/ClickHouse that referenced this pull request Oct 10, 2026
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]>
alexey-milovidov added a commit to rorylshanks/ClickHouse that referenced this pull request Oct 13, 2026
`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]>
@clickhouse-gh clickhouse-gh Bot added comp-networking The connection layer under the protocols, on the server and on the client side: socket read / wri... and removed comp-object-storage Object storage connectivity (S3/GCS/Azure) including credentials, retries, multipart, etc. labels Nov 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

can be tested Allows running workflows for external contributors comp-networking The connection layer under the protocols, on the server and on the client side: socket read / wri... external Author is not a member of the ClickHouse organization pr-improvement Pull request with some product improvements pr-synced-to-cloud The PR is synced to the cloud repo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Proxy server configuration with username & password

6 participants