Repository navigation
Apply http_forbid_headers to Basic credentials sent in the Authorization header - #129850
Conversation
…` 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 ClickHouse#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]>
Internal second-model review (click to expand)
|
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-impl-slot-5:20261106-222600 |
|
Workflow [PR], commit [fcc692d] Summary: ✅
AI ReviewSummaryPR #129850 applies Missing context / blind spots
Final VerdictStatus: ✅ Approve. |
|
cc @kolsha @Algunenano, could you review this and add the |
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Slowest function optimization changes (ThinLTO)Median per-function time ratio to the master baseline:
Compile time of recompiled translation units59 translation units recompiled, 472 s compile time in total, 59 of them have a recent master baseline. Median compile-time ratio to the baselines is ×1.05 (machine-speed difference or a change affecting every TU); per-TU deltas below are relative to that ratio. |
CI finish ledger - 224d61dEvery failure below has an owner: a fixing PR (mine or external), or a full-effort fix task
No job was dropped. The Session id: cron:our-pr-ci-monitor:20261107-033004 |
|
@groeneai merge recent master in |
Since ClickHouse#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]>
Head branch was pushed to by a user without write access
|
Thanks for merging master, and sorry for the slow reply. The merge brought in #123950, which answers
My push turned auto-merge off (I have no write access to the repo), so it needs to be enabled again. |
The new tests of #129850 call it to check the refusal, but it came to master's test file with #126184, which is not on 26.10, so those cases fail with `NameError`. Co-Authored-By: Claude Opus 5.5 <[email protected]>
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`.
Carry the conflict resolution of the cherry-pick as a tree onto the rebuilt `backport/26.9/129850` branch: the release branch was rewritten, so the earlier resolution cannot be pushed as is without bringing the old history back. Deviations from the original change, all approved: - `HTTPDictionarySource` keeps the `created_from_ddl` field of `Configuration` from #101768, which the original change relies on. - The `Elasticsearch` hunk and the `test_storage_elasticsearch` changes are dropped, the engine does not exist on this branch. - `checkAndNormalizeHeaders` is called instead of `checkHeaders`. - `test_storage_url` gets the helper `server_part_of_error` for the error assertions. - The redirect fixture of `index_pages_server.py` puts userinfo into `Location` as on master (from #126184), so that `test_url_redirect_userinfo_is_not_sent_with_forbidden_authorization` exercises the redirect with credentials. The masking of the URL in the error of `rejectOriginChangingRedirect` from #126184 is not ported: it is not part of this change, and the branch keeps its existing behavior.
Carry the conflict resolution of the cherry-pick as a tree onto the rebuilt `backport/26.8/129850` branch: the release branch was rewritten, so the earlier resolution cannot be pushed as is without bringing the old history back. Deviations from the original change, all approved: - `HTTPDictionarySource` keeps the `created_from_ddl` field of `Configuration` from #101768, which the original change relies on. - The `Elasticsearch` hunk and the `test_storage_elasticsearch` changes are dropped, the engine does not exist on this branch. - `checkAndNormalizeHeaders` is called instead of `checkHeaders`. - `test_storage_url` gets the helper `server_part_of_error` for the error assertions. - The tests use the setting name `allow_experimental_url_wildcard_from_index_pages`, as it is named on this branch. - The redirect fixture of `index_pages_server.py` puts userinfo into `Location` as on master (from #126184), so that `test_url_redirect_userinfo_is_not_sent_with_forbidden_authorization` exercises the redirect with credentials. The masking of the URL in the error of `rejectOriginChangingRedirect` from #126184 is not ported: it is not part of this change, and the branch keeps its existing behavior.
Cherry pick #129850 to 26.3: Apply `http_forbid_headers` to Basic credentials sent in the `Authorization` header
…tials sent in the `Authorization` header
Cherry pick #129850 to 26.8: Apply `http_forbid_headers` to Basic credentials sent in the `Authorization` header
…tials sent in the `Authorization` header
Cherry pick #129850 to 26.9: Apply `http_forbid_headers` to Basic credentials sent in the `Authorization` header
…tials sent in the `Authorization` header
Backport #129850 to 26.10: Apply `http_forbid_headers` to Basic credentials sent in the `Authorization` header
Backport #129850 to 26.3: Apply `http_forbid_headers` to Basic credentials sent in the `Authorization` header
Backport #129850 to 26.8: Apply `http_forbid_headers` to Basic credentials sent in the `Authorization` header
Backport #129850 to 26.9: Apply `http_forbid_headers` to Basic credentials sent in the `Authorization` header
Related: #128998
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
When
http_forbid_headersforbidsAuthorization, Basic credentials that would be sent in that header are now refused too: the userinfo ofurl,urlClusterandURLtable URLs (including url wildcards andwebdisks),credentialsofHTTPdictionaries created by DDL, the userinfo offormat_avro_schema_registry_url, anduser/passwordof theElasticsearchengine. Before, only an explicitAuthorizationheader was refused.Description
On 26.8.18.2, 26.9.19.9 and 26.10.2.103, with
<http_forbid_headers><header>Authorization</header></http_forbid_headers>,url(..., headers('Authorization' = ...))is refused, buturl('http://user:password@host/...')still sendsAuthorization: Basic ...: the credentials parsed from the userinfo are turned into that header inReadWriteBufferFromHTTP::prepareRequest, after the explicit headers and never throughHTTPHeaderFilter.This adopts the request-time design of @ kolsha's draft #128998:
HTTPHeaderFilter::checkBasicCredentials/checkURIUserInfocheck a syntheticAuthorizationheader with the existing filter, insetCredentialsFromURL(every URL-userinfo sender), each request of a DDLHTTPdictionary, and each schema registry request. A forbidden failover option fails the read instead of being skipped. Credentials with an empty username send nothing and are not refused, except by the schema registry, which sends any userinfo. StoredURLandElasticsearchtables stay attached after the header is forbidden, and a loadedHTTPdictionary is refused on its next update; only requests are refused. Admin-only senders (interserver credentials, XML dictionaries) are unchanged.Added on top of #128998: the
HTTPdictionary is checked per request instead of when its source is created, the initiator ofurlClusterchecks every URL before a worker gets it (a worker checks it under its own configuration, which can differ), the same check forElasticsearchuser/password, and tests for thewebdisk read,web_indexmetadata andAvroConfluentoutput paths. This PR supersedes the draft #128998.Validation: integration tests in
test_storage_url,test_disk_over_web_serverandtest_storage_elasticsearch; the 16 forbidden-header cases fail on master and pass with the fix, the empty-username and redirect cases pass on both.Workflow [PR]
Sync PR [sync-upstream/pr/129850]
Version info
26.11.1.1926-master(included in26.11and later)26.10.7.4,26.9.32.11,26.8.40.11,26.3.67.17