-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Description
When setting the password with the direct POSTGRES_PASSWORD
environment variable, everything works fine: I am able to connect to the database and create tables and stuff.
However, with the exact same docker-compose configuration, but using POSTGRES_PASSWORD_FILE
instead (pointing to bind-mounted read-only file inside the container), then trying to connect to the database ends up with the no pg_hba.conf entry for host
error.
I created both versions and looked at the configuration in $PGDATA/pg_hba.conf
, and the one using POSTGRES_PASSWORD_FILE
is missing the host all all all md5
line.
Here is a repository to reproduce, and here is the related DBA StackExchange post.
If I understand correctly the docker-entrypoint.sh
script, the configuration should not change depending on the use of POSTGRES_PASSWORD
or POSTGRES_PASSWORD_FILE
. The file_env
function simply fills the first one thanks to the second:
postgres/10/docker-entrypoint.sh
Lines 8 to 24 in 1805adb
file_env() { | |
local var="$1" | |
local fileVar="${var}_FILE" | |
local def="${2:-}" | |
if [ "${!var:-}" ] && [ "${!fileVar:-}" ]; then | |
echo >&2 "error: both $var and $fileVar are set (but are exclusive)" | |
exit 1 | |
fi | |
local val="$def" | |
if [ "${!var:-}" ]; then | |
val="${!var}" | |
elif [ "${!fileVar:-}" ]; then | |
val="$(< "${!fileVar}")" | |
fi | |
export "$var"="$val" | |
unset "$fileVar" | |
} |
Then the host all all all md5
should be appended in this block:
postgres/10/docker-entrypoint.sh
Lines 65 to 92 in 1805adb
file_env 'POSTGRES_PASSWORD' | |
if [ "$POSTGRES_PASSWORD" ]; then | |
pass="PASSWORD '$POSTGRES_PASSWORD'" | |
authMethod=md5 | |
else | |
# The - option suppresses leading tabs but *not* spaces. :) | |
cat >&2 <<-'EOWARN' | |
**************************************************** | |
WARNING: No password has been set for the database. | |
This will allow anyone with access to the | |
Postgres port to access your database. In | |
Docker's default configuration, this is | |
effectively any other container on the same | |
system. | |
Use "-e POSTGRES_PASSWORD=password" to set | |
it in "docker run". | |
**************************************************** | |
EOWARN | |
pass= | |
authMethod=trust | |
fi | |
{ | |
echo | |
echo "host all all all $authMethod" | |
} >> "$PGDATA/pg_hba.conf" |
Am I missing something or is it really unwanted behavior?