Skip to content

Cherry pick #129850 to 26.3: Apply http_forbid_headers to Basic credentials sent in the Authorization header - #132633

Merged
robot-ch-test-poll3 merged 10 commits into
backport/26.3/129850from
cherrypick/26.3/129850
Nov 18, 2026
Merged

robot-ch-test-poll3 merged 10 commits into
backport/26.3/129850from
cherrypick/26.3/129850

Conversation

@robot-clickhouse

Copy link
Copy Markdown
Member

Original pull-request #129850

Do not merge this PR manually

This pull-request is a first step of an automated backporting.
It contains changes similar to calling git cherry-pick locally.
If you intend to continue backporting the changes, then resolve all conflicts if any.
Otherwise, if you do not want to backport them, then just close this pull-request.

The check results does not matter at this step - you can safely ignore them.

Before you resolve anything

Conflicts are often caused by a prerequisite change that has not been backported yet, rather than by a real divergence. The bot re-tries this cherry-pick against the release branch on every run, so if that is the case here it will merge itself as soon as the prerequisite lands, and you will see a comment saying so. Manual resolution is only needed while the conflict persists.

Troubleshooting

If the conflicts were resolved in a wrong way

If this cherry-pick PR is completely screwed by a wrong conflicts resolution, and you want to recreate it:

  • delete the pr-cherrypick label from the PR
  • delete this branch from the repository

You also need to check the Original pull-request for pr-backports-created label, and delete if it's presented there

The PR source

The PR is created in the CI job

groeneai and others added 9 commits November 6, 2026 17:42
…` header

When `http_forbid_headers` forbids `Authorization`, an explicit
`url(..., headers('Authorization' = ...))` is refused, but Basic credentials
from the userinfo of a URL (`http://user:password@host/`) were still sent in
that header: `setCredentialsFromURL` builds `HTTPBasicCredentials`, and
`ReadWriteBufferFromHTTP::prepareRequest` synthesizes `Authorization` from them
after the explicit headers, never through `HTTPHeaderFilter`.

Check a synthetic `Authorization` header with the existing filter where each
sender gets its Basic credentials, at request time:

- `HTTPHeaderFilter::checkBasicCredentials` (no-op for an empty username,
  which sends nothing) and `checkURIUserInfo` (for `ConfluentSchemaRegistry`,
  which authenticates on any non-empty userinfo).
- `setCredentialsFromURL` takes the filter and checks there, which covers
  `url`, `urlCluster` workers, the `URL` engine, url wildcards from index
  pages, `web` disks and schema inference. Its four callers moved the call out
  of their failover `try`, so a forbidden option fails the read instead of
  being skipped.
- `HTTP` dictionaries created by DDL (`credentials(user, password)`), and
  every schema registry request of `AvroConfluent` input and output.

Request time rather than definition time, so stored definitions keep loading
(startup, `ATTACH`, replicated replay, `RESTORE`) after an administrator adds
`Authorization` to the list; only their requests are refused. Admin-defined
senders that do not go through these paths (interserver credentials of
`DataPartsExchange`, XML-config dictionaries) are unchanged.

Based on the draft #128998 by
@ kolsha (its final request-time design, unchanged), plus a test for the
`AvroConfluent` output path.

Co-authored-by: Nikolai Ovchinnikov <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
`ElasticsearchConfiguration::validate` checks the `Authorization` header of
`bearer_token` and `api_key` against `http_forbid_headers`, but
`authorizationHeaders` is empty for `user` + `password`, which
`ElasticsearchClient` sends as Basic credentials in `Authorization`. Check
them in the client constructor, i.e. per read, so a stored table still loads
after the header is forbidden and only its reads are refused.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…eb disk guards

A loaded `HTTP` dictionary keeps its source: a periodic update clones it
(`ExternalLoader` calls `clone`, and `HTTPDictionarySource::isModified` is
always true), and `DIRECT` and cache layouts call `loadIds`/`loadKeys` on the
retained source. So the check at source construction let an already loaded
DDL dictionary keep sending its Basic credentials after `SYSTEM RELOAD CONFIG`
added `Authorization` to `http_forbid_headers`. Check them in `loadAll`,
`loadUpdatedAll`, `loadIds` and `loadKeys` instead; the check at construction
is removed, since a `DIRECT` dictionary sends no request when it is created.

Tests:
- a loaded dictionary with `LIFETIME(MIN 1 MAX 1)` is refused on its next update;
- a `web` disk whose `.index` is fetched without credentials reads its data
  through `ReadBufferFromWebServer` with the userinfo, and a `web_index` disk
  probes `format_version.txt` with a HEAD request before any listing, so both
  guards are reached on their own (every other test hits the listing guard first).

Also drop the request-counter assertion of the `AvroConfluent` output test, which
could not fail: the mock server does not handle POST, so the registration
request was never counted.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The initiator of `urlCluster` checked only the host and the explicit headers,
then handed each URL to the workers, which check its userinfo under their own
`http_forbid_headers`. A worker whose configuration does not forbid
`Authorization` therefore still sent the Basic credentials although the
initiator refuses an explicit `Authorization` header. The task callback now
calls `setCredentialsFromURL` for each failover option of every URL before a
worker gets it, parsing the options as the worker does.

Test: `test_cluster_node2` has `node2`, whose configuration does not forbid the
header, as its only worker; the userinfo is in the second failover option, so
checking only the whole URL is not enough.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Drop comments that narrate the new code's design; restore master's wording of the comments the PR only moved or rephrased; shorten the API comments to one line each.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Since #123950 (merged with master in 21e71b8), `SELECT sum(id)` over the
web disk table is answered from the per-part `basic` statistics. The statistics
are loaded by the first query and kept in memory, so the query after
`http_forbid_headers` forbids `Authorization` sent no HTTP request and
`test_userinfo_with_forbidden_authorization` failed with "Client expected to be
failed but succeeded".

A filter disables that optimization, so every query reads `id` from the web
server again. The query needs no new setting, so the test stays the same on
release branches that do not have `use_statistics_for_sum_avg_aggregation`.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The existing failover case puts the credentialed option last, so it cannot
tell a refused read from one that skips the forbidden option: with no later
option, both end with the same error. With a usable second option, a read
that moved on to it would succeed. Cover both the `url()` failover loop and
the listing loop of a `url()` wildcard.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ation

Apply `http_forbid_headers` to Basic credentials sent in the `Authorization` header
@robot-clickhouse robot-clickhouse added pr-cherrypick Cherry-pick of merge-commit before backporting. Do not use manually - automated use only! do not test disable testing on pull request pr-bugfix Pull request with bugfix, not backported by default labels Nov 18, 2026
Carry the port of the cherry-pick as a tree onto the rebuilt `backport/26.3/129850` branch: the release branch was rewritten, so the earlier port cannot be pushed as is without bringing the old history back.

This branch has no `web` disk, no index pages listing and no `Elasticsearch`, so the change is ported instead of cherry-picked. Deviations from the original change, all approved:
- `StorageURLSource::setCredentials` is rewritten to call `checkBasicCredentials`; the check runs before the `try` in `getFirstAvailableURIAndReadBuffer`, and the initiator of `urlCluster` checks all failover options.
- The schema registry check is in `SchemaRegistry::fetchSchema` in `AvroRowInputFormat.cpp`.
- `checkAndNormalizeHeaders` is called instead of `checkHeaders`.
- `HTTPDictionarySource` keeps the `created_from_ddl` field of `Configuration` from #101768, which the original change relies on.
- The changes of the `web` disk, `test_disk_over_web_server`, `Elasticsearch` and `web_index` are dropped, they do not exist on this branch.
- `test_storage_url` gets 11 ported test cases, and `configs/conf.xml` a placeholder `http_forbid_headers`.
@robot-ch-test-poll3
robot-ch-test-poll3 merged commit b0cffa8 into backport/26.3/129850 Nov 18, 2026
2 checks passed
@robot-ch-test-poll3
robot-ch-test-poll3 deleted the cherrypick/26.3/129850 branch November 18, 2026 12:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

do not test disable testing on pull request pr-bugfix Pull request with bugfix, not backported by default pr-cherrypick Cherry-pick of merge-commit before backporting. Do not use manually - automated use only!

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants