Skip to content

Do not validate DataLakeCatalog auth_header or build catalog on ATTACH - #108674

Merged
alexey-milovidov merged 2 commits into
ClickHouse:masterfrom
groeneai:datalake_attach_no_block_startup_108671
Jun 28, 2026
Merged

alexey-milovidov merged 2 commits into
ClickHouse:masterfrom
groeneai:datalake_attach_no_block_startup_108671

Conversation

@groeneai

@groeneai groeneai commented Jun 27, 2026 •

Copy link
Copy Markdown
Collaborator

Closes: #108671

Changelog category (leave one):

  • Bug Fix (user-visible misbehavior in an official stable release)

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

Fixed a startup failure where a DataLakeCatalog database created by an older version (25.12 or earlier) with a malformed auth_header could not be attached after upgrading to 26.2 or later, preventing the server from starting. The auth_header is now validated only on CREATE, and on ATTACH the 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_header was validated eagerly in registerDatabaseDataLake (src/Databases/DataLake/DatabaseDataLake.cpp), and that validation ran on ATTACH as well as CREATE. At startup every database is re-attached, so one database with a malformed auth_header threw BAD_ARGUMENTS during 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 master the failure additionally came from the constructor, because DatabaseDataLake::initialize() builds the catalog eagerly (the RestCatalog constructor calls parseAuthHeader and loadConfig()), so any database with an unreachable endpoint also failed to attach at startup.

Fix:

  • Gate the auth_header validation on CREATE only (if (!args.create_query.attach && ...)), 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: initialize() is no longer called from the constructor for attach, and getCatalog() builds the catalog lazily under catalog_mutex. The eager construction was originally added as a race fix, so the lazy path is now synchronized. On CREATE the catalog is still built eagerly so misconfiguration is reported up front.

A malformed auth_header is 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_startup loads previously-persisted DataLakeCatalog databases (a malformed auth_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 that CREATE with a malformed header is still rejected.

Version info

  • Merged into: 26.7.1.192 (included in 26.7 and later)
  • Backported to: 26.6.2.12, 26.5.5.11, 26.4.5.89, 26.3.17.11

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

Copy link
Copy Markdown
Collaborator Author
Pre-PR validation gate (click to expand)
# Question Answer
a Deterministic repro? Yes. Hand-author metadata/baddb.sql with auth_header = 'malformed_without_colon' (the state an older non-validating version persisted) and load with clickhouse-local --path: unfixed binary throws Code: 36 ... Invalid auth header format ... while loading database baddb from file metadata/baddb.sql. A well-formed header with an unreachable endpoint throws Connection refused during load on master.
b Root cause explained? The auth_header validation in registerDatabaseDataLake ran unconditionally, so it fired on ATTACH (every DB is re-attached at startup) → a malformed header threw BAD_ARGUMENTS and the server failed to start. On master the constructor also built the catalog eagerly (RestCatalog ctor runs parseAuthHeader + loadConfig() network I/O), so attach did validation and network I/O that can fail at startup. 25.12 validated lazily, so it never affected startup.
c Fix matches root cause? Yes. (1) Gate the auth_header validation on !args.create_query.attach, matching the sibling allow_experimental_database_* gates. (2) Defer catalog construction to first use on attach (getCatalog() builds lazily); CREATE still builds eagerly. Both directly target the two mechanisms in (b).
d Test intent preserved / new tests added? New test 04401_datalake_attach_does_not_block_startup added (attach of malformed + unreachable persisted DBs succeeds; first use still reports the error; CREATE still rejected). Existing 03913_datalake_restful_catalog_bad_format (eager-CREATE-rejection contract) still passes unchanged.
e Both directions demonstrated? Yes. Unfixed binary (Build ID 76f844d3...): startup attach throws exit-36 Invalid auth header format. Fixed binary (0339de0c...): same metadata attaches (count=1), first use reports Unexpected format of auth header, CREATE still rejected. 04401 [ OK ] and 03913 [ OK ] via clickhouse-test.
f Fix is general across code paths? Yes. The auth_header colon-format check and the forbidden-header check share one if block, now both CREATE-only. loadFromQuery already self-skips its iceberg_ validation on attach; the experimental gates already use !attach; structural must have arguments throws can't fire on a valid persisted DB. The auth_header block + eager catalog build were the only attach-affecting validations; both are fixed.
g Fix generalizes across inputs? Lazy deferral covers ALL catalog types (Rest/OneLake/BigLake/Unity/Glue/Hive/Paimon) via the single initialize()/getCatalog() path, not just REST. Verified with both a malformed-format header and a well-formed-but-unreachable endpoint. The CREATE-only gate is independent of the specific header value.
h Backward compatible? This IS the backward-compat fix: a DB persisted by an older version must still attach after upgrade. No on-disk/metadata/wire format change; no setting default change (so no SettingsChangesHistory.cpp entry). CREATE behavior is unchanged (malformed/forbidden headers still rejected). The constructor gained a lazy_init param (internal API only).
i Invariants and contracts preserved? Yes. The eager initialize() was originally a race fix; the lazy path restores synchronization via catalog_mutex (catalog_impl is TSA_GUARDED_BY(catalog_mutex), initialize() is TSA_REQUIRES(catalog_mutex)). getCatalog() double-checks under the lock; initialize() does not call getCatalog() (no recursive lock). The lock serializes concurrent first-access, which is the correct behavior the original race fix intended.

Session id: cron:clickhouse-worker-slot-3:20260627-004000

@groeneai

Copy link
Copy Markdown
Collaborator Author

cc @kssenii @scanhex12 — could you review this? It stops a DataLakeCatalog database with a malformed auth_header (or unreachable endpoint) from blocking server startup after upgrade: auth_header is validated on CREATE only (matching the existing allow_experimental_database_* attach gates), and the catalog is built lazily on first use for ATTACH instead of eagerly in the constructor (the eager build was a race fix, so the lazy path is synchronized under a mutex). Closes #108671.

@clickhouse-gh

clickhouse-gh Bot commented Jun 27, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [2f423c3]

Summary: ✅


AI Review

Summary

This PR fixes the DataLakeCatalog upgrade/startup regression by making auth_header validation CREATE-only and deferring catalog construction on ATTACH until first use, while keeping first-use validation for malformed and forbidden headers. I found no remaining code findings; the earlier http_forbid_headers gap is addressed in RestCatalog before the first request is issued.

Missing context / blind spots
  • ⚠️ CI was still pending at review time, and this checkout has no local build directory or clickhouse binary to run 04401_datalake_attach_does_not_block_startup; passing the focused functional/stateless CI would close this.
Final Verdict

Status: ✅ Approve

@clickhouse-gh clickhouse-gh Bot added the pr-bugfix Pull request with bugfix, not backported by default label Jun 27, 2026
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]>
@groeneai

Copy link
Copy Markdown
Collaborator Author

Follow-up fix: restore http_forbid_headers on the lazy ATTACH first-use path

Addresses the review finding that gating auth_header validation to CREATE-only also removed the only enforcement of http_forbid_headers for a persisted auth_header. Pushed in 2f423c3.

Pre-PR validation gate (click to expand)
# 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

@clickhouse-gh

clickhouse-gh Bot commented Jun 27, 2026

Copy link
Copy Markdown
Contributor

LLVM Coverage Report

Metric Baseline Current Δ
Lines 85.40% 85.30% -0.10%
Functions 92.60% 92.60% +0.00%
Branches 77.60% 77.50% -0.10%

Changed lines: Changed C/C++ lines covered by tests: 22/30 (73.33%) | Lost baseline coverage: none · Uncovered code

Full report · Diff report

@alexey-milovidov alexey-milovidov self-assigned this Jun 28, 2026
@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Jun 28, 2026
Merged via the queue into ClickHouse:master with commit 90646a6 Jun 28, 2026
169 checks passed
@clickgapai

Copy link
Copy Markdown
Contributor

Found via ClickGap automated review. Please close or comment if this is incorrect or needs adjustment.

TL;DR

Do not validate DataLakeCatalog auth_header or build catalog on ATTACH

ClickGap verified: reproduced it with the script below on 26.5; tested 6 version(s) — 5 affected, 1 clean (see Affects); bisected to a candidate range — a single introducing PR could not be pinned (see Bisect).

Reproduction

Shell reproducer — run against a local ClickHouse build (bash <script> <clickhouse-binary>); requires the referenced test fixtures from the repo.

# 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

  • ✓ Fix is on master — this PR's change fixes the bug on master. Branches below still have the bug and need the backport.
  • Reproduces on: 26.5, 26.4, 26.3, 26.2, 26.1
  • Does NOT reproduce on: master
  • Backport needed: 26.5, 26.4, 26.3, 26.2, 26.1

Suggested next step

The bisect boundary above narrows the search in comp-datalake — treat the candidate range as the starting point; the single introducing PR is unconfirmed.

Component: comp-datalake
Severity: P2

cc fix PR author: @groeneai
cc fix PR reviewer: @alexey-milovidov


ClickGap · Finding: phase_d_pr108674

Triage metadata

  • Primary component: comp-datalake
  • Secondary components: comp-database-engines
  • Component owners (comp-datalake): @scanhex12 @divanik

@robot-clickhouse robot-clickhouse added the pr-synced-to-cloud The PR is synced to the cloud repo label Jun 28, 2026
@robot-clickhouse robot-clickhouse added the pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR label Jun 29, 2026
clickhouse-gh Bot pushed a commit that referenced this pull request Jun 29, 2026
clickhouse-gh Bot added a commit that referenced this pull request Jun 29, 2026
Backport #108674 to 26.6: Do not validate DataLakeCatalog auth_header or build catalog on ATTACH
alexey-milovidov added a commit that referenced this pull request Jun 30, 2026
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]>
alexey-milovidov added a commit that referenced this pull request Jun 30, 2026
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`.
robot-clickhouse added a commit that referenced this pull request Jun 30, 2026
Cherry pick #108674 to 26.3: Do not validate DataLakeCatalog auth_header or build catalog on ATTACH
robot-clickhouse added a commit that referenced this pull request Jun 30, 2026
robot-clickhouse added a commit that referenced this pull request Jun 30, 2026
Cherry pick #108674 to 26.4: Do not validate DataLakeCatalog auth_header or build catalog on ATTACH
robot-clickhouse added a commit that referenced this pull request Jun 30, 2026
robot-clickhouse added a commit that referenced this pull request Jun 30, 2026
Cherry pick #108674 to 26.5: Do not validate DataLakeCatalog auth_header or build catalog on ATTACH
robot-clickhouse added a commit that referenced this pull request Jun 30, 2026
@robot-clickhouse-ci-2 robot-clickhouse-ci-2 added the pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore label Jun 30, 2026
alexey-milovidov added a commit that referenced this pull request Jun 30, 2026
Backport #108674 to 26.5: Do not validate DataLakeCatalog auth_header or build catalog on ATTACH
alexey-milovidov added a commit that referenced this pull request Jun 30, 2026
Backport #108674 to 26.4: Do not validate DataLakeCatalog auth_header or build catalog on ATTACH
alexey-milovidov added a commit that referenced this pull request Jun 30, 2026
Backport #108674 to 26.3: Do not validate DataLakeCatalog auth_header or build catalog on ATTACH
@kssenii kssenii added v25.12-must-backport and removed pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore labels Jul 23, 2026
@robot-ch-test-poll robot-ch-test-poll added the pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore label Jul 23, 2026
zeekay pushed a commit to hanzoai/datastore that referenced this pull request Sep 11, 2026
…_block_startup_108671

Do not validate DataLakeCatalog auth_header or build catalog on ATTACH
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 pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore pr-bugfix Pull request with bugfix, not backported by default pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR pr-synced-to-cloud The PR is synced to the cloud repo v25.12-must-backport v26.2-must-backport

Projects

None yet

Development

Successfully merging this pull request may close these issues.

DataLakeCatalog with a malformed auth_header created in 25.12 prevents server startup after upgrade to 26.2+

8 participants