Repository navigation
mysql: track the auth plugin and seed from an authentication switch request - #440
Merged
oshai merged 1 commit intoNov 6, 2026
Conversation
…equest MySQLConnection stored the authentication method and seed from the initial handshake only. When the server's default plugin differs from the account's plugin (e.g. the handshake advertises mysql_native_password but the account uses caching_sha2_password), the server answers with an authentication switch request. switchAuthentication() answered it but did not record the new plugin and seed, so a following AuthMoreData packet asking for full authentication was checked against the stale plugin and failed with: AuthMoreDataMessage is only supported for 'caching_sha2_password' method It also scrambled the password with the stale seed on the RSA path. Record the plugin and seed from the switch request before answering it. Tests: AuthenticationSpec gets a case against a real server whose default plugin is mysql_native_password; AuthenticationSwitchSpec covers the packet flows against an in-process fake server without Docker. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Contributor
Author
|
Note on the red checks, neither comes from this change:
The new Happy to send a separate PR bumping Testcontainers (or pinning the runner) if you'd like. |
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.
mysql: track the auth plugin and seed from an authentication switch request
Fixes #441
Problem
MySQLConnectionstoresauthenticationMethodandauthenticationSeedfrom the initial handshake only (onHandshake).switchAuthentication()answers the server's authentication switch request but never records the plugin and seed it carries.That breaks any server whose default plugin differs from the account's plugin, for example:
mysql_native_password(server default, e.g.default_authentication_plugin=mysql_native_password, or a managed MySQL 8.0 service), butcaching_sha2_password.The flow is: handshake (native) -> client response -> auth switch request (
caching_sha2_password, new seed) -> client scramble ->AuthMoreData(0x04)(cold server cache, full authentication required).onAuthMoreDatathen checks the stale handshake plugin and throws:Every new connection fails while the server's
caching_sha2_passwordcache is cold (after a restart,FLUSH PRIVILEGES,ALTER USER), and works again once another client has populated the cache (AuthMoreData(0x03)is accepted without looking at the plugin). Even with the plugin check fixed, the RSA path would scramble the password with the stale handshake seed instead of the seed from the switch request, so both values need updating.Not a TLS/
sslModeissue: it fails identically withMode.DisableandMode.Prefer.Fix
Record the plugin and seed from the switch request before answering it:
No behavior change when the handshake and the account use the same plugin (no switch happens).
Tests
AuthenticationSpec.cachingSha2PasswordAuthenticationWhenServerAdvertisesNativePasswordInHandshake: real MySQL 8.0.32 started with--default-authentication-plugin=mysql_native_password, accounts createdWITH caching_sha2_password. Mirrors the existingcachingSha2PasswordAuthenticationtest: cold cache without SSL fails with the unsafe-connection error, full authentication with SSL, fast authentication, full authentication with an RSA public key.AuthenticationSwitchSpec(new, no Docker): an in-process fake MySQL server scripts the exact packets, which also covers things a real server can't be made to do on demand:mysql_native_passwordcompletes;AuthMoreDataafter a switch away fromcaching_sha2_passwordis rejected (the plugin check now reflects the plugin actually in use).Verification
AuthMoreDataMessage is only supported for 'caching_sha2_password' methodAuthenticationSwitchSpec(6 tests), with fixAuthenticationSwitchSpec, fix revertedAuthenticationSwitchSpec, plugin line only (seed line removed)AuthenticationSpec(all 5, incl. sha256 and old-password flows), with fix:mysql-async:test+:r2dbc-mysql:test, with fixktlintCheckNote: on my machine (Apple silicon, Docker Desktop)
MySQLConnectionSpec."connect to a MySQL instance with unix domain socket"fails with and without the change (connection refused), andsha256Authenticationfailed once in the full run on container startup (mysql:5.7.32) and passed when rerun. Neither relates to this change.Run locally with JDK 17 and
-PTEST_CONTAINERS_VERSION=1.21.4: the pinned Testcontainers 1.17.6 can't talk to a current Docker daemon (API too old). That override is not part of this PR.🤖 Generated with Claude Code