Skip to content

Support bearer-token authentication in BuilderRWBufferFromHTTP (attempt 2) - #115400

Merged
serxa merged 1 commit into
masterfrom
http-builder-bearer-token-attempt-2
Aug 19, 2026
Merged

serxa merged 1 commit into
masterfrom
http-builder-bearer-token-attempt-2

Conversation

@serxa

@serxa serxa commented Aug 19, 2026 •

Copy link
Copy Markdown
Member

Recreated from #110313 with the same changes.

BuilderRWBufferFromHTTP had no way to authenticate with a bearer token: callers spliced an Authorization: Bearer entry into the header list themselves and had to remember not to pass HTTP Basic credentials at the same time, because both occupy the same header. create now takes the credential directly, in three overloads: Basic credentials, a bearer token, or both — with a non-empty token taking precedence, so the either/or rule lives in one place instead of in every caller. create also appends the bearer header to a local copy of the header list rather than mutating the builder, so a builder can be reused without carrying over a stale token.

Every bearer-token call site of the class is migrated to the new overloads:

  • HTTPBasedCatalogUtils and UnityCatalog: built the header by hand and passed never-used HTTP Basic credentials alongside; now call create with the token.
  • RestCatalog, OneLakeCatalog, BigLakeCatalog: getAuthHeaders now returns an AuthHeaders (a bearer token plus extra headers). The bearer goes to create; only genuine extra headers (a user-supplied auth_header, x-goog-user-project, User-Agent) stay in the header list. OneLakeCatalog's pre-obtained token also moved from a spliced header to the bearer.
  • PaimonRestCatalog: the bearer token provider (the dlf request-signing branch keeps its own signed headers).

Out of scope — different transport (plain Poco requests or S3-client headers), not BuilderRWBufferFromHTTP: OpenAIProvider, CloudJWTProvider, ArrowFlight AuthMiddleware, GCS diskSettings.

Changelog category (leave one):

  • Not for changelog (changelog entry is not required)

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

...


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

Version info

  • Merged into: 26.8.1.1702 (included in 26.8 and later)

…pt 2)

Clone of #110313 on a fresh branch off current master — same changes, reconciled onto master. Opened because the original PR's sync pair got wedged.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@clickhouse-gh

clickhouse-gh Bot commented Aug 19, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [3491b04]

Summary: ✅


AI Review

Summary

This PR adds bearer-token support to BuilderRWBufferFromHTTP, moves Unity/Paimon callers onto that path, and adds validation/tests around malformed tokens. The direction makes sense, but I do not think it is ready to merge as-is: the new validation changes first-use behavior for already-persisted bearer-auth databases, and the test additions still do not cover the builder-reuse regression the PR description says this change fixes.

PR Metadata
  • Changelog category is correct: Not for changelog.
  • Changelog entry is not required for that category.
Findings
  • ⚠️ Major [src/Databases/DataLake/HTTPBasedCatalogUtils.cpp:45] The new bearer-token validation now fires in the request path for Unity (and the analogous new call in PaimonRestCatalog::createReadBuffer does the same for Paimon). Because those bearer tokens are persisted in database metadata, an upgrade can start rejecting an existing attached database on first use if the synthetic Authorization header now violates http_forbid_headers. ClickHouse normally keeps this kind of validation on CREATE/ALTER paths or behind compatibility handling instead of retroactively changing runtime behavior for old metadata.
  • ⚠️ Major [src/Databases/DataLake/tests/gtest_rest_catalog.cpp:617] The added tests do not hit the main behavior this PR is changing. OneLakeCatalog token validation was already present before this patch, and the helper-level validateBearerToken test does not prove that reusing one BuilderRWBufferFromHTTP no longer leaks the previous Authorization header. A focused request-level regression test is still needed for the new builder contract.
Final Verdict

⚠️ Needs changes before merge.

LLVM Coverage Report

Metric Baseline Current Δ
Lines 86.80% 86.90% +0.10%
Functions 91.90% 92.00% +0.10%
Branches 79.20% 79.30% +0.10%

Changed lines: Changed C/C++ lines covered: 73/96 (76.04%) · Uncovered code

Full report · Diff report

@clickhouse-gh clickhouse-gh Bot added the pr-not-for-changelog This PR should not be mentioned in the changelog label Aug 19, 2026
const std::string & method,
std::function<void(std::ostream &)> out_stream_callaback)
{
validateBearerToken(context, bearer_token);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This changes behavior for already-persisted Unity/Paimon databases, not just new CREATE DATABASE statements. Their bearer token is stored in metadata (catalog_credential for Unity, catalog_credential/PaimonToken in bearer mode), so an attached database that previously worked can now start throwing BAD_ARGUMENTS on first use if the synthetic Authorization header trips http_forbid_headers. ClickHouse usually keeps this kind of validation on the CREATE/ALTER path specifically to avoid retroactively rejecting old metadata; if this hardening is intended, it needs either a compatibility gate or a create-time validation path for newly created objects.

auto context = DB::Context::createCopy(getContext().context);
context->makeQueryContext();

/// Every bearer-token catalog path (Unity, and Paimon via HTTPBasedCatalogUtils) runs this

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

These tests still do not exercise the main regression the patch claims to fix. OneLakeCatalog already validated a pre-obtained token before this PR, and validateBearerToken only checks the helper in isolation. The changed contract is in BuilderRWBufferFromHTTP::createWithBearerToken: reusing one builder for multiple requests must not leak the previous Authorization header, and bearer/basic precedence must stay stable. Without a request-level test that reuses one builder across two calls, that behavior is still unproven and easy to regress silently.

@clickhouse-gh

clickhouse-gh Bot commented Aug 19, 2026

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing 3491b043b with master 071c010ef (stripped binary size, per-symbol sizes and ThinLTO time; compile times per translation unit against the most recent warmup build that recompiled it).

✅ No significant changes.

Binary sizes
Binary Master PR Δ
programs/clickhouse-stripped 701.99 MiB 698.96 MiB -3.02 MiB (-0.43%)

Only the stripped binary is compared: the official master build keeps debug symbols while PR builds strip them, so the other binaries differ by construction.

Compile time of recompiled translation units

50 translation units recompiled, 328 s compile time in total, 50 of them have a recent master baseline.

Job report

@clickhouse-gh

clickhouse-gh Bot commented Aug 19, 2026

Copy link
Copy Markdown
Contributor

📊 Cloud Performance Report

✅ AI verdict: no_change — no significant changes across 34 queries analysed

This PR only reworks DataLake REST-catalog bearer-token authentication (Unity/Paimon/OneLake) and the HTTP read buffer's Authorization handling — none of which is on the ClickBench query-execution path. The two flagged queries (Q30 +22.7%, Q31 +21.6%) both show essentially flat CPU time with the increase confined to wall clock, the signature of page-cache/IO variance rather than real extra work. The deterministic gate already held both within master's current-era variance band, and that call is correct and consistent with the diff. No action needed on these numbers.

clickbench

⚠️ 2 inconclusive

Flagged queries (2 of 43)
Query Verdict Baseline median (ms) PR median (ms) Change q-value Hint
⚠️ 30 not_sure 229 281 +22.7% <0.0001 cache: CPU time is essentially flat (2469.7ms vs 2475.2ms) while wall time rose +22.7%, so the delta is page-cache/IO variance, not extra work. This PR only touches DataLake catalog bearer-token auth, which Q30 never executes.
⚠️ 31 not_sure 299 364 +21.6% <0.0001 cache: Same story as Q30: CPU flat (3482.8ms vs 3516.7ms) against a +21.6% wall-time move, and the diff is confined to catalog HTTP auth. This is run-to-run variance, correctly held within the baseline envelope.

Change = percent below ×2; the ratio of medians (×N faster/slower) beyond, where percent understates the scale. q-value = BH-FDR adjusted p; smaller is stronger evidence. MIRAI flags a query when q < fdr_q (default 0.10) — the value the verdict is based on.

tpch_adapted_1_official

🟢 No significant changes

Debug info
  • StressHouse run: 08907a9e-0f83-4666-b6ec-8beb0bd6a49b
  • MIRAI run: 08d47e46-e0f8-443f-88a4-24925dd6ce2e
  • PR check IDs:
    • clickbench_88431_1787136953
    • clickbench_88442_1787136953
    • clickbench_88450_1787136953
    • tpch_adapted_1_official_88461_1787136953
    • tpch_adapted_1_official_88487_1787136953
    • tpch_adapted_1_official_88501_1787136953

@vdimir vdimir self-assigned this Aug 19, 2026
@serxa
serxa added this pull request to the merge queue Aug 19, 2026
Merged via the queue into master with commit 8a49692 Aug 19, 2026
179 of 180 checks passed
@serxa
serxa deleted the http-builder-bearer-token-attempt-2 branch August 19, 2026 14:46
@robot-clickhouse-ci-1 robot-clickhouse-ci-1 added the pr-synced-to-cloud The PR is synced to the cloud repo label Aug 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr-not-for-changelog This PR should not be mentioned in the changelog 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.

3 participants