Repository navigation
Cherry pick #117407 to 26.3: Fix TOTP bypass in MySQL protocol authentication - #127116
Merged
robot-clickhouse-ci-2 merged 10 commits intoOct 21, 2026
Merged
Conversation
The `mysql_native_password` auth response is a hash of the password alone, so it cannot carry a one-time password. `checkMySQLAuthentication` verified only the password scramble and ignored the configured TOTP secret, so a user with `plaintext_password` or `double_sha1_password` plus TOTP could log in over the MySQL protocol with the password alone, skipping the second factor. Now `checkMySQLAuthentication` fails closed when a one-time password is configured, and `MySQLHandler` switches such users to the `sha256_password` plugin, which transmits the actual password string: the client appends the one-time password to the password, like 'password+123456', and the `BasicCredentials` path enforces the second factor. Co-Authored-By: Claude Opus 4.8 <[email protected]>
The flaky check runs the test file on several pytest-xdist workers in parallel, and `create_config` writes the shared `config/users.xml`. With a random module-level `TOTP_SECRET` the last writer wins, and the other workers' servers reject codes generated for their own secrets with `WRONG_PASSWORD`, failing every test that uses the random secret: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=117407&sha=a9ca343fa63aa8299c12e5cb9cd68c96372ff03e&name_0=PR https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=117408&sha=c88676cc0bc8587b70dfbb9fba92482587b74245&name_0=PR #117407 #117408 Also fix operator precedence in `get_one_time_password`: the intent is `int((timepoint or time.time()) / interval)`, not dividing only `time.time()` by the interval. Co-Authored-By: Claude Fable 5 <[email protected]>
…ully verify The `mysql_native_password` auth response can be re-checked only against `plaintext_password` and `double_sha1_password` methods. Besides skipping a second factor, serving a user with `mysql_native_password` when they also have a `scram_sha256_password` or `bcrypt_password` method lets that method drop out of the fail-close combination in `IAccessStorage::authenticateImpl`, so a shared password regains the broader `GRANTS` or lifetime of the `double_sha1_password` method over MySQL. Such users, like `sha256_password` users before, are now switched to the `sha256_password` plugin, which transmits the actual password string. As a side effect, users with only a `scram_sha256_password` or `bcrypt_password` method can log in over MySQL. The decision is made in `MySQLHandler` from the user's authentication methods instead of a `Session::userHasSecondFactor` helper. Addresses the review comment on #117407
# Conflicts: # tests/integration/test_totp_auth/config/users.xml # tests/integration/test_totp_auth/test_totp.py
…authenticated user snapshot `MySQLHandler` chose the plugin from a snapshot of the user read before the client answers the `AuthSwitchRequest`, while `IAccessStorage::authenticateImpl` reads a fresh one. A user altered in between (e.g. to add a `bcrypt_password` method with an expired `VALID UNTIL`) could be authenticated with a Native41 response that silently skipped the new method. Move the predicate to `Authentication::mysqlNative41CannotVerify` and re-check it in `IAccessStorage::authenticateImpl` on the same snapshot used for the authentication, rejecting `MySQLNative41Credentials` when any method cannot be enforced. Add a deterministic pause/alter/resume regression test with a raw MySQL protocol client. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Fix TOTP bypass in MySQL protocol authentication
Resolve conflicts in `test_totp_auth`: keep the MySQL protocol tests and users from #117407, drop the PostgreSQL parts that come from a change not present in 26.3.
On master it is included already; on 26.3 it is not. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Original pull-request #117407
Do not merge this PR manually
This pull-request is a first step of an automated backporting.
It contains changes similar to calling
git cherry-picklocally.If you intend to continue backporting the changes, then resolve all conflicts if any.
Otherwise, if you do not want to backport them, then just close this pull-request.
The check results does not matter at this step - you can safely ignore them.
Before you resolve anything
Conflicts are often caused by a prerequisite change that has not been backported yet, rather than by a real divergence. The bot re-tries this cherry-pick against the release branch on every run, so if that is the case here it will merge itself as soon as the prerequisite lands, and you will see a comment saying so. Manual resolution is only needed while the conflict persists.
Troubleshooting
If the conflicts were resolved in a wrong way
If this cherry-pick PR is completely screwed by a wrong conflicts resolution, and you want to recreate it:
pr-cherrypicklabel from the PRYou also need to check the Original pull-request for
pr-backports-createdlabel, and delete if it's presented thereThe PR source
The PR is created in the CI job