@@ -28,6 +28,11 @@ PMA_HOST=${PMA_HOST:-db}
2828PMA_PORT=${PMA_PORT:- 3306}
2929PMA_ABSOLUTE_URI=${PMA_ABSOLUTE_URI:- }
3030PMA_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:- }
3136UPLOAD_LIMIT=${UPLOAD_LIMIT:- 256M}
3237MEMORY_LIMIT=${MEMORY_LIMIT:- 512M}
3338MAX_EXECUTION_TIME=${MAX_EXECUTION_TIME:- 600}
5964 fi
6065fi
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 )"
6381cat > " $CONFIG " << PHPCONF
6482<?php
6583declare(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';
91109PHPCONF
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+
93119if [ -n " $PMA_ABSOLUTE_URI " ]; then
94120 printf " \$ cfg['PmaAbsoluteUri'] = '%s';\n" " $PMA_ABSOLUTE_URI " >> " $CONFIG "
95121fi
0 commit comments