Skip to content

MySQL dictionary source: accept enable_local_infile only in the configuration file - #120972

Merged
nihalzp merged 2 commits into
ClickHouse:masterfrom
groeneai:groeneai/mysql-dict-reject-enable-local-infile
Sep 22, 2026
Merged

nihalzp merged 2 commits into
ClickHouse:masterfrom
groeneai:groeneai/mysql-dict-reject-enable-local-infile

Conversation

@groeneai

@groeneai groeneai commented Sep 19, 2026 •

Copy link
Copy Markdown
Collaborator

Related: #112070

Changelog category (leave one):

  • Backward Incompatible Change

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

A MySQL dictionary source created with a CREATE DICTIONARY query can no longer enable enable_local_infile, at the source or at one of its REPLICA entries; loading such a dictionary fails with BAD_ARGUMENTS, which with the default dictionaries_lazy_load is on first use rather than at CREATE. A REPLICA that does not set the key inherits the source's value, as the connection pool does. To keep the option, define the dictionary in a server configuration file; enable_local_infile 0, and a SOURCE(MYSQL(NAME ...)) reference to a named collection where the key was never read, are unaffected.

Description

Completes #112070's guard for a sibling key in the same list.

#112070 established that a dictionary created with a DDL query may not name files for the server to open, since the server reads them with its own privileges, and implemented that as checkNoSSLPaths over ssl_ca / ssl_cert / ssl_key. enable_local_infile is in the same dictionary_allowed_keys and meets that premise another way: it sets MYSQL_OPT_LOCAL_INFILE, letting the endpoint a dictionary points at ask the client for the contents of a file of its choosing. It is off by default for that reason (mysqlxx/Connection.h, since 33205bb), and was not considered there.

Change. A new checkNoLocalInfile, at the two prefixes the pool reads for a DDL-created dictionary: each <replica> and the single-endpoint one. It resolves the value in Pool::Pool's order, a replica winning over the parent as its fallback, so what is rejected is the value the connection would use: a truthy parent whose every replica sets 0 stays accepted, since only per-replica pools exist when replicas do. Configuration-file dictionaries keep working, as in #112070.

socket, the other key naming a path a query chooses, is deliberately not mirrored: a connect(2), not a file read. The named-collection route needs none, though only as a precondition: it passes the literal default and MySQLSettings has no local_infile, so the key is accepted and never read. Add such a setting, as #103229 did for enable_compression, and it needs the guard too. Happy to drop the option outright instead, if you prefer.

Validation. New 05229_mysql_dictionary_enable_local_infile covers the four shapes that enable the option and the two that do not, 50/50 green with randomized settings. A new test_dictionaries_mysql arm proves a configuration-file dictionary still loads and serves data with the option on. Every arm is pinned by a distinct mutation; test_storage_mysql's ssl arms stay green.


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

Version info

  • Merged into: 26.10.1.401-master (included in 26.10 and later)
  • Backported to: 26.9.2.6, 26.8.11.12, 26.7.14.47, 26.3.33.149

…guration file

ClickHouse#112070 established that the source configuration of a dictionary created with a
DDL query comes from the query itself, so it may not name files for the server to
open: the server reads them with its own privileges. It implemented that as
checkNoSSLPaths, keyed on the three ssl_ca / ssl_cert / ssl_key key names rather
than on the invariant itself.

enable_local_infile is in the same dictionary_allowed_keys and satisfies the same
premise by a second, indirect route: it sets MYSQL_OPT_LOCAL_INFILE on the
outgoing connection, which lets the MySQL endpoint the dictionary points at ask
the client for the contents of a file of its choosing. The option is off by
default for exactly this reason, and has been since 33205bb ("Disable LOAD
DATA LOCAL INFILE because it is insecure", still visible at
mysqlxx/Connection.h:16); 26a951e re-exposed it as an argument and
bfc705c put it in the dictionary source's allowed keys, which is how a DDL
query reaches it. It was never considered in ClickHouse#112070, so this completes that
guard for the sibling key rather than duplicating it.

The guard is applied at the two configuration prefixes the connection pool
actually reads for a DDL-created dictionary: each <replica> prefix and the
single-endpoint prefix, both inside the existing created_from_ddl block of the
non-named-collection branch.

It resolves the value in Pool::Pool's own lookup order, a replica value winning
over the parent as its fallback (Pool.cpp:94-95), so what is rejected is the
value the connection would really use. That matters in both directions: a
<replica> inheriting a truthy parent is rejected, while a truthy parent whose
every replica sets 0 is not, because PoolWithFailover builds only per-replica
pools when replicas exist and so the parent alone decides nothing. An
independent parent check would reject that safe configuration; open ClickHouse#109736 is a
bug fix for the same class of mistake two lines away.

The guard is deliberately not placed beside checkNoSSLPaths, which sits before
the branch because for the SSL keys that breadth is necessary. It is not needed
there for this key: the named-collection route reaches
createMySQLPoolWithFailover, which passes the literal
MYSQLXX_DEFAULT_ENABLE_LOCAL_INFILE (PoolWithFailover.cpp:164), and MySQLSettings
carries no local_infile, so a collection-defined or NAME-overriding key is
accepted and then never read. Guarding it there would break a configuration that
cannot enable the option. That inertness is a precondition rather than a
property, so it is stated in the PR body: adding such a setting, as ClickHouse#103229 did
for enable_compression, would make that branch a live carrier.

Resolution is by value rather than by presence, unlike checkNoSSLPaths: for a
path key any value is dangerous, but enable_local_infile 0 is bit-for-bit the
default and harmless, and this change is already backward incompatible without
breaking configurations that never reach MYSQL_OPT_LOCAL_INFILE = 1.

socket is the one other key in that list naming a path a DDL query can choose. It
is deliberately not mirrored: it is a connect(2) to a path rather than a read of
a file's contents, and pointing a dictionary at a local mysqld.sock is a
legitimate, widely used configuration.

Tests: a stateless test covering the four shapes that enable the option (source,
an explicit <replica>, a <replica> that inherits it, a later <replica> when the
first disables it) and the two that do not (0 at the source, 0 at every <replica>
of a truthy source), which needs no MySQL server
because the rejection precedes any connection, and an integration arm in
test_dictionaries_mysql proving a configuration-file dictionary still loads and
serves data with the option on while the same option from a DDL query against
that endpoint is rejected.

Co-Authored-By: Claude Opus 5 <[email protected]>
@groeneai groeneai added can be tested Allows running workflows for external contributors groeneai-origin-oranjeai PR origin: delegated from the OranjeAI sibling fleet labels Sep 19, 2026
@groeneai

Copy link
Copy Markdown
Collaborator Author
Internal second-model review: adjudication log (click to expand)

Three rounds of pre-publication review before this PR was opened: an independent model
(engine: codex; 5 findings across the rounds) plus my own cold review of the resulting tree in
each round (8 findings), adjudicated against the code. 11 distinct items after merging the two
that both reviews raised. The final round is clean: 0 findings from the independent model, 0
blockers and 0 majors from mine. The guard itself was asked to change in none of the 11.

# Sev Finding Verdict Evidence / action
1 ⚠️ The structured source documentation documented neither enable_local_infile nor its new restriction, while documenting the sibling enable_compression and the sibling TLS-path restriction AGREE, fixed One setting-fields row and one <Note> added to the Documentation block of registerDictionarySourceMysql; docs/ is untouched because that page is generated from this block
2 ⚠️ The changelog promised that the CREATE DICTIONARY query itself fails, but with the default dictionaries_lazy_load the query succeeds and the rejection surfaces when the dictionary is loaded AGREE, changelog corrected The sibling checkNoSSLPaths behaves identically in the same function, as 04648_mysql_tls_credentials states; moving validation into the loader buys no security, since the option cannot reach a connection without the source being instantiated
3 ⚠️ The changelog stated the rejection unqualified, but SOURCE(MYSQL(NAME ...)) still accepts the key AGREE on the wording, DISAGREE on rejecting it there That route reaches createMySQLPoolWithFailover, which passes the literal MYSQLXX_DEFAULT_ENABLE_LOCAL_INFILE, and MySQLSettings has no local_infile, so the key is accepted and never read: rejecting it would break a configuration that cannot enable the option. The changelog now names it as unaffected and says why
4 ⚠️ The replica loop was not pinned to visit every <replica>: with a single replica in each rejecting arm, stopping after the first match left the whole suite green AGREE, fixed Re-measured independently rather than taken on the model's word. The pool resolves the option per replica and fails over between them, so a later replica would still reach it. A sixth arm now declares the disabled replica first and the enabled one second, and the matching mutation reddens that arm alone while the other five stay green
5 ⚠️ The configuration-file test would pass even if the option were ignored, so it should observe a real local-infile request from a controlled MySQL endpoint DISAGREE That arm is not inert: dropping the created_from_ddl scoping makes it fail with BAD_ARGUMENTS on the configuration-file route, which is the regression it exists to catch. Propagation of the option on that route is pre-existing behaviour this diff cannot alter, and the suggested fixture would add an endpoint that requests arbitrary files to the public suite
6 💡 Carrier enumeration: the shared-pool cache is a precondition of this guard, since a cached pool built with the option on could otherwise be handed to a dictionary whose own configuration is silent DISAGREE (no action) getPoolEntryName already folds enable_local_infile into the cache key for both the replica and the single-endpoint shape, with the same parent fallback, and gtest_pool_entry_name asserts that discriminator. Re-derived from the tree in the final round, same conclusion
7 💡 A test comment attributed the reload to a failed initial load, but dictionaries are lazily loaded by default AGREE, fixed Comment corrected; the identical wording in the neighbouring pre-existing test is outside this diff and was left alone
8 💡 The commit message and PR body claimed a complete truth table the test did not have AGREE, fixed Both now name the four shapes that enable the option and the two that do not, which is what the six arms cover
9 💡 The configuration-file arm's reload retry swallows the reload error, so a wrongly rejected route fails one statement later on the raw dictGet error and the crafted last_exception message never prints AGREE, noted, not changed Liveness is unaffected: the test still fails. The neighbouring pre-existing test uses the identical retry shape, so changing only the new one would diverge from the file's style for no gain in the oracle
10 💡 The error text says the option "is only accepted in a dictionary defined in a server configuration file", which is about where it takes effect: a named-collection reference also accepts it silently AGREE, noted, not changed True and actionable for the user who hits it, since only the inline form can reach the message, and it matches the sibling guard's style. The documentation <Note> and the changelog entry both carry the nuance
11 💡 The error text names the key but not the configuration prefix that carried the truthy value, so a user whose <replica> inherits it from the source is not told where it came from AGREE, noted, not changed The sibling guard has the identical property, and the documentation row added for finding 1 states the inheritance rule explicitly

Severity: ❌ blocker / ⚠️ major / 💡 nit. DISAGREE verdicts carry recorded evidence and are
terminal per finding. No finding was raised in two rounds, and none was deferred.

Session id: cron:clickhouse-review-slot-9:20260919-042400

@clickhouse-gh clickhouse-gh Bot closed this Sep 19, 2026
@clickhouse-gh clickhouse-gh Bot reopened this Sep 19, 2026
@groeneai

Copy link
Copy Markdown
Collaborator Author
Pre-PR validation gate (click to expand)
# Question Answer
a Deterministic repro? Yes. One clickhouse local invocation per arm; the guard throws while the source is instantiated, before any connection, so there is no timing component. 6/6 arms reproduce on every run.
b Root cause explained? The DDL guard was keyed on the three ssl_* key names instead of on its own stated invariant ("a DDL source may not make the server open a path"), so enable_local_infile, in the same dictionary_allowed_keys, passed it; the value then flows unconditionally to mysql_options(MYSQL_OPT_LOCAL_INFILE).
c Fix matches root cause? Yes. The guard sits at the only layer holding the provenance bit (created_from_ddl, known solely in registerDictionarySourceMysql), at the two prefixes the pool actually reads, resolved in Pool::Pool's own order. Nothing widened, tagged, shrunk or defensively guarded downstream.
d Test intent preserved / new tests added? No existing test weakened or retagged. Two new regression tests: 6 stateless arms (05229_mysql_dictionary_enable_local_infile) plus one integration arm in test_dictionaries_mysql.
e Both directions demonstrated? Yes. On the pristine binary the four enabling arms are accepted and reach a connection attempt (ALL_CONNECTION_TRIES_FAILED); with the guard they fail BAD_ARGUMENTS before connecting. The two safe arms are unchanged by both binaries.
f Fix is general across code paths? Yes. Both DDL-reachable prefixes are fixed. The named-collection branch, the mysql() table function and the MySQL table and database engines build pools via createMySQLPoolWithFailover, which passes the literal default, and MySQLSettings has no local_infile, so they cannot reach the option. PoolFactory::get(config, prefix) has exactly one caller in the tree, exercised by the stateless arms. PostgreSQLDictionarySource has no infile-class key. Fixed at the source, not at the point of use.
g Fix generalizes across inputs (params/datatypes/wrappers)? Yes for the input space that exists: the key is a boolean, and the matrix covers both values against every prefix shape that can carry it (the source, a <replica> explicitly, a <replica> inheriting it, and a later <replica> when the first one disables it), so a loop that stopped after the first replica reddens. No type wrappers apply; this is a configuration key, not a column expression.
h Backward compatible? (maintainer-approved exception only) Deliberately not, which is the point of the change; category Backward Incompatible Change, following #112070's precedent for the sibling keys. The break is confined to configurations whose effective value reaches MYSQL_OPT_LOCAL_INFILE = 1. Still accepted and pinned by tests: enable_local_infile 0, a truthy parent every replica turns off, and the server configuration file. No setting default changed, so no SettingsChangesHistory.cpp entry is owed.
i Invariants and contracts preserved? Yes. The guard is a configuration read plus a throw: no lock, no resource, and it runs before the pool exists, so there is no error or early-return path to leak; the throw propagates exactly as checkNoSSLPaths's does two lines above. It strengthens the existing precondition of the created_from_ddl block without changing any postcondition, and resolves the value in the same order as Pool::Pool, so guard and pool cannot disagree about what the connection will use. No durability or concurrency surface is touched.

Session id: cron:clickhouse-impl-slot-4:20260919-033400

@groeneai
groeneai requested review from kssenii and nihalzp September 19, 2026 04:57
@clickhouse-gh

clickhouse-gh Bot commented Sep 19, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [32d8edc]

Summary: ❌

job_name test_name status info comment
Build profile diff ERROR

AI Review

Summary

This PR closes the remaining DDL carrier for MySQL dictionary enable_local_infile by rejecting the effective value at the same prefixes and fallback order that mysqlxx::Pool uses, and it adds focused regression coverage for source-level, replica-level, inherited, and explicitly-disabled configurations. After reviewing the current diff, the surrounding pool construction code, and the prior PR discussion, I did not find a correctness, safety, or coverage gap that still warrants a new review finding on the current head.

Final Verdict

✅ Approve.

LLVM Coverage Report

Measured on commit 32d8edc.

Metric Baseline Current Δ
Lines 88.40% 88.40% +0.00%
Functions 91.80% 91.80% +0.00%
Branches 80.60% 80.60% +0.00%

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

Full report · Diff report

@clickhouse-gh clickhouse-gh Bot added pr-backward-incompatible Pull request with backwards incompatible changes comp-mysql MySQL-specific integration (table engine/function/protocol mapping). labels Sep 19, 2026
@clickhouse-gh

clickhouse-gh Bot commented Sep 19, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing commit 32d8edc4acd9a405feb80782320ea3e4b25aaf4d with master failed: RuntimeError: CI logs cluster query failed: SELECT file, countIf(side = 'pr') AS pr_cou….

See the job log for details.

@groeneai

Copy link
Copy Markdown
Collaborator Author

CI finish ledger - c1a3809

Every failure below has an owner: a fixing PR (mine or external), or a full-effort fix task
whose fixing-PR link will be posted here when it opens. Only CH Inc sync is exempt.

Check / test Reason Owner / fixing PR
Performance Comparison (arm_release, master_head, 5/6) / iceberg_suite_tpch perf-harness abort, not caused by this PR: TPC-H Q5 exceeds the harness 15 s per-query cap after a join-order cost change, perf.py re-raises the driver error and the rest of the test file never runs, so the shard reports 10 errors, 3 too long. The same shard is red on master itself (14 distinct master heads in 7 days) and on 40+ other PRs since 2026-09-18; this shard went from about 1 failed run per day to 163 on 2026-09-18, right after the join-order change merged. #120762 (mine, open)
Mergeable Check, PR aggregator rows: both only mirror the shard red above, and no other check failed on this head #120762 (mine, open)

Session id: cron:our-pr-ci-monitor:20260919-093158

@nihalzp nihalzp self-assigned this Sep 22, 2026
@nihalzp
nihalzp added this pull request to the merge queue Sep 22, 2026
@nihalzp nihalzp added pr-must-backport Pull request should be backported intentionally. Use this label with great care! v26.8-must-backport and removed pr-must-backport Pull request should be backported intentionally. Use this label with great care! labels Sep 22, 2026
Merged via the queue into ClickHouse:master with commit 3fc318b Sep 22, 2026
176 of 177 checks passed
@robot-clickhouse-ci-1 robot-clickhouse-ci-1 added the pr-synced-to-cloud The PR is synced to the cloud repo label Sep 22, 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 Sep 22, 2026
@robot-clickhouse-ci-1 robot-clickhouse-ci-1 added the pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR label Sep 22, 2026
clickhouse-gh Bot added a commit that referenced this pull request Sep 22, 2026
Backport #120972 to 26.9: MySQL dictionary source: accept `enable_local_infile` only in the configuration file
PedroTadim added a commit that referenced this pull request Sep 22, 2026
Backport #120972 to 26.8: MySQL dictionary source: accept `enable_local_infile` only in the configuration file
@nihalzp nihalzp added pr-must-backport Pull request should be backported intentionally. Use this label with great care! and removed pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR v26.8-must-backport labels Sep 22, 2026
@robot-ch-test-poll2 robot-ch-test-poll2 added the pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR label Sep 22, 2026
kewin-robetti pushed a commit to viasoftkorp/ClickHouse that referenced this pull request Sep 25, 2026
…enable_local_infile` only in the configuration file
kewin-robetti pushed a commit to viasoftkorp/ClickHouse that referenced this pull request Sep 25, 2026
…enable_local_infile` only in the configuration file
PedroTadim pushed a commit that referenced this pull request Sep 25, 2026
…guration file

`enable_local_infile` sets `MYSQL_OPT_LOCAL_INFILE`, which lets the MySQL endpoint the
dictionary points at ask the client for the contents of a file of its choosing, read with the
server's own privileges. The source configuration of a dictionary created with a DDL query
comes from the query itself, so it may not reach that option; it stays available to a
dictionary defined in a server configuration file.

(cherry picked from commit c1a3809)

Adapted for 26.3. #112070 is not on this branch, so there is no `checkNoSSLPaths` for the
guard to sit beside and no `BAD_ARGUMENTS` in the file's `ErrorCodes` block.
`checkNoLocalInfile` is therefore added standalone, with that declaration, and hooked into
the two `created_from_ddl` call sites this branch already has: the per-`<replica>` loop,
which passes the parent prefix so an inherited value is resolved the way `Pool::Pool`
resolves it, and the single-endpoint branch. The documentation hunk of the original is
dropped, because the settings table it edits does not exist on this branch.

Original pull-request: #120972

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
PedroTadim pushed a commit that referenced this pull request Sep 25, 2026
…guration file

`enable_local_infile` sets `MYSQL_OPT_LOCAL_INFILE`, which lets the MySQL endpoint the
dictionary points at ask the client for the contents of a file of its choosing, read with the
server's own privileges. The source configuration of a dictionary created with a DDL query
comes from the query itself, so it may not reach that option; it stays available to a
dictionary defined in a server configuration file.

(cherry picked from commit c1a3809)

Adapted for 26.7. #112070 is not on this branch, so there is no `checkNoSSLPaths` for the
guard to sit beside and no `BAD_ARGUMENTS` in the file's `ErrorCodes` block.
`checkNoLocalInfile` is therefore added standalone, with that declaration, and hooked into
the two `created_from_ddl` call sites this branch already has: the per-`<replica>` loop,
which passes the parent prefix so an inherited value is resolved the way `Pool::Pool`
resolves it, and the single-endpoint branch. The documentation hunk of the original is
dropped, because the settings table it edits does not exist on this branch.

Original pull-request: #120972

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
PedroTadim added a commit that referenced this pull request Sep 25, 2026
Cherry pick #120972 to 26.3: MySQL dictionary source: accept `enable_local_infile` only in the configuration file
PedroTadim added a commit that referenced this pull request Sep 25, 2026
Cherry pick #120972 to 26.7: MySQL dictionary source: accept `enable_local_infile` only in the configuration file
robot-clickhouse added a commit that referenced this pull request Sep 25, 2026
…al_infile` only in the configuration file
robot-clickhouse added a commit that referenced this pull request Sep 25, 2026
…al_infile` only in the configuration file
@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 Sep 25, 2026
PedroTadim added a commit that referenced this pull request Sep 25, 2026
Backport #120972 to 26.3: MySQL dictionary source: accept `enable_local_infile` only in the configuration file
clickhouse-gh Bot added a commit that referenced this pull request Sep 25, 2026
Backport #120972 to 26.7: MySQL dictionary source: accept `enable_local_infile` only in the configuration file
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 comp-mysql MySQL-specific integration (table engine/function/protocol mapping). groeneai-origin-oranjeai PR origin: delegated from the OranjeAI sibling fleet pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore pr-backward-incompatible Pull request with backwards incompatible changes pr-must-backport Pull request should be backported intentionally. Use this label with great care! 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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants