Fix MariaDB 11.4+ warnings with --no-defaults flag #297
+23
−8
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.
MariaDB 11.4+ emits SSL verification warnings when
MYSQL_PWDis used with--no-defaults, treating the environment variable as "no password provided" for SSL purposes.Changes
Added
--ssl-verify-server-certflag conditionally only for MariaDB (not MySQL) to all MySQL/mysqldump commands using--no-defaultsinsrc/Context/FeatureContext.php:create_db()- CREATE DATABASE commandtest_connection()- connection test querydrop_db()- DROP DATABASE commandinstall_wp()- mysql source and mysqldump commandsImplementation
The database type is now auto-detected using
Utils\get_db_type()when not explicitly set via theWP_CLI_TEST_DBTYPEenvironment variable:Created a helper method
is_mariadb()to detect MariaDB installations by checking the database type:The flag is then added conditionally:
Before
After
This suppresses the warning for MariaDB without changing MySQL behavior. The detection uses
Utils\get_db_type()which checks the binary version output for the 'MariaDB' string, making it reliable for both standard and custom installations.Original prompt
This section details on the original issue you should resolve
<issue_title>Using MYSQL_PWD causes warnings in recent versions of MariaDB</issue_title>
<issue_description>Background: We remove the password from any mysql commands and store it in the
MYSQL_PWDenv var:https://github.com/wp-cli/wp-cli/blob/aeae8711ad62327b943f2fb9d1ed8770dd01b4d6/php/utils.php#L596-L599
This practice used to be encouraged years ago with the idea being that if you send the password on the command line anybody can see it in the output of ps / top / etc...
The problem is, you can also see env vars in these tools as well (
ps aux efor example), so you can't really hide the password that way either. On modern systems it is easy and common to make it so users just can't see other users processes, which is the more secure method (see hidepid)MariaDB specifically discourages using
MYSQL_PWD:https://mariadb.com/kb/en/mariadb-environment-variables/
And as of this commit from last year: MariaDB/server@853bdf5
It now displays a warning when the following conditions are true:
These conditions are true for wp-cli, because we use
MYSQL_PWDwhich MariaDB considers to beno password was provided(here).This is normally fixable by adding this to the config:
But it doesn't remove the warnings in our test environment because we use
--no-defaultsin several places, which tells MariaDB to ignore the config file:wp-cli-tests/src/Context/FeatureContext.php
Lines 994 to 1004 in c388578
Additionally, our tests use that as well: https://github.com/search?q=repo%3Awp-cli%2Fdb-command%20--no-defaults&type=code
So our CI tests for MariaDB don't work because many SQL commands emit the warning:
Probably the correct solution overall is to not use
MYSQL_PWDas it is discouraged. Alternatives would possibly be manually adding--disable-ssl-verify-server-cert(or--ssl-verify-server-cert) to all of these commands. I believe the issue isn't with the option itself, but when the option is not explicitly stated AND there is no password sent as part of the command.related slack discussion</issue_description>
Comments on the Issue (you are @copilot in this section)
@mrsdizzie Steps to test and reproduce this locally: ``` docker run --name mariadb-test \ -e MARIADB_ROOT_PASSWORD=root \ -e MARIADB_USER=wp_cli_test \ -e MARIADB_PASSWORD=password1 \ -e MARIADB_DATABASE=wp_cli_test \ -d mariadb:11.4docker exec -it mariadb-test bash
Using password directly works with no warning
root@154e63c58cd5:/# mariadb -u wp_cli_test -p'password1' -h 127.0.0.1 --port=3306 --protocol=tcp -e "SHOW DATABASES;"
+--------------------+
| Database |
+--------------------+
| information_schema |
| wp_cli_test |
+--------------------+
Using MYSQL_PWD works but causes warning
root@154e63c58cd5:/# export MYSQL_PWD=password1
root@154e63c58cd5:/# mariadb -uwp_cli_test -h 127.0.0.1 --port=3306 --protocol=tcp -e "SHOW DATABASES;"
WARNING: option --ssl-verify-server-cert is disabled, because of an insecure passwordless login.
+--------------------+
| Database |
+--------------------+
| information_schema |
| wp_cli_test |
+--------------------+
Edit /etc/mysql/my.cnf and add:
[client-mariadb]
ssl-verify-server-cert
Now works without warning
root@154e63c58cd5:/# mariadb -u wp_cli_test -h 127.0.0.1 --port=3306 --protocol=tcp -e "SHOW DATABASES;"
+--------------------+
| Database |
+--------------------+
| information_schema |
| wp_cli_test |
+--------------------+
Using --no-defaults ignores the config file and warning is back
root@154e63c58cd5:/# mariadb --no-defaults -u wp_cli_test -h 127.0.0.1 --port=3306 --protocol=tcp -e "SHOW DATABASES;"
WARNING: option --ssl-verify-server-cert is disabled, because of an insecure passwordless login.
+--------------------+
| Database |
+--------------------+
| information_schema |
| wp_cli_test |
+--------------------+
Adding --ssl-verify-server-cert directly to command removes warning:
root@154e63...
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.