Skip to content

fix: explicitly set AllowNativePasswords=true in newDSN#665

Merged
morgo merged 1 commit into
block:mainfrom
deanbaker:fix/allow-native-passwords
Mar 18, 2026
Merged

fix: explicitly set AllowNativePasswords=true in newDSN#665
morgo merged 1 commit into
block:mainfrom
deanbaker:fix/allow-native-passwords

Conversation

@deanbaker
Copy link
Copy Markdown
Contributor

@deanbaker deanbaker commented Mar 18, 2026

Fixes #666

Problem

Spirit rejects connections to MySQL servers that use mysql_native_password authentication:

[mysql] could not use requested auth plugin 'mysql_native_password': this user requires mysql native password authentication
spirit: error: [MAIN-DATABASE-CONNECTION-FALLBACK] ping failed: this user requires mysql native password authentication

Root Cause

In newDSN() (pkg/dbconn/conn.go), Spirit explicitly sets several driver config options (RejectReadOnly, InterpolateParams, AllowCleartextPasswords) but does not explicitly set AllowNativePasswords. While NewConfig() defaults it to true, FormatDSN() omits default-true values from the DSN string, making the setting fragile across DSN serialization/deserialization cycles.

Fix

Explicitly set cfg.AllowNativePasswords = true in newDSN(), consistent with how other driver options are already configured.

Test

Added TestNewDSNAllowNativePasswords which validates AllowNativePasswords is true for both TLS-enabled (default PREFERRED mode) and TLS-disabled (fallback path) DSNs, and asserts the DSN never contains allowNativePasswords=false.

Also verified with integration test against a MySQL server using mysql_native_password:

  • Baseline (no fix): could not use requested auth plugin 'mysql_native_password'
  • Fixed: Connects successfully, proceeds to migration

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>
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

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=true on the MySQL driver config in newDSN().
  • 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 morgo merged commit f78688a into block:main Mar 18, 2026
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Fix: explicitly set AllowNativePasswords=true to support mysql_native_password auth

3 participants