Skip to content

Implement http header validation for DataLakeCatalog - #98827

Merged
michael-anastasakis merged 8 commits into
masterfrom
datalake-http-header-bug-fix
Apr 16, 2026
Merged

michael-anastasakis merged 8 commits into
masterfrom
datalake-http-header-bug-fix

Conversation

@michael-anastasakis

@michael-anastasakis michael-anastasakis commented Mar 5, 2026 •

Copy link
Copy Markdown
Member

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):

DataLakeCatalog now respects the server's http_forbid_headers configuration when validating the auth_header setting.


Note

Medium Risk
Changes CREATE DATABASE ... ENGINE=DataLakeCatalog validation behavior by rejecting forbidden HTTP headers earlier, which could break existing configs that relied on previously-accepted headers.

Overview
DataLakeCatalog now enforces server-level forbidden header rules at database creation time. When auth_header is provided in name: value form, it is checked/normalized via HTTPHeaderFilter (respecting http_forbid_headers) and rejected if forbidden.

Tests are updated to use a properly formatted auth_header (e.g. Authorization: ...) and a new stateless test case asserts that malformed headers without a colon still create successfully (lazy failure later), while explicitly forbidden headers fail during CREATE DATABASE.

Written by Cursor Bugbot for commit 35cb194. This will update automatically on new commits. Configure here.

Version info

  • Merged into: 26.4.1.997 (included in 26.4 and later)
  • Backported to: 26.3.11.22, 25.8.29.8

@clickhouse-gh

clickhouse-gh Bot commented Mar 5, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [5198f32]

Summary: ❌

job_name test_name status info comment
Stateless tests (amd_debug, distributed plan, s3 storage, parallel) failure
02835_nested_array_lowcardinality FAIL cidb, issue ISSUE EXISTS

AI Review

Summary

This PR adds creation-time validation for DataLakeCatalog auth_header: malformed values without : now throw BAD_ARGUMENTS, and formatted headers are checked against http_forbid_headers. Test coverage was extended across integration and stateless tests. High-level verdict: good direction, but there is one backward-compatibility blocker on ATTACH paths because validation currently runs unconditionally in create_fn.

Missing context
  • ⚠️ No CI logs/results were provided in this review context.
Findings

❌ Blockers

  • [src/Databases/DataLake/DatabaseDataLake.cpp:947-962] New auth_header format validation runs for both CREATE and ATTACH (unconditional in create_fn). This can break backward compatibility for existing metadata that previously attached successfully but contains legacy auth_header values.
    Suggested fix: gate strict format validation to non-attach flow (for example if (!args.create_query.attach)), or introduce a compatibility toggle/migration path.

⚠️ Majors

  • [src/Databases/DataLake/DatabaseDataLake.cpp:952-956] Validation accepts any string containing :, including empty header names (e.g. ': token'), while message says HeaderName: HeaderValue. This leaves malformed headers reachable despite new strict validation intent.
    Suggested fix: explicitly reject empty/whitespace-only header names before calling checkAndNormalizeHeaders.
Tests
  • ⚠️ Add an ATTACH DATABASE ... ENGINE = DataLakeCatalog regression test for legacy auth_header values to lock backward-compatibility behavior.
ClickHouse Rules
Item Status Notes
Deletion logging ➖
Serialization versioning ➖
Core-area scrutiny ✅
No test removal ✅
Experimental gate ➖
No magic constants ✅
Backward compatibility ❌ ATTACH compatibility risk from unconditional validation
SettingsChangesHistory.cpp ➖
PR metadata quality ✅
Safe rollout ⚠️ Rollout is risky until ATTACH behavior is compatibility-safe
Compilation time ✅
No large/binary files ✅
Final Verdict
  • Status: ⚠️ Request changes
  • Minimum required actions:
    • Make auth_header strict validation compatibility-safe for ATTACH / existing metadata.
    • Tighten format validation to reject empty header names.

@clickhouse-gh clickhouse-gh Bot added the pr-bugfix Pull request with bugfix, not backported by default label Mar 5, 2026
@kssenii kssenii self-assigned this Mar 5, 2026
{
throw Exception(ErrorCodes::BAD_ARGUMENTS, "Invalid auth header format. Expected 'HeaderName:HeaderValue'");
}
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Header validation runs during ATTACH blocking server restart

High Severity

The new forbidden-header validation runs unconditionally in the factory's create_fn, which is invoked for both CREATE DATABASE and ATTACH DATABASE (server restart). The comment says "during creation" but there's no !args.create_query.attach guard. If a server admin later adds a previously-allowed header to http_forbid_headers, existing databases using that header will fail to attach on restart, potentially preventing the server from starting. The HTTPDictionarySource avoids this by guarding with created_from_ddl, and the other checks in the same file (lines 1007, 1020, etc.) already use !args.create_query.attach.

Fix in Cursor Fix in Web

}
else
{
throw Exception(ErrorCodes::BAD_ARGUMENTS, "Invalid auth header format. Expected 'HeaderName:HeaderValue'");

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Duplicated header parsing logic with RestCatalog's parseAuthHeader

Low Severity

The header-format parsing logic (finding :, splitting into name/value, throwing on missing :) duplicates parseAuthHeader in RestCatalog.cpp (lines 85–94). If the expected format ever changes, both copies need updating. Reusing the existing function would keep the format validation consistent and reduce maintenance risk.

Fix in Cursor Fix in Web

@kssenii

kssenii commented Mar 5, 2026

Copy link
Copy Markdown
Member

@michael-anastasakis let's also adjust 03913_datalake_restful_catalog_bad_format to use correct auth header format instead of auth_header = '\''wrong.header'\'',

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.

@michael-anastasakis

Copy link
Copy Markdown
Member Author

@kssenii : I actually think the output of that test is okay since it throws an error on wrong format, not a forbidden header. The missing part was the change of line in the reference file which I updated. WDYT?

@kssenii

kssenii commented Mar 5, 2026

Copy link
Copy Markdown
Member

I think it is supposed to be wrong header, not wrong format header. The test was added in #96680 and has a comment when we create a restful datalake catalog with a invalid auth_header, it will break system.tables. We should catch this exception.. So the test must successfully create a database with incorrect header and not break system.tables after that. So currently the database is not created successfully and therefore we do not check the case with system.tables.

Comment on lines -957 to -960
else
{
throw Exception(ErrorCodes::BAD_ARGUMENTS, "Invalid auth header format. Expected 'HeaderName:HeaderValue'");
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think it does make sense to have this validation, why remove? For the failed test I think it could be enough to have something like Authorization: Wrong header

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I assumed from the PR #96680 the goal was to allow the lazy creation of the database and have it fail on the format when executed.

If I re-introduce the error throwing there then the test will still fail. I'm all for re-introducing and preventing the creation to begin with so maybe I misunderstood your initial point.

@kssenii kssenii Mar 10, 2026 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

My idea was that in that test we could just switch Wrong header to Authorization: Wrong header -- so your new exception will not apply to it, but the header will still not allow to connect successfully - which the test checks that it does not lead to failed system.tables query.

And add a separate test to test your change specifically - that header validation works.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@michael-anastasakis so let's take that validation back and just update the test to use Authorization: Wrong header instead of just Wrong header? (Since the test, which used to to fail, tests behaviour on incorrect credentials, not incorrect credentials format)

@alexey-milovidov alexey-milovidov added the close in a month if not active This will be closed in case of no information label Apr 6, 2026
…der format

Restore the `else` branch in `registerDatabaseDataLake` that throws an
exception when `auth_header` is provided without a colon (i.e. not in
`name: value` format). This was removed in a previous commit but kssenii
asked to keep this validation.

Update `03913_datalake_restful_catalog_bad_format` to use
`Authorization: Wrong header` instead of `wrong.header` so the test
continues to exercise the "bad credentials" path (verifying
`system.tables` does not fail) without triggering the format-validation
exception.

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
if (database_engine_define->settings)
database_settings.loadFromQuery(*database_engine_define, args.create_query.attach);

const auto & auth_header_str = database_settings[DatabaseDataLakeSetting::auth_header].value;

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 validation now runs for both CREATE and ATTACH because it is unconditional in create_fn. That creates a backward-compatibility risk: existing DataLakeCatalog metadata with legacy auth_header values (without :) that previously attached may now start failing during ATTACH/startup.

Please gate strict format validation to non-attach flows (for example if (!args.create_query.attach)) or provide a compatibility setting/migration path.

Comment thread CHANGELOG.md Outdated
* Fix query obfuscator (`clickhouse-format --obfuscate`) to produce parseable SQL in more cases. [#97584](https://github.com/ClickHouse/ClickHouse/pull/97584) ([Alexey Milovidov](https://github.com/alexey-milovidov)).

#### Bug Fix (user-visible misbehavior in an official stable release)
* `DataLakeCatalog` now respects the server's `http_forbid_headers` configuration when validating the `auth_header` setting. [#98827](https://github.com/ClickHouse/ClickHouse/pull/XXXXX) ([Michael Anastasakis](https://github.com/michael-anastasakis)).

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.

The changelog link still contains placeholder XXXXX, so the rendered entry points to a broken PR URL. Please replace it with the actual PR number (98827).

Add `test_invalid_auth_header_format` to the three iceberg catalog
integration test suites (REST, Nessie, Lakekeeper). Each test verifies
that `CREATE DATABASE` with an `auth_header` that has no colon
(e.g. `wrong.header`) is rejected at creation time with
`Invalid auth header format`.

These tests fail on master (where no format validation exists) and pass
on this PR, satisfying the Bugfix validation CI requirement.

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
Comment thread CHANGELOG.md Outdated
* Fix query obfuscator (`clickhouse-format --obfuscate`) to produce parseable SQL in more cases. [#97584](https://github.com/ClickHouse/ClickHouse/pull/97584) ([Alexey Milovidov](https://github.com/alexey-milovidov)).

#### Bug Fix (user-visible misbehavior in an official stable release)
* `DataLakeCatalog` now respects the server's `http_forbid_headers` configuration when validating the `auth_header` setting. [#98827](https://github.com/ClickHouse/ClickHouse/pull/XXXXX) ([Michael Anastasakis](https://github.com/michael-anastasakis)).

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.

The changelog entry currently describes only http_forbid_headers enforcement, but this PR also changes behavior by rejecting malformed auth_header values (without :) during CREATE DATABASE.

Please expand the entry to mention both user-visible changes, for example:

DataLakeCatalog now validates auth_header during CREATE DATABASE: malformed values without name: value are rejected with BAD_ARGUMENTS, and formatted headers are checked against http_forbid_headers.

@alexey-milovidov alexey-milovidov removed the close in a month if not active This will be closed in case of no information label Apr 13, 2026
auto pos = auth_header_str.find(':');
if (pos != std::string::npos)
{
DB::HTTPHeaderEntries header_entries{{auth_header_str.substr(0, pos), auth_header_str.substr(pos + 1)}};

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.

The new validation only checks for the presence of :, so values like ': token' (empty header name) still pass creation-time validation, despite the error text saying we expect HeaderName: HeaderValue.

This keeps a malformed auth_header reachable and can still fail later in request construction, so the strict validation is currently incomplete.

Could we additionally reject empty header names (and likely all-whitespace names) here before calling checkAndNormalizeHeaders?

Comment thread CHANGELOG.md Outdated
* Fix query obfuscator (`clickhouse-format --obfuscate`) to produce parseable SQL in more cases. [#97584](https://github.com/ClickHouse/ClickHouse/pull/97584) ([Alexey Milovidov](https://github.com/alexey-milovidov)).

#### Bug Fix (user-visible misbehavior in an official stable release)
* `DataLakeCatalog` now respects the server's `http_forbid_headers` configuration when validating the `auth_header` setting. [#98827](https://github.com/ClickHouse/ClickHouse/pull/98827) ([Michael Anastasakis](https://github.com/michael-anastasakis)).

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

AFAIK we do not need to manually modify changelog, it will be auto-generated under a patch release number.

@clickhouse-gh

clickhouse-gh Bot commented Apr 13, 2026

Copy link
Copy Markdown
Contributor

LLVM Coverage Report

Metric Baseline Current Δ
Lines 84.00% 84.10% +0.10%
Functions 90.90% 90.90% +0.00%
Branches 76.50% 76.60% +0.10%

Changed lines: 90.00% (9/10) · Uncovered code

Full report · Diff report

@michael-anastasakis
michael-anastasakis added this pull request to the merge queue Apr 16, 2026
robot-clickhouse-ci-1 added a commit that referenced this pull request May 14, 2026
Cherry pick #98827 to 26.2: Implement http header validation for DataLakeCatalog
@robot-ch-test-poll4 robot-ch-test-poll4 added the pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore label May 14, 2026
Algunenano added a commit that referenced this pull request May 15, 2026
Backport #98827 to 26.2: Implement http header validation for DataLakeCatalog
@Algunenano Algunenano added v26.3-must-backport and removed pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore labels May 15, 2026
robot-ch-test-poll3 added a commit that referenced this pull request May 15, 2026
Cherry pick #98827 to 26.3: Implement http header validation for DataLakeCatalog
@robot-ch-test-poll2 robot-ch-test-poll2 added the pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore label May 15, 2026
Algunenano added a commit that referenced this pull request May 15, 2026
Backport #98827 to 26.3: Implement http header validation for DataLakeCatalog
@michael-anastasakis michael-anastasakis 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 Jun 14, 2026
@robot-clickhouse robot-clickhouse added the pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore label Jun 14, 2026
@michael-anastasakis michael-anastasakis added v25.8-must-backport and removed pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore labels Jul 5, 2026
Algunenano added a commit that referenced this pull request Jul 6, 2026
Resolve conflicts for the backport of #98827 to 25.8:
- Keep only the new `HTTPHeaderFilter.h` include (25.8 has no `FailPoint.h` include here).
- `test_database_iceberg`: keep only the new `test_invalid_auth_header_format`, dropping master-only tests.
- `test_database_iceberg_nessie_catalog` does not exist in 25.8, keep it deleted.
- `03913_datalake_restful_catalog_bad_format`: keep only the forbidden-header check added by this PR. The first half of the master test relies on #96680, which is not in 25.8.

Co-Authored-By: Claude Fable 5 <[email protected]>
robot-ch-test-poll3 added a commit that referenced this pull request Jul 6, 2026
Cherry pick #98827 to 25.8: Implement http header validation for DataLakeCatalog
@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 Jul 6, 2026
Algunenano added a commit that referenced this pull request Jul 8, 2026
Backport #98827 to 25.8: Implement http header validation for DataLakeCatalog
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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 v26.3-must-backport

Projects

None yet

Development

Successfully merging this pull request may close these issues.

10 participants