Skip to content

Conversation

@eldering
Copy link
Member

@eldering eldering commented Nov 27, 2025

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

@Kevinjil Kevinjil marked this pull request as draft November 27, 2025 21:18
@eldering eldering force-pushed the fix-mysql-password branch 23 times, most recently from 224970f to 9ca1d55 Compare November 29, 2025 16:10
@eldering eldering marked this pull request as ready for review November 29, 2025 16:47
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.
@eldering eldering force-pushed the fix-mysql-password branch 3 times, most recently from 9a31f6b to 60d7773 Compare November 29, 2025 19:10
Copy link
Member

@meisterT meisterT left a 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//\'/\\\'}"
Copy link
Member

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"));'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants