From f8192b82b8d1cf416464911c15eb52a0d28e6687 Mon Sep 17 00:00:00 2001 From: Yogesh Mahajan Date: Thu, 14 Nov 2024 13:09:21 +0530 Subject: [PATCH] Allow the use of a pgpass file in the pgAdmin container via Docker secrets. #5786 --- pkg/docker/entrypoint.sh | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/pkg/docker/entrypoint.sh b/pkg/docker/entrypoint.sh index 64110a8c3..b4887fefa 100755 --- a/pkg/docker/entrypoint.sh +++ b/pkg/docker/entrypoint.sh @@ -118,9 +118,8 @@ if [ ! -f /var/lib/pgadmin/pgadmin4.db ] && [ "${external_config_db_exists}" = " /venv/bin/python3 /pgadmin4/setup.py load-servers "${PGADMIN_SERVER_JSON_FILE}" --user "${PGADMIN_DEFAULT_EMAIL}" fi fi + # Pre-load any required preferences if [ -f "${PGADMIN_PREFERENCES_JSON_FILE}" ]; then - # When running in Desktop mode, no user is created - # so we have to import servers anonymously if [ "${PGADMIN_CONFIG_SERVER_MODE}" = "False" ]; then DESKTOP_USER=$(cd /pgadmin4 && /venv/bin/python3 -c 'import config; print(config.DESKTOP_USER)') /venv/bin/python3 /pgadmin4/setup.py set-prefs "${DESKTOP_USER}" --input-file "${PGADMIN_PREFERENCES_JSON_FILE}" @@ -128,6 +127,18 @@ if [ ! -f /var/lib/pgadmin/pgadmin4.db ] && [ "${external_config_db_exists}" = " /venv/bin/python3 /pgadmin4/setup.py set-prefs "${PGADMIN_DEFAULT_EMAIL}" --input-file "${PGADMIN_PREFERENCES_JSON_FILE}" fi fi + # Copy the pgpass file passed using secrets + if [ -f "${PGPASS_FILE}" ]; then + if [ "${PGADMIN_CONFIG_SERVER_MODE}" = "False" ]; then + cp ${PGPASS_FILE} /var/lib/pgadmin/.pgpass + chmod 600 /var/lib/pgadmin/.pgpass + else + PGADMIN_USER_CONFIG_DIR=$(echo "${PGADMIN_DEFAULT_EMAIL}" | sed 's/@/_/g') + mkdir -p /var/lib/pgadmin/storage/${PGADMIN_USER_CONFIG_DIR} + cp ${PGPASS_FILE} /var/lib/pgadmin/storage/${PGADMIN_USER_CONFIG_DIR}/.pgpass + chmod 600 /var/lib/pgadmin/storage/${PGADMIN_USER_CONFIG_DIR}/.pgpass + fi + fi fi