fix: explicitly set AllowNativePasswords=true in newDSN#665
Merged
Conversation
Without this, MySQL servers using mysql_native_password auth reject connections because go-sql-driver/mysql's FormatDSN() omits the default-true value, and the pre-built binary ends up with it unset. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes Spirit’s inability to connect to MySQL instances using the mysql_native_password auth plugin by making newDSN() explicitly enable native password support, ensuring the setting survives DSN formatting/parsing behavior in go-sql-driver/mysql.
Changes:
- Explicitly set
AllowNativePasswords=trueon the MySQL driver config innewDSN(). - Add a unit test covering both TLS-enabled (default/PREFERRED) and TLS-disabled (fallback/DISABLED) DSN generation to ensure native passwords remain allowed.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
pkg/dbconn/conn.go |
Ensures newDSN() always enables AllowNativePasswords before formatting the DSN. |
pkg/dbconn/conn_test.go |
Adds coverage to validate AllowNativePasswords remains enabled across TLS and fallback DSNs. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
morgo
approved these changes
Mar 18, 2026
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.
Fixes #666
Problem
Spirit rejects connections to MySQL servers that use
mysql_native_passwordauthentication:Root Cause
In
newDSN()(pkg/dbconn/conn.go), Spirit explicitly sets several driver config options (RejectReadOnly,InterpolateParams,AllowCleartextPasswords) but does not explicitly setAllowNativePasswords. WhileNewConfig()defaults it totrue,FormatDSN()omits default-true values from the DSN string, making the setting fragile across DSN serialization/deserialization cycles.Fix
Explicitly set
cfg.AllowNativePasswords = trueinnewDSN(), consistent with how other driver options are already configured.Test
Added
TestNewDSNAllowNativePasswordswhich validatesAllowNativePasswordsis true for both TLS-enabled (default PREFERRED mode) and TLS-disabled (fallback path) DSNs, and asserts the DSN never containsallowNativePasswords=false.Also verified with integration test against a MySQL server using
mysql_native_password:could not use requested auth plugin 'mysql_native_password'