Skip to content

Commit 9852586

Browse files
committed
Set more grep-able passwords in CI jobs, drop domjudge user
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.
1 parent 2ec4c8c commit 9852586

File tree

6 files changed

+42
-53
lines changed

6 files changed

+42
-53
lines changed

.github/jobs/baseinstall.sh

Lines changed: 24 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@ export APP_ENV="${4:-prod}"
1111
# In the test environment, we need to use a different database
1212
[ "$APP_ENV" = "prod" ] && DATABASE_NAME=domjudge || DATABASE_NAME=domjudge_test
1313

14-
MYSQL_ROOT_PASSWORD=${MYSQL_ROOT_PASSWORD:-root}
15-
1614
set -euxo pipefail
1715

1816
if [ -z "$phpversion" ]; then
@@ -74,25 +72,22 @@ EOF
7472
cat ~/.my.cnf
7573

7674
# TODO: Remove after fixing https://github.com/DOMjudge/domjudge/issues/2848
77-
mysql_root "SET GLOBAL innodb_snapshot_isolation = OFF;"
75+
mysql_log "SET GLOBAL innodb_snapshot_isolation = OFF;"
7876

79-
mysql_root "CREATE DATABASE IF NOT EXISTS \`$DATABASE_NAME\` DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;"
80-
mysql_root "CREATE USER IF NOT EXISTS \`domjudge\`@'%' IDENTIFIED BY 'domjudge';"
81-
mysql_root "GRANT SELECT, INSERT, UPDATE, DELETE ON \`$DATABASE_NAME\`.* TO 'domjudge'@'%';"
82-
mysql_root "FLUSH PRIVILEGES;"
77+
mysql_log "CREATE DATABASE IF NOT EXISTS \`$DATABASE_NAME\` DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;"
78+
mysql_log "CREATE USER IF NOT EXISTS \`domjudge\`@'%' IDENTIFIED BY 'domjudge';"
79+
mysql_log "GRANT SELECT, INSERT, UPDATE, DELETE ON \`$DATABASE_NAME\`.* TO 'domjudge'@'%';"
80+
mysql_log "FLUSH PRIVILEGES;"
81+
echo "unused:sqlserver:$DATABASE_NAME:domjudge:domjudge:3306" > /opt/domjudge/domserver/etc/dbpasswords.secret
8382

8483
# Show some MySQL debugging
85-
mysql_root "show databases"
86-
mysql_root "SELECT CURRENT_USER();"
87-
mysql_root "SELECT USER();"
88-
mysql_root "SELECT user,host FROM mysql.user"
89-
mysql_root "SET GLOBAL max_allowed_packet=1073741824"
90-
mysql_root "SHOW GLOBAL STATUS LIKE 'Connection_errors_%'"
91-
mysql_root "SHOW VARIABLES LIKE 'innodb_snapshot_isolation'"
92-
mysql_root "SHOW VARIABLES LIKE '%_timeout'"
93-
echo "unused:sqlserver:$DATABASE_NAME:domjudge:domjudge:3306" > /opt/domjudge/domserver/etc/dbpasswords.secret
94-
mysql_user "SELECT CURRENT_USER();"
95-
mysql_user "SELECT USER();"
84+
mysql_log "show databases"
85+
mysql_log "SELECT CURRENT_USER();"
86+
mysql_log "SELECT USER();"
87+
mysql_log "SELECT user,host FROM mysql.user"
88+
mysql_log "SET GLOBAL max_allowed_packet=1073741824"
89+
mysql_log "SHOW GLOBAL STATUS LIKE 'Connection_errors_%'"
90+
mysql_log "SHOW VARIABLES LIKE '%_timeout'"
9691
section_end
9792

9893
if [ "${db}" = "install" ]; then
@@ -102,6 +97,7 @@ if [ "${db}" = "install" ]; then
10297
elif [ "${db}" = "upgrade" ]; then
10398
section_start "Upgrade DOMjudge database"
10499
/opt/domjudge/domserver/bin/dj_setup_database -uroot -p${MYSQL_ROOT_PASSWORD} upgrade
100+
/opt/domjudge/domserver/webapp/bin/console domjudge:reset-user-password admin "pass"
105101
section_end
106102
fi
107103

@@ -141,31 +137,31 @@ if [ "${db}" = "install" ]; then
141137
section_start "Install the example data"
142138
if [ "$version" = "unit" ]; then
143139
# Make sure admin has no team associated so we will not insert submissions during unit tests.
144-
mysql_root "UPDATE user SET teamid=null WHERE userid=1;" $DATABASE_NAME
140+
mysql_log "UPDATE user SET teamid=null WHERE userid=1;" $DATABASE_NAME
145141
fi
146142
/opt/domjudge/domserver/bin/dj_setup_database -uroot -p${MYSQL_ROOT_PASSWORD} install-examples | tee -a "$ARTIFACTS/mysql.txt"
147143
section_end
148144
fi
149145

150146
section_start "Setup user"
151147
# We're using the admin user in all possible roles
152-
mysql_root "DELETE FROM userrole WHERE userid=1;" $DATABASE_NAME
148+
mysql_log "DELETE FROM userrole WHERE userid=1;" $DATABASE_NAME
153149
if [ "$version" = "team" ]; then
154150
# Add team to admin user
155-
mysql_root "INSERT INTO userrole (userid, roleid) VALUES (1, 3);" $DATABASE_NAME
156-
mysql_root "UPDATE user SET teamid = 1 WHERE userid = 1;" $DATABASE_NAME
151+
mysql_log "INSERT INTO userrole (userid, roleid) VALUES (1, 3);" $DATABASE_NAME
152+
mysql_log "UPDATE user SET teamid = 1 WHERE userid = 1;" $DATABASE_NAME
157153
elif [ "$version" = "jury" ]; then
158154
# Add jury to admin user
159-
mysql_root "INSERT INTO userrole (userid, roleid) VALUES (1, 2);" $DATABASE_NAME
155+
mysql_log "INSERT INTO userrole (userid, roleid) VALUES (1, 2);" $DATABASE_NAME
160156
elif [ "$version" = "balloon" ]; then
161157
# Add balloon to admin user
162-
mysql_root "INSERT INTO userrole (userid, roleid) VALUES (1, 4);" $DATABASE_NAME
158+
mysql_log "INSERT INTO userrole (userid, roleid) VALUES (1, 4);" $DATABASE_NAME
163159
elif [ "$version" = "admin" ]; then
164160
# Add admin to admin user
165-
mysql_root "INSERT INTO userrole (userid, roleid) VALUES (1, 1);" $DATABASE_NAME
161+
mysql_log "INSERT INTO userrole (userid, roleid) VALUES (1, 1);" $DATABASE_NAME
166162
elif [ "$version" = "all" ] || [ "$version" = "unit" ]; then
167-
mysql_root "INSERT INTO userrole (userid, roleid) VALUES (1, 1);" $DATABASE_NAME
168-
mysql_root "INSERT INTO userrole (userid, roleid) VALUES (1, 3);" $DATABASE_NAME
169-
mysql_root "UPDATE user SET teamid = 1 WHERE userid = 1;" $DATABASE_NAME
163+
mysql_log "INSERT INTO userrole (userid, roleid) VALUES (1, 1);" $DATABASE_NAME
164+
mysql_log "INSERT INTO userrole (userid, roleid) VALUES (1, 3);" $DATABASE_NAME
165+
mysql_log "UPDATE user SET teamid = 1 WHERE userid = 1;" $DATABASE_NAME
170166
fi
171167
section_end

.github/jobs/ci_settings.sh

100644100755
Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,9 @@ section_end_internal () {
2424
trace_on
2525
}
2626

27-
mysql_root () {
27+
mysql_log () {
2828
# shellcheck disable=SC2086
29-
echo "$1" | mysql -uroot -proot ${2:-} | tee -a "$ARTIFACTS"/mysql.txt
30-
}
31-
32-
mysql_user () {
33-
# shellcheck disable=SC2086
34-
echo "$1" | mysql -udomjudge -pdomjudge ${2:-} | tee -a "$ARTIFACTS"/mysql.txt
29+
echo "$1" | mysql -uroot -p${MYSQL_ROOT_PASSWORD} ${2:-} | tee -a "$ARTIFACTS"/mysql.txt
3530
}
3631

3732
show_phpinfo() {

.github/workflows/database-upgrade.yml

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ on:
99
jobs:
1010
upgrade_test:
1111
runs-on: ubuntu-latest
12+
env:
13+
MYSQL_ROOT_PASSWORD: mysql_root_password
1214
container:
1315
image: domjudge/gitlabci:24.04
1416
services:
@@ -17,9 +19,7 @@ jobs:
1719
ports:
1820
- 3306:3306
1921
env:
20-
MYSQL_ROOT_PASSWORD: root
21-
MYSQL_USER: domjudge
22-
MYSQL_PASSWORD: domjudge
22+
MYSQL_ROOT_PASSWORD: ${{ env.MYSQL_ROOT_PASSWORD }}
2323
options: --health-cmd="healthcheck.sh --connect --innodb_initialized" --health-interval=10s --health-timeout=5s --health-retries=3
2424
steps:
2525
- uses: actions/checkout@v4
@@ -38,18 +38,16 @@ jobs:
3838
restore-keys: |
3939
composer-
4040
- name: Import Database
41-
run: mysql -hsqlserver -uroot -proot < .github/jobs/data/dj733.sql
41+
run: mysql -hsqlserver -uroot -p${{ env.MYSQL_ROOT_PASSWORD }} < .github/jobs/data/dj733.sql
4242
- name: Upgrade DOMjudge
4343
run: .github/jobs/baseinstall.sh default upgrade
44-
- name: Setting initial Admin Password
45-
run: echo "pass" > /opt/domjudge/domserver/etc/initial_admin_password.secret
4644
- name: Check for Errors in the Upgrade
47-
run: mysql -hsqlserver -uroot -proot -e "SHOW TABLES FROM domjudge;"
45+
run: mysql -hsqlserver -uroot -p${{ env.MYSQL_ROOT_PASSWORD }} -e "SHOW TABLES FROM domjudge;"
4846
- name: Check for Errors in DOMjudge Webinterface
4947
run: .github/jobs/webstandard.sh none admin
5048
- name: dump the db
5149
if: ${{ !cancelled() }}
52-
run: mysqldump -uroot -proot --quick --max_allowed_packet=1024M domjudge > /tmp/db.sql
50+
run: mysqldump -hsqlserver -uroot -p${{ env.MYSQL_ROOT_PASSWORD }} --quick --max_allowed_packet=1024M domjudge > /tmp/db.sql
5351
- name: Upload database dump for debugging
5452
if: ${{ !cancelled() }}
5553
uses: actions/upload-artifact@v4

.github/workflows/integration.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ on:
99
jobs:
1010
integration:
1111
runs-on: ubuntu-24.04
12+
env:
13+
MYSQL_ROOT_PASSWORD: mysql_root_password
1214
timeout-minutes: 30
1315
container:
1416
image: domjudge/gitlabci:24.04
@@ -19,9 +21,7 @@ jobs:
1921
ports:
2022
- 3306:3306
2123
env:
22-
MYSQL_ROOT_PASSWORD: root
23-
MYSQL_USER: domjudge
24-
MYSQL_PASSWORD: domjudge
24+
MYSQL_ROOT_PASSWORD: ${{ env.MYSQL_ROOT_PASSWORD }}
2525
options: --health-cmd="healthcheck.sh --connect --innodb_initialized" --health-interval=10s --health-timeout=5s --health-retries=3
2626
steps:
2727
- uses: actions/checkout@v4
@@ -95,7 +95,7 @@ jobs:
9595
done
9696
- name: dump the db
9797
if: ${{ !cancelled() }}
98-
run: mysqldump -uroot -proot --quick --max_allowed_packet=1024M domjudge > /tmp/db.sql
98+
run: mysqldump -uroot -p${{ env.MYSQL_ROOT_PASSWORD }} --quick --max_allowed_packet=1024M domjudge > /tmp/db.sql
9999
- name: Upload database dump for debugging
100100
if: ${{ !cancelled() }}
101101
uses: actions/upload-artifact@v4

.github/workflows/unit-tests.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ jobs:
2828
permissions:
2929
checks: write
3030
runs-on: ubuntu-24.04
31+
env:
32+
MYSQL_ROOT_PASSWORD: mysql_root_password
3133
timeout-minutes: 30
3234
container:
3335
image: domjudge/gitlabci:24.04
@@ -37,9 +39,7 @@ jobs:
3739
ports:
3840
- 3306:3306
3941
env:
40-
MYSQL_ROOT_PASSWORD: root
41-
MYSQL_USER: domjudge
42-
MYSQL_PASSWORD: domjudge
42+
MYSQL_ROOT_PASSWORD: ${{ env.MYSQL_ROOT_PASSWORD }}
4343
options: --health-cmd="healthcheck.sh --connect --innodb_initialized" --health-interval=10s --health-timeout=5s --health-retries=3
4444
strategy:
4545
matrix:

.github/workflows/webstandard.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ on:
99
jobs:
1010
standards:
1111
runs-on: ubuntu-latest
12+
env:
13+
MYSQL_ROOT_PASSWORD: mysql_root_password
1214
container:
1315
image: domjudge/gitlabci:24.04
1416
services:
@@ -17,9 +19,7 @@ jobs:
1719
ports:
1820
- 3306:3306
1921
env:
20-
MYSQL_ROOT_PASSWORD: root
21-
MYSQL_USER: domjudge
22-
MYSQL_PASSWORD: domjudge
22+
MYSQL_ROOT_PASSWORD: ${{ env.MYSQL_ROOT_PASSWORD }}
2323
options: --health-cmd="healthcheck.sh --connect --innodb_initialized" --health-interval=10s --health-timeout=5s --health-retries=3
2424
strategy:
2525
matrix:

0 commit comments

Comments
 (0)