Skip to content

Remove the obsolete mysql_ssl_rsa_setup from the MySQL 8 test image - #112967

Merged
nikitamikhaylov merged 1 commit into
ClickHouse:masterfrom
groeneai:fix-integration-mysql8-entrypoint-rsa-setup
Aug 3, 2026
Merged

nikitamikhaylov merged 1 commit into
ClickHouse:masterfrom
groeneai:fix-integration-mysql8-entrypoint-rsa-setup

Conversation

@groeneai

@groeneai groeneai commented Aug 2, 2026

Copy link
Copy Markdown
Collaborator

Related: #96252
Related: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=112338&sha=6d6f6157b52d0580f7b793af3a6beec106675102&name_0=PR&name_1=Integration%20tests%20%28amd_asan_ubsan%2C%20db%20disk%2C%20old%20analyzer%2C%201%2F6%29

Changelog category (leave one):

  • CI Fix or Improvement (changelog entry is not required)

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

...

Description

Integration modules using with_mysql8=True sporadically fail their whole module with
Exception: Cannot wait MySQL 8 container. Seen on 6 unrelated PRs over the last 90 days
(0 on master), across 4 job flavours including arm_binary, most recently 2026-07-30.

The container's entrypoint runs mysql_ssl_rsa_setup under set -e, after the datadir
bootstrap but before the step that applies the MYSQL_ROOT_HOST=% grant. If that call exits
non-zero the entrypoint aborts, restart: always relaunches the container, and the second run
finds an initialized datadir and skips the whole init block, so the grant never runs. The server
then comes up healthy knowing only root@localhost, and every connection from the docker gateway
is refused with MySQL error 1130. That error precedes authentication and is permanent, so
wait_mysql8_to_start cannot recover and burns its full 180 s budget. In the linked report the
waiter logged 342 such refusals while the server had been ready for 171 s.

This finishes what #96252 started. That PR pre-generated all 11 cert/key files and disabled
server-side RSA generation, but left the entrypoint-side generator in place. It is dead work
here: every SSL/RSA path the server uses points at the bind-mounted /etc/mysql/certs/, and the
files this tool writes into the datadir are read by nothing. Removing it makes the entrypoint's
own command -v guard skip the step, so initialization reaches the grant.

Verified by injecting a failing mysql_ssl_rsa_setup: with it present, RestartCount=1 and
only root@localhost; with the same binary removed, RestartCount=0 and root@% present and
the waiter succeeds. 6 with_mysql8 modules show an identical failure set before and after.

I also made wait_mysql8_to_start report the errors it collects, matching the other three MySQL
waiters. It was the only one discarding them, which is why this went undiagnosed for so long.

Integration modules using with_mysql8=True sporadically fail their entire
module with "Exception: Cannot wait MySQL 8 container". Seen on 6 unrelated
PRs over the last 90 days (0 on master) across 4 job flavours, including
arm_binary and amd_llvm_coverage.

The MySQL 8 container's entrypoint calls mysql_ssl_rsa_setup under
"set -eo pipefail", inside docker_init_database_dir: after the datadir
bootstrap, but before docker_setup_db, which is the function that applies the
MYSQL_ROOT_HOST=% grant. A non-zero exit from that call therefore aborts the
entrypoint before the grant is created. "restart: always" on the compose
service then relaunches the container, and the second run finds an initialized
datadir, so DATABASE_ALREADY_EXISTS is set and the whole initialization block,
grant included, is skipped for good.

The server consequently comes up healthy while knowing only root@localhost,
and every connection from the docker gateway is rejected with MySQL error
1130. That error is issued before authentication and is permanent, so
wait_mysql8_to_start cannot recover from it and burns its full 180 s budget
before raising. In one collected report the waiter logged 342 such rejections
while the server had already been ready for 171 s. Because the fixture is
module-scoped, all 21 tests of the module were reported as failures from that
single event.

This finishes what ClickHouse#96252 started. That PR pre-generated all 11 cert and key
files and turned off server-side RSA generation, but left the entrypoint-side
generator in the image. The generator is dead work here: every SSL and RSA
path the server actually uses points at the bind-mounted /etc/mysql/certs,
and the eight .pem files this tool writes into the datadir are read by
nothing. The server log confirms it skips generation of its own accord.
Removing the executable makes the entrypoint's own "command -v" guard skip the
step, so initialization proceeds to the grant. rm -f keeps the layer
idempotent should a future base image ship without the binary.

Verified by injecting a deliberately failing mysql_ssl_rsa_setup, so both arms
run the same failing binary and only the fix differs. With it present:
RestartCount=1, a grant table holding only root@localhost, and 344
occurrences of error 1130 (the collected report shows 342), plus the same 16
initial connection-refused errors. With it removed: RestartCount=0, root@'%'
present, and the waiter succeeds. Six with_mysql8 modules show an identical
failure set before and after, including test_storage_mysql, which also
exercises the untouched official mysql:8.0 cluster nodes.

What makes that step fail in the wild is still unidentified: it did not fail
once in 480 local invocations under load. Since the step is dead work in this
configuration, removing it eliminates the failure mode regardless of the
trigger.

wait_mysql8_to_start now also reports the per-attempt errors it collects,
matching the three sibling MySQL waiters. It was the only one discarding them,
which is why the raised exception carried no diagnostics and this signature
went undiagnosed across six PRs. No fatal-fast on 1130 is added: that would
convert a future transient into a hard failure.
@groeneai

groeneai commented Aug 2, 2026

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

Two independent reviews were run against this diff before publishing: a cold read by a
reviewer that had not seen the implementation notes, and a second-model gate review. The
second-model gate returned 0 findings, with coverage of the changed files, the full
waiter and its caller, the sibling waiters, the MySQL compose files and container
entrypoint, the image-build wiring, and every existing with_mysql8 fixture, including a
build and inspection of the resulting image.

The cold read raised no blockers and no majors. It re-derived the root cause from the base
image rather than from the implementation notes, and confirmed each step: the entrypoint
runs under set -eo pipefail; the guarded mysql_ssl_rsa_setup call sits inside
docker_init_database_dir; _main orders that before docker_temp_server_start and
docker_setup_db; the CREATE USER 'root'@'%' and GRANT live in docker_setup_db; and
DATABASE_ALREADY_EXISTS is derived from the presence of $DATADIR/mysql. One extra piece
of corroboration came out of it: the collected error.log contains no temporary-server
phase at all between the first run's shutdown and the second run's start, which brackets the
abort to the certificate step from both sides.

💡 Three notes, all addressed in the text of this pull request rather than in code.

The generality argument was strengthened. Saying the other MySQL services are "untouched
controls" understates it: the official mysql:8.0 entrypoint contains no reference to
mysql_ssl_rsa_setup at all, while the Ubuntu-flavoured one calls it twice, even though
both images ship the binary. The three mysql_cluster nodes therefore cannot take this path
despite carrying an identical restart: always and MYSQL_ROOT_HOST compose shape, which
is corroborated by 0 occurrences of the sibling waiters' failure messages over 90 days
against 150 for the MySQL 8 one.

⚠️ One claim was corrected before posting. The validation gate originally stated that
git grep mysql_ssl_rsa_setup returns 0 hits over the repository. That was true of the base
but not of this branch, which adds the rm -f line itself, so anyone running the command
here would have seen the claim fail. It now states what is both true and load-bearing:
nothing in the repository invokes the removed binary.

The claim that the waiter "discarded" its errors was also softened. It logged each attempt at
DEBUG; what was missing is that the raised exception and the INFO-level console output
carried nothing, which under this suite's logging configuration is why the error text never
reached anyone reading a failed job.

Every countable figure in the description was re-derived at review time rather than carried
over: 6 unrelated pull requests, 6 commits, 0 on master over 90 days, most recently
2026-07-30 on an arm_binary job, and 342 refusals matching the attached report exactly.

@groeneai

groeneai commented Aug 2, 2026

Copy link
Copy Markdown
Collaborator Author
Pre-PR validation gate (click to expand)
# Question Answer
a Deterministic repro? YES for the causal chain, by fault injection: build the image with a mysql_ssl_rsa_setup that exits 1, docker compose up, and every run gives RestartCount=1, a grant table holding only root@localhost, and error 1130 on every client attempt. NOT deterministic for the natural failure of that step: 480 direct invocations (12 parallel containers x 40, host load 22-38) gave 0 failures. Stated plainly rather than claimed.
b Root cause explained? YES. The entrypoint runs mysql_ssl_rsa_setup under set -eo pipefail after the datadir bootstrap but before docker_setup_db, which applies the MYSQL_ROOT_HOST=% grant. A non-zero exit aborts the entrypoint, restart: always relaunches it, run 2 sees an initialized datadir so DATABASE_ALREADY_EXISTS is set and the whole init block including the grant is skipped. The server is healthy but knows only root@localhost, so every gateway connection gets error 1130, which precedes authentication and is permanent, so the waiter exhausts its 180 s budget.
c Fix matches root cause? YES. It removes the failing step itself, which is dead work in this setup. Not a timeout bump (the server was ready in 9 s; 171 s of the budget was spent being refused), not a waiter retry (1130 never clears), not a grant applied by a second hand.
d Test intent preserved / new tests added? YES. No test logic weakened, nothing skipped, no no-parallel, no widened bound, no reduced dataset. This is a CI-image defect with no SQL surface; coverage is a 6-module before/after sweep. The waiter diagnostics change is covered by a both-directions stub test.
e Both directions demonstrated? YES, at two independent levels with the SAME failing binary, so only the fix differs. Raw compose: present -> RestartCount=1 + only root@localhost + 1130; removed -> RestartCount=0 + root@% + connects. Through the real ClickHouseCluster path: present -> Cannot wait MySQL 8 container; removed -> wait_mysql8_to_start succeeds and the node answers SELECT 1. The reproduction logged 344 x 1130 and 16 x 2003, against 342 and 16 in the linked CI report.
f Fix is general across code paths? YES. The sibling asymmetry that hid this was hunted and closed: wait_mysql8_to_start was the only MySQL waiter that failed to surface its per-attempt errors, and all four are now symmetric. The other MySQL services are provably immune rather than merely untouched: mysql57 uses official mysql:5.7, and the client plus the 3 cluster nodes use official mysql:8.0, whose entrypoint does not reference mysql_ssl_rsa_setup at all, even though the binary is present in that image too. Those cluster nodes carry an identical restart: always and MYSQL_ROOT_HOST compose shape and have never shown 1130. Only clickhouse/test-mysql80 derives from the Ubuntu-flavoured base whose entrypoint calls it, so this one-image change is the complete fix, and nothing in the repository invokes the removed binary.
g Fix generalizes across inputs (params/datatypes/wrappers)? YES on the axes that exist here. Both container uid paths verified: uid 1000 directly, and uid 0 which takes the gosu mysql re-exec branch and matches the CI project prefix. rm -f keeps the layer idempotent if a future base image ships without the binary, and the entrypoint's own command -v guard makes the step a clean no-op once removed. Type wrappers and settings matrices do not apply to a Dockerfile plus logging change.
h Backward compatible? (maintainer-approved exception only) YES, vacuously. ci/docker/** and tests/integration/** only. No setting default, no SettingsChangesHistory.cpp entry needed, no serialization or format change, no user-visible behavior.
i Invariants and contracts preserved? YES. The restored invariant is that the entrypoint completes initialization through the root-grant step in a single container run, so root@'%' exists; verified directly by reading mysql.user in both arms. The waiter change preserves its contract exactly: same signature, same success path, same exception type and message, same timeout budget, with only an errors list and one logging.error added on the failure path before the existing raise. Deliberately no fatal-fast short-circuit on 1130, which would turn a future transient into a hard failure.

Known limitation, disclosed rather than omitted: what makes mysql_ssl_rsa_setup fail in the
first place is still unidentified (it did not fail once in 480 local invocations). Since the step
is dead work in this configuration, removing it eliminates the failure mode independently of its
trigger. TLS was already disabled on this image before the change (have_ssl = DISABLED, from
SSL_CTX_set_default_verify_paths failed) and is byte-identical after it, so this PR neither
causes nor fixes that.

Session id: cron:clickhouse-impl-slot-42:20260801-225300

@groeneai

groeneai commented Aug 2, 2026

Copy link
Copy Markdown
Collaborator Author

cc @fm4v @leshikus, could you review this? The MySQL 8 test image's entrypoint calls mysql_ssl_rsa_setup under set -e after the datadir bootstrap but before the step that applies the MYSQL_ROOT_HOST=% grant, so a non-zero exit there aborts initialization, restart: always relaunches into an already-initialized datadir which skips the whole init block, and the server ends up knowing only root@localhost and refusing the test harness with error 1130 until the readiness waiter times out. That generator is dead work here since #96252 pre-generated all the cert and key files, so this removes it.

@alexey-milovidov alexey-milovidov added the can be tested Allows running workflows for external contributors label Aug 2, 2026
@clickhouse-gh

clickhouse-gh Bot commented Aug 2, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [c20a047]

Summary: ✅


AI Review

Summary

This PR removes mysql_ssl_rsa_setup from the custom MySQL 8 integration image and makes wait_mysql8_to_start surface the collected connection errors on timeout. The implementation matches the current Ubuntu MySQL entrypoint path, but the change still relies on manual validation for its main contract, so I would not approve it without a small deterministic regression around the image bootstrap.

Tests
  • ⚠️ [ci/docker/integration/mysql80/Dockerfile:10] The key claim here is that the MySQL 8 image still completes bootstrap far enough to create root@'%' after mysql_ssl_rsa_setup is removed. The existing with_mysql8 integration suites only fail when the upstream helper happens to break again, so they do not keep this fix covered. Please add a focused check that makes the old path fail deterministically and then asserts bootstrap still reaches the grant step / wait_mysql8_to_start succeeds with the helper removed.
Final Verdict
  • Status: ⚠️ Request changes
  • Add one deterministic regression around the MySQL 8 image startup contract, or explain why that coverage cannot live in-tree.

@clickhouse-gh clickhouse-gh Bot added the pr-ci label Aug 2, 2026
&& apt-get install -y iptables iproute2 curl \
&& rm -rf /var/lib/apt/lists/*
&& rm -rf /var/lib/apt/lists/* \
&& rm -f /usr/bin/mysql_ssl_rsa_setup

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 changes the MySQL 8 image's bootstrap contract, but the PR still has no deterministic regression that proves the image reaches docker_setup_db and creates root@'%' without mysql_ssl_rsa_setup. The existing with_mysql8 suites only surface this if the upstream helper happens to fail again, so today the fix is still validated by manual reproduction only. Please add the focused startup check described in the PR body (for example, fault-inject mysql_ssl_rsa_setup and assert bootstrap reaches the grant step / wait_mysql8_to_start succeeds).

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

I checked the ask against the harness before answering. Declining the fault-injected test, for three measured reasons, and pointing at the coverage that already exists.

The assertion you describe already runs as a hard gate on all 9 with_mysql8 modules. wait_mysql8_to_start connects as root (helpers/config_cluster.py:2) to the container's network address (helpers/cluster.py:2908, via get_instance_ip), not over localhost. Error 1130 is issued before authentication, so that connection can only succeed if root@'%' exists, and the fixture raises when it does not. On the rebuilt image the entrypoint's command -v guard (line 167) skips the cert step, so reaching docker_setup_db is the only way those modules can pass. ci/defs/defs.py:207-212 makes clickhouse/test-mysql80 a rebuild target of this Dockerfile, Dockers Build (amd, arm, multiplatform) passed here, and 6 integration shards are running against that rebuilt image on this commit now. So this is not "only if the upstream helper happens to fail again".

What those suites genuinely cannot catch is a future re-introduction of the binary. The proposed test would not close that gap either.

The test as described is not constructible here. Fault-injecting mysql_ssl_rsa_setup requires building or mutating an image. Integration tests only pull images by tag (helpers/cluster.py:3634, tag from integration_tests_configs.py:131); image builds live in the separate Dockers Build job. There is no docker build, docker commit or images.build anywhere under tests/integration/.

Even with a mutant image, the red arm is observable only once. The datadir is a bind mount (helpers/cluster.py:1464), so after the first run [ -d "$DATADIR/mysql" ] sets DATABASE_ALREADY_EXISTS (entrypoint 190-193) and _main skips the whole init block including the grant (352-358), permanently. The red arm's only observable outcome is the 180 s fixture timeout and its module-wide victim failures, which is the exact shape this PR removes.

Precedent: #96252, the previous fix for this same symptom on this same image, shipped compose and cert changes with no tests.

The diagnostics half is not manual-only either: it was tested both directions with a stubbed pymysql.connect raising the 1130 error (pre-fix 0 ERROR records, post-fix 1 record carrying the 1130 text).

I am not adding an "assert the binary is absent" test, because the waiter already gates the behaviour and such a test would pin the implementation rather than the outcome. I will add one if a reviewer prefers an explicit re-introduction guard.

@groeneai

groeneai commented Aug 2, 2026

Copy link
Copy Markdown
Collaborator Author

CI finish ledger - c20a047

CI is fully finished and there are no failures to own.

Check / test Reason Owner / fixing PR
(none) - -

174 check-runs: 37 success, 137 skipped, 0 queued/in_progress. Config Workflow, CI Tests and
Finish Workflow are all green. CIDB has ingested this commit (26256 rows) with 0 rows in
FAIL/ERROR. The six Integration tests (amd_asan_ubsan, db disk, old analyzer, N/6) shards that
were still running at the previous tick have now all finished green, and so have the three
Dockers Build (*) jobs that rebuild the MySQL 8 image this PR changes.

Moving to review.

Session id: cron:our-pr-ci-monitor:20260802-053000

@nikitamikhaylov nikitamikhaylov self-assigned this Aug 3, 2026
@nikitamikhaylov
nikitamikhaylov added this pull request to the merge queue Aug 3, 2026
Merged via the queue into ClickHouse:master with commit c216c78 Aug 3, 2026
179 checks passed
@robot-ch-test-poll2 robot-ch-test-poll2 added the pr-synced-to-cloud The PR is synced to the cloud repo label Aug 3, 2026
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-ci 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.

4 participants