Repository navigation
Do not validate DataLakeCatalog auth_header or build catalog on ATTACH - #108674
alexey-milovidov merged 2 commits into
Conversation
A DataLakeCatalog database whose auth_header was accepted by an older version (which validated it lazily) became un-attachable after upgrading to 26.2+. The auth_header validation in registerDatabaseDataLake ran on ATTACH as well as CREATE, so at startup one database with a malformed auth_header threw BAD_ARGUMENTS during attach and the server failed to start (exit 36). On master the constructor additionally builds the catalog eagerly (RestCatalog reads the catalog config over the network), so any database with an unreachable endpoint also failed to attach at startup. Gate the auth_header validation on CREATE only, matching the existing allow_experimental_database_* gates in the same function which already self-skip on attach. Defer catalog construction to first use on ATTACH so that attach performs no validation or network I/O; the catalog is built lazily in getCatalog under catalog_mutex (the eager construction was originally a race fix, so lazy init is now synchronized). CREATE still builds eagerly and rejects malformed headers up front. A malformed auth_header is reported lazily on first use of the database, as it was before, so one misconfigured database can no longer block server startup. Co-Authored-By: Claude Opus 4.8 <[email protected]>
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-worker-slot-3:20260627-004000 |
|
cc @kssenii @scanhex12 — could you review this? It stops a |
|
Workflow [PR], commit [2f423c3] Summary: ✅
AI ReviewSummaryThis PR fixes the Missing context / blind spots
Final VerdictStatus: ✅ Approve |
The startup-block fix gated auth_header validation in registerDatabaseDataLake to CREATE only. That validation was also the only place enforcing http_forbid_headers for a persisted auth_header, so old metadata carrying a forbidden header would attach and then send it on first use, even though CREATE still rejects it. Run the forbidden-header check in the RestCatalog constructor, right after the header is parsed and before loadConfig issues the first request. That is where a user-provided auth_header first becomes a header sent to the catalog, so the check covers the deferred first-use path without reintroducing the startup block (the catalog is still built lazily on ATTACH). The CREATE path is unchanged. Extend 04401_datalake_attach_does_not_block_startup: a persisted forbidden auth_header attaches (no startup block) but is rejected on first use. The forbidden-header filter is read only by the server, so that part runs against the test server. Co-Authored-By: Claude Opus 4.8 <[email protected]>
Follow-up fix: restore
|
| # | Question | Answer |
|---|---|---|
| a | Deterministic repro? | Yes. Start a server with http_forbid_headers configured, ATTACH DATABASE ... auth_header='exact_header: some_value' (a forbidden header), then CHECK DATABASE. Before the fix the header is accepted on attach and sent on first use; the forbidden filter never runs. |
| b | Root cause explained? | The CREATE-only gate moved auth_header validation out of the ATTACH path. That validation (getHTTPHeaderFilter().checkAndNormalizeHeaders) was the ONLY enforcement of http_forbid_headers for a persisted auth_header. On the deferred first-use path RestCatalog::parseAuthHeader only splits on :, so a forbidden header attaches and is then sent on the wire. |
| c | Fix matches root cause? | Yes. The check is restored at the true trust boundary: RestCatalog's constructor, right after parseAuthHeader and before loadConfig issues any request. RestCatalog is the only catalog type that forwards a user auth_header, so this is the single point where it becomes a sent header. The startup-block fix is untouched (catalog still builds lazily on ATTACH). |
| d | Test intent preserved / new tests added? | Extended 04401_datalake_attach_does_not_block_startup: a persisted forbidden auth_header attaches (no startup block) but is rejected with "is forbidden" on first use, so it is never sent. Existing malformed/unreachable/CREATE-rejection assertions unchanged. |
| e | Both directions demonstrated? | Yes. Without the fix: forbidden header attaches and CHECK DATABASE proceeds to send it. With the fix: attach succeeds, CHECK DATABASE rejects with "is forbidden"; malformed still reports "Unexpected format of auth header"; an allowed header passes; CREATE still rejects forbidden/malformed up front. 04401 passes 5/5. |
| f | Fix is general across code paths? | Yes. auth_header flows only to RestCatalog (UnityCatalog builds its header from catalog_credential, not the user auth_header). The check sits in the constructor that all RestCatalog instances pass through, so every catalog-build that uses a user auth_header is covered. The OAuth catalog_credential path is unchanged, matching the CREATE-path scope. |
| g | Fix generalizes across inputs? | Yes. The check validates the parsed header regardless of header name/value; forbidden exact-match and regexp rules from http_forbid_headers both apply (same checkAndNormalizeHeaders the CREATE path uses). Malformed (no colon) still falls to parseAuthHeader's existing rejection. |
| h | Backward compatible? | Yes, and it is the point of the PR. ATTACH of an already-persisted database still succeeds (no startup block); the forbidden/malformed header is reported lazily on first use, matching 25.12 behavior. No on-disk/metadata/wire format change. CREATE behavior is unchanged. |
| i | Invariants and contracts preserved? | Yes. The check runs under the same path that builds catalog_impl (eager in ctor for CREATE, lazy under catalog_mutex via getCatalog for ATTACH), so no new concurrency surface. It validates a copy and keeps the original parsed header, so the sent header is unchanged when allowed. It runs before loadConfig, upholding the contract that no forbidden header is ever sent. |
Session id: cron:clickhouse-worker-slot-1:20260627-165500
LLVM Coverage Report
Changed lines: Changed C/C++ lines covered by tests: 22/30 (73.33%) | Lost baseline coverage: none · Uncovered code |
|
Found via ClickGap automated review. Please close or comment if this is incorrect or needs adjustment. TL;DRDo not validate DataLakeCatalog auth_header or build catalog on ATTACH ClickGap verified: reproduced it with the script below on ReproductionShell reproducer — run against a local ClickHouse build ( # A DataLakeCatalog DB persisted by an older version with a malformed auth_header
# must still ATTACH at server startup; the error should surface lazily on first use.
mkdir -p /tmp/dl/metadata
cat > /tmp/dl/metadata/baddb.sql <<'EOF'
ATTACH DATABASE baddb
ENGINE = DataLakeCatalog('http://localhost:8181/v1')
SETTINGS catalog_type = 'rest', auth_header = 'malformed_without_colon', warehouse = 'demo'
EOF
clickhouse local --path /tmp/dl --query "SELECT name FROM system.databases WHERE name = 'baddb'"
# Buggy: Code: 36. DB::Exception: Invalid auth header format ... while loading database `baddb`
# -> the DB fails to ATTACH at startup (server exits 36 / startup blocked).
# Fixed: baddb (attaches; the malformed header is only reported on first use, e.g. CHECK DATABASE baddb).Bisect
Affects
Suggested next stepThe bisect boundary above narrows the search in Component: cc fix PR author: @groeneai ClickGap · Finding: Triage metadata
|
… or build catalog on ATTACH
Backport #108674 to 26.6: Do not validate DataLakeCatalog auth_header or build catalog on ATTACH
Adapt cherry-pick of #108674 ("Do not validate DataLakeCatalog `auth_header` or build catalog on ATTACH") to 26.3, where the catalog is already built lazily. On `master` the fix had two parts: gate the `auth_header` validation in `registerDatabaseDataLake` on `CREATE` only, and defer eager catalog construction (`DatabaseDataLake::initialize` called from the constructor) to first use on `ATTACH`. In 26.3 the constructor only calls `validateSettings` and the catalog is already built lazily inside `getCatalog` (there is no `initialize` method and `catalog_impl` is already `mutable`), so the second part of the change does not apply and would not even compile against 26.3. Resolution: - `DatabaseDataLake.h`: kept unchanged (the `lazy_init` constructor parameter, `catalog_mutex`, and `initialize` declaration from `master` do not exist in 26.3). - `DatabaseDataLake.cpp`: applied only the `registerDatabaseDataLake` gate (`if (!args.create_query.attach && !auth_header_str.empty())`), which is the part that fixes the 26.3 startup failure. The constructor/`initialize`/`getCatalog` changes were dropped. - `RestCatalog.cpp`: kept the `http_forbid_headers` enforcement on the lazy `RestCatalog` constructor path and the `Common/HTTPHeaderFilter.h` include (auto-merged cleanly; 26.3 also builds the catalog lazily, so this is where a forbidden persisted header is first rejected). - Added the test `04401_datalake_attach_does_not_block_startup`. The resulting diff against the backport base is exactly the four files of the adapted fix; `DatabaseDataLake.h` is unchanged. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Resolve cherry-pick conflicts of #108674 for 26.5. 26.5 already builds the `DataLakeCatalog` lazily: the `DatabaseDataLake` constructor does not call `initialize()` and `getCatalog()` constructs the catalog on first access, so the master fix's `lazy_init` parameter / `initialize` restructuring / `catalog_mutex` (which moved master from eager to lazy construction) do not apply and `DatabaseDataLake.h` is left unchanged. The parts of the fix that are meaningful for 26.5 are applied: - `registerDatabaseDataLake`: gate the `auth_header` validation on CREATE only (`!args.create_query.attach`), so a database persisted by an older version with a malformed/forbidden `auth_header` no longer blocks server startup on ATTACH. - `RestCatalog`: enforce `http_forbid_headers` on the lazy build path, where the `auth_header` first becomes a request header, since validation no longer runs on ATTACH. Includes test `04401_datalake_attach_does_not_block_startup`.
Cherry pick #108674 to 26.3: Do not validate DataLakeCatalog auth_header or build catalog on ATTACH
… or build catalog on ATTACH
Cherry pick #108674 to 26.4: Do not validate DataLakeCatalog auth_header or build catalog on ATTACH
… or build catalog on ATTACH
Cherry pick #108674 to 26.5: Do not validate DataLakeCatalog auth_header or build catalog on ATTACH
… or build catalog on ATTACH
Backport #108674 to 26.5: Do not validate DataLakeCatalog auth_header or build catalog on ATTACH
Backport #108674 to 26.4: Do not validate DataLakeCatalog auth_header or build catalog on ATTACH
Backport #108674 to 26.3: Do not validate DataLakeCatalog auth_header or build catalog on ATTACH
…_block_startup_108671 Do not validate DataLakeCatalog auth_header or build catalog on ATTACH
Closes: #108671
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fixed a startup failure where a
DataLakeCatalogdatabase created by an older version (25.12 or earlier) with a malformedauth_headercould not be attached after upgrading to 26.2 or later, preventing the server from starting. Theauth_headeris now validated only onCREATE, and onATTACHthe catalog is built lazily on first use instead of during startup, so a single misconfigured or unreachable catalog database no longer blocks server startup.Description
auth_headerwas validated eagerly inregisterDatabaseDataLake(src/Databases/DataLake/DatabaseDataLake.cpp), and that validation ran onATTACHas well asCREATE. At startup every database is re-attached, so one database with a malformedauth_headerthrewBAD_ARGUMENTSduring attach and the server failed to start (exit 36). In 25.12 the same setting was parsed lazily on first use, so it never affected startup.On
masterthe failure additionally came from the constructor, becauseDatabaseDataLake::initialize()builds the catalog eagerly (theRestCatalogconstructor callsparseAuthHeaderandloadConfig()), so any database with an unreachable endpoint also failed to attach at startup.Fix:
auth_headervalidation onCREATEonly (if (!args.create_query.attach && ...)), matching the existingallow_experimental_database_*gates in the same function, which already self-skip on attach.ATTACH:initialize()is no longer called from the constructor for attach, andgetCatalog()builds the catalog lazily undercatalog_mutex. The eager construction was originally added as a race fix, so the lazy path is now synchronized. OnCREATEthe catalog is still built eagerly so misconfiguration is reported up front.A malformed
auth_headeris reported lazily on first use of the database (as in 25.12), so one misconfigured database can no longer block server startup.Affected: 26.2, 26.3, master (26.6). Introduced by #98827.
Test:
04401_datalake_attach_does_not_block_startuploads previously-persisted DataLakeCatalog databases (a malformedauth_header, and a well-formed header with an unreachable endpoint) and asserts both attach, that first use of the malformed one still reports the error, and thatCREATEwith a malformed header is still rejected.Version info
26.7.1.192(included in26.7and later)26.6.2.12,26.5.5.11,26.4.5.89,26.3.17.11