Skip to content

Reject MySQL hosts that the client library would reinterpret, and check remote_url_allow_hosts in the MySQL database engine - #129139

Merged
nikitamikhaylov merged 8 commits into
ClickHouse:masterfrom
Algunenano:mysql-database-remote-host-filter
Nov 6, 2026
Merged

nikitamikhaylov merged 8 commits into
ClickHouse:masterfrom
Algunenano:mysql-database-remote-host-filter

Conversation

@Algunenano

@Algunenano Algunenano commented Nov 4, 2026 •

Copy link
Copy Markdown
Member

CREATE DATABASE ... ENGINE = MySQL did not check hosts against remote_url_allow_hosts, unlike the mysql table function, the MySQL table engine and the PostgreSQL database engine. Now it does, for both inline arguments and named collections, skipping the check only for the server's own metadata replay.

The MySQL client library does not always connect to the host and port that were checked. It reads a host containing ; or = as a connection string (which can set a socket, a plugin directory or TLS files), :// as a connection plugin URL, and , as a list of hosts. It also stops at a NUL, sends localhost to its default Unix socket and replaces port 0 with its default port. All MySQL connections now reject these hosts, port 0 without a used socket, and sockets containing NUL. Connections without an explicit socket always use TCP to the given port, including localhost.

Closes: https://github.com/ClickHouse/clickhouse-private/issues/74309

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

The MySQL database engine now respects remote_url_allow_hosts. MySQL hosts that the client library would read as a connection string, a plugin URL or a list of hosts are rejected, and localhost without an explicit socket now connects over TCP to the given port instead of the default Unix socket.


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

Version info

  • Merged into: 26.11.1.1523-master (included in 26.11 and later)

@Algunenano Algunenano added the pr-must-backport Pull request should be backported intentionally. Use this label with great care! label Nov 4, 2026
@clickhouse-gh

clickhouse-gh Bot commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [b886e19]

Summary: ✅


AI Review

Summary

Reviewed head b886e197ec7751a4c8cdd440ae935865e8309feb. The PR applies remote_url_allow_hosts to the MySQL database engine, rejects connector syntax that changes the effective connection target, and uses TCP when no explicit socket is configured. Both previously reported bypasses are addressed in the current code; no actionable findings remain.

Missing context / blind spots
  • ⚠️ Targeted CI for this head is still pending, and no local ClickHouse binary is available. Passing results for 05493_mysql_host_connector_syntax and test_mysql_database_host_filter would close the runtime validation gap.
  • ⚠️ The linked private issue returned HTTP 404. Its original reproduction could not be compared with the public PR description and added regression cases.
Final Verdict

✅ Approve based on code review. Targeted CI results remain outstanding.

@clickhouse-gh clickhouse-gh Bot added the pr-bugfix Pull request with bugfix, not backported by default label Nov 4, 2026
Comment thread src/Databases/MySQL/DatabaseMySQL.cpp Resolved
@clickhouse-gh clickhouse-gh Bot added the comp-mysql MySQL-specific integration (table engine/function/protocol mapping). label Nov 4, 2026
@clickhouse-gh

clickhouse-gh Bot commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing b886e197e with master 3b0d42e9e (stripped binary size, per-symbol sizes and ThinLTO time; compile times per translation unit against the most recent warmup build that recompiled it).

✅ No significant changes.

Binary sizes

programs/clickhouse-stripped: smaller than the master baseline by the known offset between the two builds, so the difference is not shown. A delta that differs from the offset by more than 50% of it is shown, in either direction.

The official master build is compiled with -g and a pull request build is not, and XRay counts debug instructions towards its instrumentation threshold, so master instruments thousands of functions more and its binary is ~0.4% larger no matter what the pull request does.

Object file sizes

9 object files changed (+23.26 KiB total), 0 added.

Object file Master PR Δ
src/Common/mysqlxx/CMakeFiles/mysqlxx.dir/Pool.cpp.o 166.96 KiB 186.61 KiB +19.65 KiB (+11.77%)

719 more object files are built by the master warmup baseline only (it builds every object-file target, a pull request build only clickhouse-bundle) and not compared.

Compile time of recompiled translation units

13 translation units recompiled, 40 s compile time in total, 13 of them have a recent master baseline.

Median compile-time ratio to the baselines is ×1.06 (machine-speed difference or a change affecting every TU); per-TU deltas below are relative to that ratio.
The matched translation units cost +2.6 s (+7%) in total before that adjustment.

Job report

Comment thread src/Common/RemoteHostFilter.cpp Resolved
Algunenano and others added 6 commits November 5, 2026 16:02
`mysql_real_connect` reads a host with `;` or `=` as a connection string (socket, plugin dir, TLS files), `://` as a plugin URL, `,` as a host list, and stops at NUL. Reject these in `mysqlxx::Pool` for all MySQL paths, drop `checkCanonicalHostAndPort`, and fix clang-tidy.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Otherwise the client library sends `localhost` to its default Unix socket and ignores the port checked by `remote_url_allow_hosts`.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The client library replaces port 0 with its default port, so the connection would not go to the port checked by `remote_url_allow_hosts`.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The client library uses `socket` only for `localhost`, so port 0 with another host still goes to the default TCP port. Document that hosts are reached over TCP and that `remote_url_allow_hosts` does not check dictionary sockets.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The client library ends the socket path at the first NUL, so a socket starting with one would be ignored and the connection would go over TCP to the default port.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@Algunenano Algunenano changed the title Check remote_url_allow_hosts in the MySQL database engine Reject MySQL hosts that the client library would reinterpret, and check remote_url_allow_hosts in the MySQL database engine Nov 5, 2026
@nikitamikhaylov nikitamikhaylov self-assigned this Nov 6, 2026
@nikitamikhaylov
nikitamikhaylov added this pull request to the merge queue Nov 6, 2026
Merged via the queue into ClickHouse:master with commit 8cd49f2 Nov 6, 2026
185 checks passed
@robot-clickhouse robot-clickhouse added the pr-synced-to-cloud The PR is synced to the cloud repo label Nov 6, 2026
@robot-ch-test-poll robot-ch-test-poll added the pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR label Nov 6, 2026
robot-clickhouse-ci-1 added a commit that referenced this pull request Nov 6, 2026
Cherry pick #129139 to 26.3: Reject MySQL hosts that the client library would reinterpret, and check `remote_url_allow_hosts` in the `MySQL` database engine
robot-clickhouse added a commit that referenced this pull request Nov 6, 2026
…would reinterpret, and check `remote_url_allow_hosts` in the `MySQL` database engine
robot-clickhouse-ci-1 added a commit that referenced this pull request Nov 6, 2026
Cherry pick #129139 to 26.8: Reject MySQL hosts that the client library would reinterpret, and check `remote_url_allow_hosts` in the `MySQL` database engine
robot-clickhouse added a commit that referenced this pull request Nov 6, 2026
…would reinterpret, and check `remote_url_allow_hosts` in the `MySQL` database engine
robot-clickhouse-ci-1 added a commit that referenced this pull request Nov 6, 2026
Cherry pick #129139 to 26.9: Reject MySQL hosts that the client library would reinterpret, and check `remote_url_allow_hosts` in the `MySQL` database engine
robot-clickhouse added a commit that referenced this pull request Nov 6, 2026
…would reinterpret, and check `remote_url_allow_hosts` in the `MySQL` database engine
robot-clickhouse-ci-1 added a commit that referenced this pull request Nov 6, 2026
Cherry pick #129139 to 26.10: Reject MySQL hosts that the client library would reinterpret, and check `remote_url_allow_hosts` in the `MySQL` database engine
robot-clickhouse added a commit that referenced this pull request Nov 6, 2026
… would reinterpret, and check `remote_url_allow_hosts` in the `MySQL` database engine
@robot-clickhouse-ci-1 robot-clickhouse-ci-1 added the pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore label Nov 6, 2026
clickhouse-gh Bot added a commit that referenced this pull request Nov 6, 2026
Backport #129139 to 26.8: Reject MySQL hosts that the client library would reinterpret, and check `remote_url_allow_hosts` in the `MySQL` database engine
clickhouse-gh Bot added a commit that referenced this pull request Nov 6, 2026
Backport #129139 to 26.10: Reject MySQL hosts that the client library would reinterpret, and check `remote_url_allow_hosts` in the `MySQL` database engine
clickhouse-gh Bot added a commit that referenced this pull request Nov 6, 2026
Backport #129139 to 26.9: Reject MySQL hosts that the client library would reinterpret, and check `remote_url_allow_hosts` in the `MySQL` database engine
alexey-milovidov added a commit that referenced this pull request Nov 7, 2026
Backport #129139 to 26.3: Reject MySQL hosts that the client library would reinterpret, and check `remote_url_allow_hosts` in the `MySQL` database engine
groeneai added a commit to groeneai/ClickHouse that referenced this pull request Nov 12, 2026
…ct-socket

Resolves the conflict with ClickHouse#129139 in the embedded MySQL dictionary source docs.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
groeneai added a commit to groeneai/ClickHouse that referenced this pull request Nov 12, 2026
ClickHouse#129139 made every MySQL connection without an explicit `socket` use TCP,
including `localhost`, and made every MySQL connection reject hosts that the
client library reads as a connection string or a list of hosts. That covers
the `force_tcp` flag and the dictionary-only host check of this PR, so both are
removed and the mysqlxx and MySQLHelpers files are back to master.

What remains is rejecting `socket` in a dictionary created with a DDL query,
at the source and at each replica. 05229_mysql_dictionary_socket keeps the
`socket` cases and one TCP control. The dictionary cases of
05493_mysql_host_connector_syntax set `SOCKET` in a DDL dictionary, so they now
check port 0 without `socket`; a dictionary with `socket` and port 0 is only
reachable from a server configuration file.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
groeneai added a commit to groeneai/ClickHouse that referenced this pull request Nov 13, 2026
…entries of configuration-file ones

With `share_connection`, `PoolFactory::get` returns a cached pool keyed by
`getPoolEntryName`, which joins the configuration fields without framing.
The DDL checks (`socket`, `ssl_*` paths, `enable_local_infile`, the host
filter) only see the keys of the `CREATE DICTIONARY` query, so a DDL source
whose key matched a pool created from a configuration file got that pool,
including its configured socket. On bbfc810 the `force_tcp` suffix kept the
keys apart; it went away with ClickHouse#129139.

`getPoolEntryName` now takes `created_from_ddl` and appends a marker for
DDL-created sources, so their keys never equal a configuration-file key.
The dictionary source passes it through `PoolFactory::get`. Covered by a
new case in `gtest_pool_entry_name.cpp` (same configuration, different
origin, different key).

Also drop the `MySQL socket` alternative from the 05493 grep: the DDL
dictionary cases there no longer set `SOCKET`.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
leshikus pushed a commit that referenced this pull request Nov 13, 2026
…would reinterpret, and check `remote_url_allow_hosts` in the `MySQL` database engine
leshikus pushed a commit that referenced this pull request Nov 13, 2026
…would reinterpret, and check `remote_url_allow_hosts` in the `MySQL` database engine
leshikus pushed a commit that referenced this pull request Nov 13, 2026
…would reinterpret, and check `remote_url_allow_hosts` in the `MySQL` database engine
leshikus pushed a commit that referenced this pull request Nov 13, 2026
… would reinterpret, and check `remote_url_allow_hosts` in the `MySQL` database engine
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp-mysql MySQL-specific integration (table engine/function/protocol mapping). 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 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.

5 participants