Skip to content

Commit d7d3a95

Browse files
committed
Skip server certificate verification for passwordless MariaDB connections
MariaDB 11.4 enables TLS server certificate verification by default. For a passwordless connection the auto-generated self-signed certificate cannot be verified, so MariaDB disables verification and prints a warning to STDERR. That warning fails the Behat tests on MariaDB and is noise for users running `wp db` commands. Explicitly pass `--skip-ssl-verify-server-cert` for passwordless MariaDB connections so the opt-out is intentional and the warning goes away. Enabling verification instead would force certificate checks that break older clients and self-signed or untrusted certificates, so password-protected connections are deliberately left untouched. Both `ssl-verify-server-cert` and its `skip-` variant are added to the allowed MySQL client options so the behaviour can be overridden per invocation.
1 parent 8a9a130 commit d7d3a95

2 files changed

Lines changed: 32 additions & 0 deletions

File tree

‎features/db-query.feature‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,3 +119,21 @@ Feature: Query the database with WordPress' MySQL config
119119
"""
120120
ANSI
121121
"""
122+
123+
# Regression test for https://github.com/wp-cli/db-command/issues/309
124+
# MariaDB 11.4+ verifies the server certificate by default and prints a warning
125+
# to STDERR for passwordless connections, which broke the tests. `run()` now opts
126+
# out via `--skip-ssl-verify-server-cert` for passwordless MariaDB connections, and
127+
# both `ssl-verify-server-cert` and its `skip-` variant are allowed so the behaviour
128+
# can be overridden. Assert the flag is forwarded to the MySQL client (visible in the
129+
# debug output before the connection is attempted). SQLite does not use the MySQL
130+
# client, hence the tag.
131+
@require-mysql-or-mariadb
132+
Scenario: Query forwards the ssl-verify-server-cert flags to the MySQL client
133+
Given a WP install
134+
135+
When I try `wp db query "SELECT 1" --skip-ssl-verify-server-cert --debug`
136+
Then STDERR should contain:
137+
"""
138+
skip-ssl-verify-server-cert
139+
"""

‎src/DB_Command.php‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1988,6 +1988,18 @@ private static function run( $cmd, $assoc_args = [], $send_to_shell = true, $int
19881988
unset( $assoc_args['dbpass'], $assoc_args['password'] );
19891989
}
19901990

1991+
// Passwordless MariaDB connections cannot verify the auto-generated self-signed
1992+
// certificate, so MariaDB disables verification and prints a warning to STDERR.
1993+
// Make that opt-out explicit to silence the warning, without forcing verification
1994+
// on (which would break older clients and untrusted certificates). Connections
1995+
// that use a password are left untouched.
1996+
if ( 'mariadb' === Utils\get_db_type()
1997+
&& '' === (string) $required['pass']
1998+
&& ! isset( $assoc_args['ssl-verify-server-cert'] )
1999+
&& ! isset( $assoc_args['skip-ssl-verify-server-cert'] ) ) {
2000+
$required['skip-ssl-verify-server-cert'] = true;
2001+
}
2002+
19912003
$final_args = array_merge( $required, $assoc_args );
19922004

19932005
// Filter out empty string values to avoid passing empty parameters to MySQL commands
@@ -2232,6 +2244,7 @@ private static function get_mysql_args( $assoc_args ) {
22322244
'skip-pager',
22332245
'skip-reconnect',
22342246
'skip-ssl',
2247+
'skip-ssl-verify-server-cert',
22352248
'socket',
22362249
'ssl',
22372250
'ssl-ca',
@@ -2243,6 +2256,7 @@ private static function get_mysql_args( $assoc_args ) {
22432256
'ssl-fips-mode',
22442257
'ssl-key',
22452258
'ssl-mode',
2259+
'ssl-verify-server-cert',
22462260
'syslog',
22472261
'table',
22482262
'tee',

0 commit comments

Comments
 (0)