-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
initial user does not respect $POSTGRES_HOST_AUTH_METHOD=scram-sha-256 #726
Comments
Can't reproduce. Is your database being fully initialized in time? $ docker run -d --rm --name postgres -e POSTGRES_USER=user -e POSTGRES_PASSWORD=pass -e POSTGRES_DB=db -e POSTGRES_HOST_AUTH_METHOD=scram-sha-256 postgres:12
552e1ffaef464c9a09e3dface53418841c834ab4edb284c354a6b1085fddb350
$ docker exec -it postgres bash -c 'psql -d $POSTGRES_DB -U $POSTGRES_USER'
psql (12.2 (Debian 12.2-2.pgdg100+1))
Type "help" for help.
db-# \du+
List of roles
Role name | Attributes | Member of | Description
-----------+------------------------------------------------------------+-----------+-------------
user | Superuser, Create role, Create DB, Replication, Bypass RLS | {} |
db-# \q
$ docker exec -it postgres bash
root@552e1ffaef46:/# cat /var/lib/postgresql/data/pg_hba.conf | grep -v '^#\|^$'
local all all trust
host all all 127.0.0.1/32 trust
host all all ::1/128 trust
local replication all trust
host replication all 127.0.0.1/32 trust
host replication all ::1/128 trust
host all all all scram-sha-256 |
It seems like the database fully initializes. The list of roles is identical to yours and the entries in pg_hba.conf match. When I try to log in this is what happens:
This is the output from the logs:
|
setting |
I'm facing the same issue.
But it would be nicer to set password_encryption in postgresql.conf to variable value.
It will set variable value if it is set, and md5 if not. |
I think this is technically fixed most appropriately by #897 👍 |
I am still seeing this issue with the latest image (version 14). version: '3.3' pg_hba.conflocal all all scram-sha-256 local replication all scram-sha-256 host all all all scram-sha-256 postgresql.conflisten_addresses = '*' These are my config, Expected: connection allowed from any IP using username and password set while creating the Postgres container, but the docker environment variables set are not respected and I am not able to login using the credentials. These are the logs I see from the container: From the logs, it seems that the connection is reaching the container, and the set config to allow connections from any host is working, but the credentials seem to be the issue here. Can someone please help? what am I doing wrong here? Based on this issue, the fix is already merged but I am still seeing the same error. This is the workaround I have found so far to be working after banging my head on the wall for 7 hours and multiple trials and errors later. Thought to share as it might save some immediate headache to other devs trying to set up the same now. But it is tedious to set up a docker container and follow these additional steps to reset the password and then log back into DB. docker-compose (working for now): version: '3.3'
|
Thanks @preethaml7 for that work around. I was fighting the exact same thing yesterday evening also on a postgres:14 container. For me this happened after changing pg_hba.conf. With the initial auth config created by the container the login was working for some time now. I then changed that file to be more restrictive and require mTLS ( |
Here is how to replicate the issue.
docker-compose.yml
:./env/.env.db
:Run
docker-compose up -d
and thendocker-compose run db-test /bin/bash -c 'psql -d $POSTGRES_DB -U $POSTGRES_USER -h $DB_HOST'
Enter
pass
as your password.It would fail.
Now modify
./env/.env.db
as such:Run
docker-compose down && docker-compose up -d
and thendocker-compose run db-test /bin/bash -c 'psql -d $POSTGRES_DB -U $POSTGRES_USER -h $DB_HOST'
again.Enter
pass
as your password.This time it would succeed.
I purposely didn't persist any data for the database to start with a new clean environment on each try.
The text was updated successfully, but these errors were encountered: