incorrect use of PGADMIN_CONFIG_CONFIG_DATABASE_URI in entrypoint.sh
Please note that security bugs or issues should be reported to [email protected].
Describe the bug
I have an error when starting pgadmin container (dpage/pgadmin:9.15.0).
`
Traceback (most recent call last):
File "
File "/pgadmin4/pgadmin/utils/check_external_config_db.py", line 18, in check_external_config_db
engine = create_engine(database_uri)
File "
The check for PGADMIN_CONFIG_CONFIG_DATABASE_URI in entrypoint.sh is incorrect. The line 153 put double quotes around environment variable but the var should be specified with single quotes for correct generation of config_distro.py.
external_config_db_exists=$(cd /pgadmin4/pgadmin/utils && $SU_EXEC /venv/bin/python3 -c "from check_external_config_db import check_external_config_db; val = check_external_config_db(\"${PGADMIN_CONFIG_CONFIG_DATABASE_URI}\"); print(val)")
The error doesn't prevent the start of pgadmin.
To Reproduce
Steps to reproduce the behavior:
- configure PGADMIN_CONFIG_CONFIG_DATABASE_URI
- start container
- check container log
Expected behavior
No error reported
Indeed: without quotes config.py fails with "SyntaxError: invalid syntax" on CONFIG_DATABASE_URI = postgresql+psycopg://…, but with quotes in docker variable, double quotes are used in check_external_config_db("'postgresql+psycopg://…'"), which confuses SQLAlchemy. Manually overriding entrypoint.sh with a copy with quotes removed from line 153 fixes this error, but runs into another problem, where PGADMIN_DEFAULT_EMAIL and PGADMIN_DEFAULT_PASSWORD are not used anymore.
Thanks for the report — and to @angs for the follow-up confirming the PGADMIN_DEFAULT_EMAIL/PGADMIN_DEFAULT_PASSWORD regression that comes with it. Both symptoms have the same root cause; diagnosed and fixed in draft PR #10009.
Diagnosis
pkg/docker/entrypoint.sh constructs a Python -c argument by shell-substituting ${PGADMIN_CONFIG_CONFIG_DATABASE_URI} inside a double-quoted Python string:
val = check_external_config_db("${PGADMIN_CONFIG_CONFIG_DATABASE_URI}")
That collides with the long-standing config_distro.py convention, which requires the env var's value to be a Python literal (so the entrypoint's CONFIG_DATABASE_URI = $val append produces valid Python). So users correctly set the env var to 'postgresql+psycopg://...'. The entrypoint then re-wraps that literal in another set of quotes, producing check_external_config_db("'postgresql+psycopg://...'") — a string with literal single quotes inside, which SQLAlchemy can't parse → ArgumentError.
The PGADMIN_DEFAULT_EMAIL symptom is the same crash propagating downstream: Python raises, $(...) captures empty stdout, so external_config_db_exists="". The later check [ "${external_config_db_exists}" = "False" ] then evaluates to false (empty ≠ "False"), so the entire first-launch user-setup block at line 224 is silently skipped — and your default email/password are never applied.
Regression history
Bisected to commit 1fe840fca ("Allow to pass PGADMIN_CONFIG_CONFIG_DATABASE_URI from docker secrets", #5869, Oct 2024), which incidentally added the shell "…" quoting around the expansion in an otherwise focused docker-secrets PR. The pre-Oct-2024 form (bare ${VAR} expansion, ed211a2bb, Sep 2024) worked correctly with the convention.
Why both env-var forms are broken on shipped images
| Env var form | Result |
|---|---|
PGADMIN_CONFIG_CONFIG_DATABASE_URI="'postgresql+psycopg://…'" (with quotes, the documented convention) |
SQLAlchemy ArgumentError + silent PGADMIN_DEFAULT_EMAIL skip — what you hit |
PGADMIN_CONFIG_CONFIG_DATABASE_URI=postgresql+psycopg://… (without quotes) |
config_distro.py becomes invalid Python → container exits on startup — what @angs hit |
Fix shape (in PR #10009)
Removes the shell from the quoting question altogether — Python reads the env var via os.environ and uses ast.literal_eval to unwrap any Python-literal quoting. All three forms ('url', "url", raw url) now parse to the same clean URI and round-trip through check_external_config_db correctly. The "False" default is also preserved on any Python failure, fixing the secondary symptom.
Workaround until the fix lands
Either pin a pre-Oct-2024 image (e.g. v9.13), or override pkg/docker/entrypoint.sh lines 197-201 in your image with this:
external_config_db_exists="False"
if [ -n "${PGADMIN_CONFIG_CONFIG_DATABASE_URI}" ]; then
result=$(cd /pgadmin4/pgadmin/utils && $SU_EXEC /venv/bin/python3 -c "
import os, ast
from check_external_config_db import check_external_config_db
raw = os.environ['PGADMIN_CONFIG_CONFIG_DATABASE_URI']
try:
uri = ast.literal_eval(raw)
except (ValueError, SyntaxError):
uri = raw
print(check_external_config_db(uri))
" 2>/dev/null)
if [ -n "$result" ]; then
external_config_db_exists="$result"
fi
fi
That's the patch PR #10009 lands. Restores both the URI parse path and the default-user creation path.
This was fixed and is included in pgAdmin 4 9.16 (via commit c88c8f612). The fix is listed in the 9.16 release notes; the auto-close keyword on the merged PR didn't fire, so closing manually. Please reopen if you still see it on 9.16+.