·5 min read
A MySQL init file full of passwords, and a CI check that raced it
On a customer's first MySQL start, my image writes a SQL file containing the root password and the app user's password, hands it to mysqld, and then has to make sure it does not stay on disk. I had that working. Then I noticed how I was handing it over: as a flag glued onto the end of the startup line, which the entrypoint printed to the panel console. Two small commits later the file path was out of the console, the socket lived in a private directory, and the test that proved the file was gone stopped being a coin flip.
- Project
- Pterodactyl yolks
- Date
- Oct 2026
- Stack
- Docker, Shell, MySQL 8.4, GitHub Actions
- Commit
- b96c9f5, 46468c5
What broke
MySQL needs a few statements run before it accepts connections for the first time: set the root password, create the customer's database and the app user. The only clean way to do that without a running server is --init-file. The entrypoint writes those statements to /tmp/renode-init.sql and needs mysqld to read it once.
The first version of the image (f80c221) did the obvious thing and appended the flag to whatever startup string the panel passed:
echo ":/home/container$ ${MODIFIED_STARTUP} --init-file=${INIT}"
...
setsid bash -c "${MODIFIED_STARTUP} --init-file=${INIT}" </dev/null &Two things were wrong with it. The echo line is what Pterodactyl's console shows, so a hosting customer's console printed the path of a file that holds passwords. The file itself was fine by then, written under umask 077, but a console line pointing at it invites exactly the curiosity I did not want. And a flag stitched onto a string the panel owns is fragile: whatever the egg's startup line says, my code is editing it.
What the code showed
Looking at the entrypoint, the secret handling had three parts and only one of them was where it belonged. The init file was written with a restrictive umask and lived in /tmp, outside the customer's volume, so the file manager never showed it. That part was right. A subshell removes it once the server is up:
# The init file holds passwords on first start; it is only read at startup.
(
for _ in $(seq 1 120); do
[ -S "$SOCKET" ] && break
kill -0 "$PID" 2>/dev/null || exit 0
sleep 1
done
sleep 2
rm -f "$INIT"
) &It waits for the socket to appear, sleeps two more seconds, and deletes the file. That also explains the second problem. The socket and pid file sat directly in /tmp (/tmp/mysqld.sock, /tmp/mysqld.pid), a shared directory. Nothing was visibly broken, but the server's runtime state sat in a directory I did not control, next to the file that opens the database.
The third part was in CI. My workflow asserted, right after its queries, that the init file no longer existed. But the removal runs on a timer: the socket appears, then two seconds pass, then rm. A test that checks immediately can see the file still there. The assertion raced the cleanup, and a flaky security check is worse than none, because the natural reaction is to retry until it goes green.
The fix
46468c5 (Oct 2026) did two things. The socket and pid file moved into a run directory, and the CI step learned to wait:
RUNDIR=/tmp/mysqld
SOCKET=${RUNDIR}/mysqld.sock
PIDFILE=${RUNDIR}/mysqld.pid
...
mkdir -p -m 700 "$RUNDIR"# The first-start init file carries passwords; it must not linger.
for i in $(seq 1 15); do docker exec ci test -e /tmp/renode-init.sql || break; sleep 1; done
docker exec ci test ! -e /tmp/renode-init.sqlThe loop polls for up to 15 seconds and stops as soon as the file is gone. The assertion after it is still strict: if the file is still there after the wait, the build fails. I did not loosen the check, I gave it the time the cleanup is designed to take.
One minute later, b96c9f5 (Oct 2026) fixed the console problem. The generated config now carries the init file itself, with a comment saying what it is for:
# Statements run once as the server starts, before it takes connections.
echo "init-file=${INIT}"The startup line is left exactly as the panel sent it, so the echo prints nothing about the file, and --init-file is gone from both places it was glued on. The extra export RENODE_INIT_FILE went with it, since nothing read it any more.
What I would do differently
The CI wait is a timer matching a timer, and that is the weak spot. The cleanup sleeps two seconds after the socket appears and the test polls for 15, so it works, but the number is a guess on both sides. I would make the entrypoint write a small marker when the removal is done and have the test wait on that, so the check follows a fact instead of a duration.
I would also decide on the secret path before writing the first version. I treated the init file as a file problem (permissions, location, cleanup) and the console as someone else's concern. Anything that touches a secret should be reviewed from the outside in: who can read it, where it is printed, and how a test can prove both.
Where this fits
This is the MySQL part of a pattern in all my Pterodactyl images: secrets stay out of the customer's volume and out of the console, and CI has to prove it. The full yolks case study covers the same idea in Valkey's password config and the other images, and the boot test that every one of them now has.
Read the entrypoint and the workflow to see how the init file is written, referenced, removed and checked.
View the image on GitHub#mysql#docker#pterodactyl#security#ci
Keep reading
Have a project in mind?