-
Notifications
You must be signed in to change notification settings - Fork 278
Fix mysql password #3235
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Fix mysql password #3235
Conversation
6d04e54 to
02540df
Compare
224970f to
9ca1d55
Compare
The domjudge mysql user should be created by our setup scripts, so that we test these and need to set the password only in one place. Rename mysql_root to mysql_log helper to clarify behaviour.
See for reference: - https://dev.mysql.com/doc/refman/8.0/en/connecting-using-uri-or-key-value-pairs.html#connecting-using-uri - https://symfony.com/doc/current/doctrine.html but note that we must use `rawurlencode` instead of `urlencode` which differ in how they encode a space (as tested). Fixes: #2651 Closes: #2502 as this is likely fixed but I couldn't reproduce it
Use URL encoding in DATABASE_URL and return mysql_options as an array (via ugly global variable), so each element in it can be separately added to the command line using `@` for expansion. Because of changing the script to bash, also reverts some of the changes in 483200a. The changed escaping of `DoctrineMigrations\\Version` passed to mysql is purely due to changing from `/bin/sh` to `/bin/bash`. Somehow passing that to the `mysql` wrapper function, it got unescaped before, even though `/bin/sh` is just a symlink to bash...
We don't care where the user is connecting from, and this helps when the MySQL server is not running on localhost.
This is consistent with all the other functions.
9a31f6b to
60d7773
Compare
60d7773 to
fa5654a
Compare
meisterT
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
generally LGTM, please have a look at my replacement suggestion for escaping
| { | ||
| # We need to escape for PHP ' and \ by prefixing them with a \. | ||
| local str="${1//\\/\\\\}" | ||
| str="${str//\'/\\\'}" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The whole escaping here looks error prone (and is still not correct).
What about using this trick instead which doesn't require escaping:
printf '%s' "$1" | php -r 'echo rawurlencode(file_get_contents("php://stdin"));'
The password is passed inside the environment variable DATABASE_URL which is URI-like. However, it must be URL encoded there if it contains any strange characters, like a space, %, etc.
This also overhauls the CI job code to unify setting the mysql and admin password in one place and use our tooling instead of custom SQL queries where possible.
Recreate of #2660