Skip to content

Commit f5fc022

Browse files
authored
Merge pull request #19 from netresearch/feat/pma-user-password
feat: support PMA_USER and PMA_PASSWORD like upstream does
2 parents 6b54c99 + 6afeadd commit f5fc022

2 files changed

Lines changed: 36 additions & 2 deletions

File tree

.env.example

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,14 @@ PMA_BLOWFISH_SECRET=
2121
# than the container sees, e.g. https://admin.example.org/pma/
2222
PMA_ABSOLUTE_URI=
2323

24+
# Auto-login. Setting BOTH switches the server from cookie auth to config
25+
# auth, which writes the credentials into the generated config file — meant
26+
# for a local development database, not for anything others can reach. One of
27+
# the two alone is ignored, because it would only produce a login that cannot
28+
# succeed.
29+
PMA_USER=
30+
PMA_PASSWORD=
31+
2432
# --- limits -----------------------------------------------------------------
2533
UPLOAD_LIMIT=256M
2634
MEMORY_LIMIT=512M

rootfs/usr/local/bin/entrypoint.sh

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,11 @@ PMA_HOST=${PMA_HOST:-db}
2828
PMA_PORT=${PMA_PORT:-3306}
2929
PMA_ABSOLUTE_URI=${PMA_ABSOLUTE_URI:-}
3030
PMA_ARBITRARY=${PMA_ARBITRARY:-0}
31+
# Upstream's auto-login pair. Both set switches the server to config auth,
32+
# which puts the credentials in the generated config file — sensible for a
33+
# local database, not for anything reachable by others.
34+
PMA_USER=${PMA_USER:-}
35+
PMA_PASSWORD=${PMA_PASSWORD:-}
3136
UPLOAD_LIMIT=${UPLOAD_LIMIT:-256M}
3237
MEMORY_LIMIT=${MEMORY_LIMIT:-512M}
3338
MAX_EXECUTION_TIME=${MAX_EXECUTION_TIME:-600}
@@ -59,7 +64,20 @@ else
5964
fi
6065
fi
6166

62-
log "writing $CONFIG (host $PMA_HOST:$PMA_PORT, arbitrary=$PMA_ARBITRARY)"
67+
# Cookie auth asks for credentials; config auth carries them. Only the pair
68+
# switches — one of the two alone would produce a login that cannot succeed.
69+
AUTH_TYPE=cookie
70+
if [ -n "$PMA_USER" ] && [ -n "$PMA_PASSWORD" ]; then
71+
AUTH_TYPE=config
72+
log "PMA_USER and PMA_PASSWORD are set: using config auth. The credentials"
73+
log "land in $CONFIG — intended for a local database, not a shared one."
74+
elif [ -n "$PMA_USER" ] || [ -n "$PMA_PASSWORD" ]; then
75+
log "only one of PMA_USER/PMA_PASSWORD is set — ignoring both, staying on cookie auth"
76+
PMA_USER=""
77+
PMA_PASSWORD=""
78+
fi
79+
80+
log "writing $CONFIG (host $PMA_HOST:$PMA_PORT, auth $AUTH_TYPE, arbitrary=$PMA_ARBITRARY)"
6381
cat > "$CONFIG" <<PHPCONF
6482
<?php
6583
declare(strict_types=1);
@@ -74,7 +92,7 @@ ${MARKER}
7492
\$i = 1;
7593
\$cfg['Servers'][\$i]['host'] = '${PMA_HOST}';
7694
\$cfg['Servers'][\$i]['port'] = '${PMA_PORT}';
77-
\$cfg['Servers'][\$i]['auth_type'] = 'cookie';
95+
\$cfg['Servers'][\$i]['auth_type'] = '${AUTH_TYPE}';
7896
\$cfg['Servers'][\$i]['AllowNoPassword'] = false;
7997
// Arbitrary-server mode lets anyone reaching this UI point it at any host
8098
// the container can route to. Off unless asked for.
@@ -90,6 +108,14 @@ ${MARKER}
90108
\$cfg['SendErrorReports'] = 'never';
91109
PHPCONF
92110

111+
# Appended rather than interpolated above, so the password never reaches the
112+
# here-document that is written unconditionally — and so a config without the
113+
# pair carries no empty credential lines at all.
114+
if [ "$AUTH_TYPE" = "config" ]; then
115+
printf "\$cfg['Servers'][\$i]['user'] = '%s';\n" "$PMA_USER" >> "$CONFIG"
116+
printf "\$cfg['Servers'][\$i]['password'] = '%s';\n" "$PMA_PASSWORD" >> "$CONFIG"
117+
fi
118+
93119
if [ -n "$PMA_ABSOLUTE_URI" ]; then
94120
printf "\$cfg['PmaAbsoluteUri'] = '%s';\n" "$PMA_ABSOLUTE_URI" >> "$CONFIG"
95121
fi

0 commit comments

Comments
 (0)