Skip to content

Commit d80865d

Browse files
authored
Merge pull request #334 from wp-cli/fix/mariadb-ssl-verify-warning-309
Skip server certificate verification for MariaDB connections
2 parents 4107c98 + c62855a commit d80865d

2 files changed

Lines changed: 31 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 to
125+
# STDERR (or fails) against the auto-generated self-signed certificate, which broke
126+
# the tests. `run()` now opts out via `--skip-ssl-verify-server-cert` on MariaDB, 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: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1988,6 +1988,17 @@ private static function run( $cmd, $assoc_args = [], $send_to_shell = true, $int
19881988
unset( $assoc_args['dbpass'], $assoc_args['password'] );
19891989
}
19901990

1991+
// MariaDB 11.4 enables TLS server certificate verification by default. WP-CLI
1992+
// connects the same way WordPress does, which does not verify the certificate,
1993+
// and against MariaDB's auto-generated self-signed certificate verification
1994+
// either just warns on STDERR that it disabled itself or fails outright. Opt out
1995+
// explicitly to keep the previous behaviour, unless the user asked to verify.
1996+
if ( 'mariadb' === Utils\get_db_type()
1997+
&& ! isset( $assoc_args['ssl-verify-server-cert'] )
1998+
&& ! isset( $assoc_args['skip-ssl-verify-server-cert'] ) ) {
1999+
$required['skip-ssl-verify-server-cert'] = true;
2000+
}
2001+
19912002
$final_args = array_merge( $required, $assoc_args );
19922003

19932004
// Filter out empty string values to avoid passing empty parameters to MySQL commands
@@ -2232,6 +2243,7 @@ private static function get_mysql_args( $assoc_args ) {
22322243
'skip-pager',
22332244
'skip-reconnect',
22342245
'skip-ssl',
2246+
'skip-ssl-verify-server-cert',
22352247
'socket',
22362248
'ssl',
22372249
'ssl-ca',
@@ -2243,6 +2255,7 @@ private static function get_mysql_args( $assoc_args ) {
22432255
'ssl-fips-mode',
22442256
'ssl-key',
22452257
'ssl-mode',
2258+
'ssl-verify-server-cert',
22462259
'syslog',
22472260
'table',
22482261
'tee',

0 commit comments

Comments
 (0)