Skip to content

Commit 28f7fbf

Browse files
authored
Set mysqldump SSL/TLS args based on 'tls' connection URL param. (#679)
It looks like the default for `--ssl-verify-server-cert` was changed from `FALSE` to `TRUE` in MariaDB Connector/C in version 3.4, corresponding to MariaDB 11.4: mariadb-corporation/mariadb-connector-c@1287c90 > Since version 3.4 peer certificate verification is enabled by default. https://mariadb.com/docs/server/security/securing-mariadb/securing-mariadb-encryption/data-in-transit-encryption/securing-connections-for-client-and-server#enabling-one-way-tls-for-mariadb-clients > Starting from [MariaDB 11.4](https://mariadb.com/docs/release-notes/community-server/mariadb-11-4-series/what-is-mariadb-114) (Connector/C version 3.4) this mode is enabled by default. As `dbmate` uses the `go-sql-driver/mysql` driver for executing queries, which sets [tls=false](https://github.com/go-sql-driver/mysql?tab=readme-ov-file#tls) by default, we don't see a change when applying migrations. However, `dbmate` executes `mysqldump` to dump schemas, and that's where the change in MariaDB hits us. We should disable SSL/TLS when invoking `mysqldump` if `tls` is `false`, and we should use `--ssl-verify-server-cert=false` if `tls` is `skip-verify`. This fixes the following CI test failures: ``` === RUN TestMySQLDumpSchema Dropping: dbmate_test Creating: dbmate_test mysql_test.go:202: Error Trace: /src/pkg/driver/mysql/mysql_test.go:202 Error: Received unexpected error: mysqldump: Got error: 2026: "TLS/SSL error: self-signed certificate in certificate chain" when trying to connect Test: TestMySQLDumpSchema --- FAIL: TestMySQLDumpSchema (0.04s) === RUN TestMySQLDumpSchemaContainsNoAutoIncrement Dropping: dbmate_test Creating: dbmate_test mysql_test.go:246: Error Trace: /src/pkg/driver/mysql/mysql_test.go:246 Error: Received unexpected error: mysqldump: Got error: 2026: "TLS/SSL error: self-signed certificate in certificate chain" when trying to connect Test: TestMySQLDumpSchemaContainsNoAutoIncrement --- FAIL: TestMySQLDumpSchemaContainsNoAutoIncrement (0.04s) ```
1 parent 3fe5366 commit 28f7fbf

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

pkg/driver/mysql/mysql.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,14 @@ func (drv *Driver) mysqldumpArgs() []string {
132132
args := []string{"--opt", "--routines", "--no-data",
133133
"--skip-dump-date", "--skip-add-drop-table"}
134134

135+
tls := drv.databaseURL.Query().Get("tls")
136+
if tls == "" || strings.EqualFold(tls, "false") {
137+
args = append(args, "--ssl=false")
138+
}
139+
if strings.EqualFold(tls, "skip-verify") {
140+
args = append(args, "--ssl-verify-server-cert=false")
141+
}
142+
135143
socket := drv.databaseURL.Query().Get("socket")
136144
if socket != "" {
137145
args = append(args, "--socket="+socket)

pkg/driver/mysql/mysql_test.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,7 @@ func TestMySQLDumpArgs(t *testing.T) {
154154
"--no-data",
155155
"--skip-dump-date",
156156
"--skip-add-drop-table",
157+
"--ssl=false",
157158
"--host=bob",
158159
"mydb"}, drv.mysqldumpArgs())
159160

@@ -163,6 +164,20 @@ func TestMySQLDumpArgs(t *testing.T) {
163164
"--no-data",
164165
"--skip-dump-date",
165166
"--skip-add-drop-table",
167+
"--ssl=false",
168+
"--host=bob",
169+
"--port=5678",
170+
"--user=alice",
171+
"--password=pw",
172+
"mydb"}, drv.mysqldumpArgs())
173+
174+
drv.databaseURL = dbtest.MustParseURL(t, "mysql://alice:pw@bob:5678/mydb?tls=skip-verify")
175+
require.Equal(t, []string{"--opt",
176+
"--routines",
177+
"--no-data",
178+
"--skip-dump-date",
179+
"--skip-add-drop-table",
180+
"--ssl-verify-server-cert=false",
166181
"--host=bob",
167182
"--port=5678",
168183
"--user=alice",
@@ -175,6 +190,7 @@ func TestMySQLDumpArgs(t *testing.T) {
175190
"--no-data",
176191
"--skip-dump-date",
177192
"--skip-add-drop-table",
193+
"--ssl=false",
178194
"--socket=/var/run/mysqld/mysqld.sock",
179195
"--user=alice",
180196
"--password=pw",

0 commit comments

Comments
 (0)