Skip to content

MySQL: reject an empty TLS contents override also when the collection stores contents - #113947

Merged
alexey-milovidov merged 7 commits into
masterfrom
fix-mysql-empty-pem-override
Aug 12, 2026
Merged

alexey-milovidov merged 7 commits into
masterfrom
fix-mysql-empty-pem-override

Conversation

@alexey-milovidov

@alexey-milovidov alexey-milovidov commented Aug 8, 2026 •

Copy link
Copy Markdown
Member

Related: #112070
Related: #110615

The empty-override rejection in StorageMySQL::getSSLParams only ran when the base named collection stored a credential path: with the credential stored in the contents form (ssl_ca_pem / ssl_cert_pem / ssl_key_pem), get_path returned at the empty-path fast path before looking at isQueryOverridden, so a query could pass ssl_ca_pem = '' and silently strip the collection-provided CA or client certificate — e.g. disable the verification of the server certificate — on every MySQL surface using that collection. The check is now hoisted above the fast path, so an empty contents override is rejected regardless of the form the stored credential has.

The same defect in the PostgreSQL counterpart was found by the AI review in #110615, where it is fixed the same way; this is the twin fix for the MySQL surface introduced in #112070. The existing empty-override test gains the contents-storing-collection case.

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 defect in the MySQL integrations where overriding a TLS credential of a named collection with an empty ssl_ca_pem/ssl_cert_pem/ssl_key_pem value was accepted when the collection stored the credential in the contents form, silently dropping the configured CA or client certificate instead of rejecting the override.

Version info

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

… stores contents

The empty-override rejection in `StorageMySQL::getSSLParams` only ran
when the base named collection stored a credential *path*: with the
credential stored in the contents form (`ssl_ca_pem` / `ssl_cert_pem` /
`ssl_key_pem`), `get_path` returned at the empty-path fast path before
looking at `isQueryOverridden`, so a query could pass `ssl_ca_pem = ''`
and silently strip the collection-provided CA or client certificate,
e.g. disable the verification of the server certificate. The check is
now hoisted above the fast path, so an empty contents override is
rejected regardless of the form the stored credential has.

The same defect in the PostgreSQL counterpart (#110615) was flagged by
the AI review there; this is the twin fix for the MySQL surface that
had already merged in #112070.
@clickhouse-gh

clickhouse-gh Bot commented Aug 8, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [0c661a5]

Summary: ✅


AI Review

Summary

This PR fixes the MySQL named-collection TLS override gap where an empty ssl_*_pem query override could silently drop a stored credential when the collection kept that credential in contents form. I verified the current diff and live code in the override helpers, NamedCollection bookkeeping, StorageMySQL::getSSLParams, and the dictionary / engine call sites, and I also re-checked the two resolved review threads against the current code. The fixes are present, the new behavior is covered on the AST and dictionary-DDL paths, and I did not find a remaining correctness, safety, or evidence gap that should block merge.

Final Verdict
  • Status: ✅ Approve

LLVM Coverage Report

Metric Baseline Current Δ
Lines 86.70% 86.70% +0.00%
Functions 92.00% 92.00% +0.00%
Branches 79.00% 79.00% +0.00%

Changed lines: Changed C/C++ lines covered: 31/33 (93.94%) · Uncovered code

Full report · Diff report

@clickhouse-gh clickhouse-gh Bot added the pr-bugfix Pull request with bugfix, not backported by default label Aug 8, 2026
Comment thread src/Storages/StorageMySQL.cpp Resolved
@clickhouse-gh

clickhouse-gh Bot commented Aug 8, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

No arm_release build profile data for commit 0c661a5 - the build was skipped, reused from cache, or predates profile upload.

… a stored credential

The hoisted check was broader than the defect it fixed: it rejected an
empty `ssl_*_pem` override even when the collection carried no TLS
credential at all, where the override drops nothing and used to be
a harmless no-op - and stayed one for the direct arguments.

`markQueryOverridden` now remembers the value the collection itself
stored for the key (it is called before the override is written), and
`StorageMySQL::getSSLParams` consults it through
`getValueBeforeQueryOverride`: the empty contents override is rejected
only when the collection stores the credential in either form - the
path (which a query cannot override, so its key still holds the
collection's own value) or the contents (read in its pre-override
form). A collection without the credential accepts the no-op override
again, consistent with `mysql(..., ssl_ca_pem = '')` without a named
collection.

Co-Authored-By: Claude Fable 5 <[email protected]>
…de case

The overrides of `SOURCE(MYSQL(NAME ...))` reach the collection through the
generated-config overload of `tryGetNamedCollectionWithOverrides`, which this
change also modified; the regression only exercised the AST overload. The new
case overrides the contents-storing collection with `SSL_CA_PEM ''` in a
dictionary created with a DDL query and expects the load to be rejected.
@alexey-milovidov

Copy link
Copy Markdown
Member Author

🕵 Merged master (the branch was 500 commits / ~2.5 days behind and red) and re-triggered CI. All three stress-test failures on d7fee0fd are unrelated to this PR, which only touches NamedCollection query-override bookkeeping and StorageMySQL::getSSLParams:

  • Logical error: Sizes of nested column and null map of Nullable column are not equal after deserialization — Stress test (amd_debug) and Stress test (arm_tsan). Master history shows this firing on master itself and on dozens of unrelated pull requests (40 hits on 2026-08-09 alone, pull_request_number = 0 among them), so it is a pre-existing failure, and I could not find a tracking issue for it.
  • Logical error: Bad cast from type A to B (STID: 1499-2747) — Stress test (amd_asan_ubsan), tracked by Logical error: Bad cast from type A to B (STID: 1499-2747) #113640, still open with no fix on master.

@groeneai, investigate the failures:

and provide a fix in a separate PR (the first one also needs a tracking issue). If a fix is already in progress, link it here.

@alexey-milovidov

Copy link
Copy Markdown
Member Author

🕵 Correction on the first failure: it is tracked. The stack trace goes through MergeTreeIndexGranuleSet::deserializeBinary → SerializationNullable::deserializeBinaryBulkWithMultipleStreams, i.e. a stale set skip index decoded with the new column type — #112213, with a fix in the open pull request #112484 (Related: #106988). Neither is on master yet, so the master merge cannot clear it.

So both unrelated stress failures have tracking issues with fixes pending elsewhere, and nothing further is needed on this pull request:

@groeneai, no new investigation is needed for the first one — please disregard the tracking-issue request in my previous comment.

@groeneai

Copy link
Copy Markdown
Collaborator

Both fixes are in progress, and both are mine:

Both are open and mergeable. Agreed nothing further is needed here, and I am not filing a tracking issue.

@alexey-milovidov

Copy link
Copy Markdown
Member Author

🕵 Merged master again: the Stress test (arm_debug) failure on c044f208 (Logical error: 'Bad cast from type DB::ColumnString to DB::ColumnNullable' in SerializationNullable::enumerateStreams via collectOffsetsColumns, STID 3520-4525) is the read-path variant tracked in #113891, and its fix #113925 merged on 2026-08-10 after this branch's previous master merge — pulling it in should clear that red. The other failure, test_storage_nats/test_nats_jet_stream.py::test_nats_restore_failed_connection_without_losses_on_write (Integration tests arm_binary, distributed plan 4/4), is a pre-existing cross-PR flake (10 different PRs hit it on 2026-08-10 alone) with a fix in progress in #112828.

@alexey-milovidov

Copy link
Copy Markdown
Member Author

🕵 Merged master again: both reds on 72ab3789 were unrelated to this PR. The Build (arm_tidy) failure was a readability-container-contains error in src/Databases/DatabaseRemote.cpp:1058 — a file from the newly merged Remote database engine (#110975) that this PR does not touch; master already carries the fix (host.contains(':')), so the merge pulls it in. The Finish Workflow bugfix-validation red was a cascade of that build failure: the per-arch Bugfix validation (integration tests) jobs were DROPPED (never ran), not a verdict on the test itself. The four translation units touched by this PR rebuilt cleanly after the merge.

@alexey-milovidov

Copy link
Copy Markdown
Member Author

🕵 Merged master again for a fresh CI round. The sole red on 6032e938 — Stress test (arm_debug), Logical error: Sizes of nested column and null map of Nullable column are not equal after deserialization in MergeTreeIndexGranuleSet::deserializeBinary (STID 6726-6673) — is the same stale set skip-index flake already discussed above: #112213, fix in the open #112484 (not on master yet, so it may recur). Everything else, including CH Inc sync and the AI review, is green; no unresolved review threads.

const bool is_mutable;
const SourceId source_id;
Keys query_overridden_keys;
std::map<Key, String, std::less<>> values_before_query_override;

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.

Interesting, why std::less<> is needed to be specified here. But ok.

@alexey-milovidov alexey-milovidov left a comment

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.

To be honest, it was not a big concern. Still ok to have.

@alexey-milovidov alexey-milovidov self-assigned this Aug 12, 2026
@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Aug 12, 2026
Merged via the queue into master with commit 86363e8 Aug 12, 2026
180 checks passed
@alexey-milovidov
alexey-milovidov deleted the fix-mysql-empty-pem-override branch August 12, 2026 22:53
@robot-ch-test-poll robot-ch-test-poll added the pr-synced-to-cloud The PR is synced to the cloud repo label Aug 13, 2026
pull Bot pushed a commit to AnotherGenZ/ClickHouse that referenced this pull request Aug 13, 2026
…stores no credential

Port the narrowing from ClickHouse#113947 (MySQL) to
`StoragePostgreSQL::getSSLParams`: an empty `ssl*_pem` override is rejected only when it
would actually drop a credential the named collection carries - a path (a query cannot
override path keys, so the value is the collection's own) or contents, read in the
pre-override form via `NamedCollection::getValueBeforeQueryOverride`. On a collection with
no TLS keys at all the empty override stays the no-op it is for the direct arguments.

Co-Authored-By: Claude Fable 5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr-bugfix Pull request with bugfix, not backported by default 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