Fix DSN construction to support passwords with special characters#593
Merged
morgo merged 6 commits intoblock:mainfrom Mar 2, 2026
Merged
Fix DSN construction to support passwords with special characters#593morgo merged 6 commits intoblock:mainfrom
morgo merged 6 commits intoblock:mainfrom
Conversation
Replace fmt.Sprintf-based DSN construction with mysql.Config.FormatDSN() in Runner.dsn(), and rewrite newDSN() to set parameters on the parsed config struct instead of naive string concatenation. The old approach used strings.Contains(dsn, "?") to detect query params, which broke when passwords contained "?" (e.g. AWS IAM auth tokens), causing all session variables and driver options to be absorbed into the DB name. Also enable AllowCleartextPasswords, which is required for AWS RDS IAM authentication (mysql_clear_password plugin).
Remove redundant TLS parameter pre-checks that were bypassing DSN construction. Remove unused createFallbackDSN function. Make AllowCleartextPasswords conditional on TLS being configured rather than always enabled. Update tests for corrected mixed-case TLS parameter behavior and add special character password round-trip tests.
Empty tls= is indistinguishable from unset after ParseDSN, so the TLS config should be applied rather than preserving the empty value. Remove allowNativePasswords=true from expected params since true is the go-mysql-driver default and FormatDSN() omits default values.
…n newDSN - newDSN: replace early return when TLS is set with a guard around only the TLS switch block, so session variables (sql_mode, time_zone, innodb_lock_wait_timeout, RejectReadOnly, etc.) are always applied - addTLSParametersToDSN: check cfg.TLSConfig before overwriting to preserve user-supplied TLS overrides (e.g. tls=skip-verify) - Update tests to verify TLS preservation via parsed config rather than raw string equality Amp-Thread-ID: https://ampcode.com/threads/T-019c63df-40f9-740b-8419-c3aa7d83cb32 Co-authored-by: Amp <amp@ampcode.com>
Kiran01bm
reviewed
Feb 16, 2026
Resolve conflicts in pkg/dbconn/conn.go and pkg/migration/runner_test.go: - conn.go: Keep PR's cfg.TLSConfig/cfg.FormatDSN() approach (safe for special characters in passwords) with main's switch statement structure - runner_test.go: Keep both TestDSN (from PR) and TestEnumReorder/ TestSetReorder (from main)
…ve mixed-case TLS test wording - Remove cfg.AllowNativePasswords = true since it is the default in go-sql-driver (https://github.com/go-sql-driver/mysql/blob/v1.9.3/dsn.go#L96) - Improve test description for mixed-case TLS parameter edge case to explicitly call out that uppercase 'TLS' is ignored by ParseDSN and passed through as an unknown query parameter - Remove stale comment referencing AllowNativePasswords in fallback test
morgo
approved these changes
Mar 2, 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.
Summary
Fixes #592
fmt.Sprintfand manual string concatenation breaks when passwords contain special characters (@,?,&,/) — common in AWS IAM authentication tokensnewDSN()inpkg/dbconn/conn.goanddsn()inpkg/migration/runner.goto use thego-sql-driver/mysqllibrary's structuredConfigtype withParseDSN()/FormatDSN()instead of manual string building@,?,&, and full AWS IAM-style tokens to verify correct round-trippingTest plan
@, multiple@, mixed special chars, empty password, AWS IAM-style token)go test ./pkg/dbconn/... ./pkg/migration/...)🤖 Generated with Claude Code