bitnami Postgresql 16.2 Password authentication failed for user Role does not exist

88 Views Asked by At

I'm trying to run bitnami/postgresql:16.2.0 docker image, but no luck.

Here are the steps:

  1. stop container, delete container, clean "data" directory

docker stop RR15 ; docker rm RR15 ; rm -rf ~/containers/postgres16.2/data/

  1. here is my custom pg_hba.conf (only 2 lines not commented):

    host all all 0.0.0.0/0 md5

    host all all 127.0.0.1/32 md5

  2. run docker

docker run --name RR15 -p 5432:5432 -v ~/containers/postgres16.2:/bitnami/postgresql -v ~/containers/postgres16.2/conf:/bitnami/postgresql/conf -e POSTGRESQL_USERNAME=user1 -e POSTGRESQL_PASSWORD=pwduser1 -e POSTGRESQL_DATABASE=postgres -e POSTGRESQL_POSTGRES_PASSWORD=postgres bitnami/postgresql:16.2.0

so

  • POSTGRESQL_USERNAME=user1
  • POSTGRESQL_PASSWORD=pwduser1
  • POSTGRESQL_DATABASE=postgres
  • POSTGRESQL_POSTGRES_PASSWORD=postgres. (more info about this param)

As soon as I execute the command it starts and stops, looks fine ... no issues, full detail here:

postgresql 19:03:04.46 INFO  ==> 
postgresql 19:03:04.46 INFO  ==> Welcome to the Bitnami postgresql container
postgresql 19:03:04.46 INFO  ==> Subscribe to project updates by watching https://github.com/bitnami/containers
postgresql 19:03:04.46 INFO  ==> Submit issues and feature requests at https://github.com/bitnami/containers/issues
postgresql 19:03:04.47 INFO  ==> Upgrade to Tanzu Application Catalog for production environments to access custom-configured and pre-packaged software components. Gain enhanced features, including Software Bill of Materials (SBOM), CVE scan result reports, and VEX documents. To learn more, visit https://bitnami.com/enterprise
postgresql 19:03:04.47 INFO  ==> 
postgresql 19:03:04.48 INFO  ==> ** Starting PostgreSQL setup **
postgresql 19:03:04.50 INFO  ==> Validating settings in POSTGRESQL_* env vars..
postgresql 19:03:04.52 INFO  ==> Loading custom pre-init scripts...
postgresql 19:03:04.52 INFO  ==> Initializing PostgreSQL database...
postgresql 19:03:04.53 INFO  ==> Custom configuration /opt/bitnami/postgresql/conf/postgresql.conf detected
postgresql 19:03:04.53 INFO  ==> Custom configuration /opt/bitnami/postgresql/conf/pg_hba.conf detected
postgresql 19:03:08.14 INFO  ==> Starting PostgreSQL in background...
postgresql 19:03:08.26 INFO  ==> Changing password of postgres
postgresql 19:03:08.27 INFO  ==> Stopping PostgreSQL...
waiting for server to shut down.... done
server stopped

I'm stating the container again and so far it looks good:

2024-03-18 12:03:14 postgresql 19:03:14.78 INFO  ==> 
2024-03-18 12:03:14 postgresql 19:03:14.79 INFO  ==> Welcome to the Bitnami postgresql container
2024-03-18 12:03:14 postgresql 19:03:14.79 INFO  ==> Subscribe to project updates by watching https://github.com/bitnami/containers
2024-03-18 12:03:14 postgresql 19:03:14.79 INFO  ==> Submit issues and feature requests at https://github.com/bitnami/containers/issues
2024-03-18 12:03:14 postgresql 19:03:14.79 INFO  ==> Upgrade to Tanzu Application Catalog for production environments to access custom-configured and pre-packaged software components. Gain enhanced features, including Software Bill of Materials (SBOM), CVE scan result reports, and VEX documents. To learn more, visit https://bitnami.com/enterprise
2024-03-18 12:03:14 postgresql 19:03:14.79 INFO  ==> 
2024-03-18 12:03:14 postgresql 19:03:14.81 INFO  ==> ** Starting PostgreSQL setup **
2024-03-18 12:03:14 postgresql 19:03:14.82 INFO  ==> Validating settings in POSTGRESQL_* env vars..
2024-03-18 12:03:14 postgresql 19:03:14.83 INFO  ==> Loading custom pre-init scripts...
2024-03-18 12:03:14 postgresql 19:03:14.83 INFO  ==> Initializing PostgreSQL database...
2024-03-18 12:03:14 postgresql 19:03:14.84 INFO  ==> Custom configuration /opt/bitnami/postgresql/conf/postgresql.conf detected
2024-03-18 12:03:14 postgresql 19:03:14.84 INFO  ==> Custom configuration /opt/bitnami/postgresql/conf/pg_hba.conf detected
2024-03-18 12:03:14 postgresql 19:03:14.86 INFO  ==> Deploying PostgreSQL with persisted data...
2024-03-18 12:03:14 postgresql 19:03:14.86 INFO  ==> Loading custom scripts...
2024-03-18 12:03:14 postgresql 19:03:14.87 INFO  ==> ** PostgreSQL setup finished! **
2024-03-18 12:03:14 
2024-03-18 12:03:14 postgresql 19:03:14.88 INFO  ==> ** Starting PostgreSQL **
2024-03-18 12:03:14 2024-03-18 19:03:14.901 GMT [1] LOG:  pgaudit extension initialized
2024-03-18 12:03:14 2024-03-18 19:03:14.921 GMT [1] LOG:  starting PostgreSQL 16.2 on x86_64-pc-linux-gnu, compiled by gcc (Debian 12.2.0-14) 12.2.0, 64-bit
2024-03-18 12:03:14 2024-03-18 19:03:14.922 GMT [1] LOG:  listening on IPv4 address "0.0.0.0", port 5432
2024-03-18 12:03:14 2024-03-18 19:03:14.922 GMT [1] LOG:  listening on IPv6 address "::", port 5432
2024-03-18 12:03:14 2024-03-18 19:03:14.925 GMT [1] LOG:  listening on Unix socket "/tmp/.s.PGSQL.5432"
2024-03-18 12:03:14 2024-03-18 19:03:14.934 GMT [55] LOG:  database system was shut down at 2024-03-18 19:03:08 GMT
2024-03-18 12:03:14 2024-03-18 19:03:14.944 GMT [1] LOG:  database system is ready to accept connections

Now I'm trying to connect as user1 with pwduser1 to postgres:

connect as user1 with pwduser1 to postgres

2024-03-18 12:05:49 2024-03-18 19:05:49.737 GMT [62] FATAL:  password authentication failed for user "user1"
2024-03-18 12:05:49 2024-03-18 19:05:49.737 GMT [62] DETAIL:  Role "user1" does not exist.
2024-03-18 12:05:49     Connection matched file "/opt/bitnami/postgresql/conf/pg_hba.conf" line 96: "host    all             all                 0.0.0.0/0               md5"

Same for postgres with password "postgres" to postgres DB:

postgres with password "postgres"

2024-03-18 12:04:33 2024-03-18 19:04:33.260 GMT [60] FATAL:  password authentication failed for user "postgres"
2024-03-18 12:04:33 2024-03-18 19:04:33.260 GMT [60] DETAIL:  User "postgres" has no password assigned.
2024-03-18 12:04:33     Connection matched file "/opt/bitnami/postgresql/conf/pg_hba.conf" line 96: "host    all             all                 0.0.0.0/0               md5"

I'm not sure what's wrong here, and I'm trying to find the cause. I could use a bandage-like solution, such as connecting and changing passwords, or using "trust" for localhost. However, I prefer to create a correct Docker command.

I had the same setup for v15.4, and it worked just fine. It feels like the issue is connected with volume mapping.

Any help is appreciated!

update

After looking at the Rabban Keyak's answer I played a bit more and find out that if I exclude pg_hba.conf everything works as it should

The package itself generates this content for pg_hba.conf:

host     all             all             0.0.0.0/0               md5
host     all             all             ::/0                    md5
local    all             all                                     md5
host     all             all        127.0.0.1/32                 md5
host     all             all        ::1/128                      md5

However, changing the content to this ^^ doesn't help.

1

There are 1 best solutions below

1
Rabban Keyak On

Not like instantly, but in about 15 minutes i've done repeating your case.

Differeces:

  • Using podman instead of docker (doesn't have the last one installed nearby)
  • Using port 55432 on the host system instead of 5432 (the last one is busy already for me)
  • Using --mount instead of -v, and it's option U=true to achieve apropriate rights for directories
  • Using scram-sha-256 hash instead of md5

After all of that i was able to connect the server using psql.

[admin200 /]$ podman version
Client:       Podman Engine
Version:      4.9.0
API Version:  4.9.0
Go Version:   go1.21.6
Built:        Wed Jan 24 13:07:27 2024
OS/Arch:      linux/amd64
[admin200 /]$ cd ~/
[admin200 ~]$ TMPDIR=$(mktemp -p$(realpath .) -d)
[admin200 ~]$ cd ${TMPDIR}
[admin200 tmp.TMsoFC5xs8]$ mkdir basedir
[admin200 tmp.TMsoFC5xs8]$ mkdir conf
[admin200 tmp.TMsoFC5xs8]$ echo 'host all all 0.0.0.0/0 scram-sha-256' > conf/pg_hba.conf
[admin200 tmp.TMsoFC5xs8]$ podman run -d \
--name pb16 \
-p 127.0.0.1:55432:5432 \
--mount type=bind,source="${TMPDIR}/basedir",destination=/bitnami/postgresql,U=true \
--mount type=bind,source="${TMPDIR}/conf",destination=/bitmani/postgresql/conf,U=true \
-e POSTGRESQL_USERNAME=user1 \
-e POSTGRESQL_PASSWORD=la50360329x \
-e POSTGRESQL_DATABASE=database1 \
docker.io/bitnami/postgresql:16.2.0
56ea65776fd187c86f960a4d74cffeef9d5fdffbe7d3194c40df44cb8a153aa4
[admin200 tmp.TMsoFC5xs8]$ PGPASSWORD=la50360329x PGSSLMODE=disable psql -h 127.0.0.1 -p 55432 -U user1 -d database1 -c '\l'
                                                       List of databases
   Name    |  Owner   | Encoding | Locale Provider |   Collate   |    Ctype    | ICU Locale | ICU Rules |   Access privileges   
-----------+----------+----------+-----------------+-------------+-------------+------------+-----------+-----------------------
 database1 | user1    | UTF8     | libc            | en_US.UTF-8 | en_US.UTF-8 |            |           | =Tc/user1            +
           |          |          |                 |             |             |            |           | user1=CTc/user1
 postgres  | postgres | UTF8     | libc            | en_US.UTF-8 | en_US.UTF-8 |            |           | 
 template0 | postgres | UTF8     | libc            | en_US.UTF-8 | en_US.UTF-8 |            |           | =c/postgres          +
           |          |          |                 |             |             |            |           | postgres=CTc/postgres
 template1 | postgres | UTF8     | libc            | en_US.UTF-8 | en_US.UTF-8 |            |           | =c/postgres          +
           |          |          |                 |             |             |            |           | postgres=CTc/postgres
(4 rows)

[admin200 tmp.TMsoFC5xs8]$ sudo ls -la basedir/data/
total 96
drwx------ 19 201000 domain users 4096 Mar 19 00:08 .
drwxr-xr-x  3 201000 domain users 4096 Mar 19 00:08 ..
-rw-------  1 201000 domain users    3 Mar 19 00:08 PG_VERSION
drwx------  6 201000 domain users 4096 Mar 19 00:08 base
drwx------  2 201000 domain users 4096 Mar 19 00:09 global
drwx------  2 201000 domain users 4096 Mar 19 00:08 pg_commit_ts
drwx------  2 201000 domain users 4096 Mar 19 00:08 pg_dynshmem
-rw-------  1 201000 domain users 2640 Mar 19 00:08 pg_ident.conf
drwx------  4 201000 domain users 4096 Mar 19 00:08 pg_logical
drwx------  4 201000 domain users 4096 Mar 19 00:08 pg_multixact
drwx------  2 201000 domain users 4096 Mar 19 00:08 pg_notify
drwx------  2 201000 domain users 4096 Mar 19 00:08 pg_replslot
drwx------  2 201000 domain users 4096 Mar 19 00:08 pg_serial
drwx------  2 201000 domain users 4096 Mar 19 00:08 pg_snapshots
drwx------  2 201000 domain users 4096 Mar 19 00:08 pg_stat
drwx------  2 201000 domain users 4096 Mar 19 00:08 pg_stat_tmp
drwx------  2 201000 domain users 4096 Mar 19 00:08 pg_subtrans
drwx------  2 201000 domain users 4096 Mar 19 00:08 pg_tblspc
drwx------  2 201000 domain users 4096 Mar 19 00:08 pg_twophase
drwx------  3 201000 domain users 4096 Mar 19 00:08 pg_wal
drwx------  2 201000 domain users 4096 Mar 19 00:08 pg_xact
-rw-------  1 201000 domain users   88 Mar 19 00:08 postgresql.auto.conf
-rw-------  1 201000 domain users  249 Mar 19 00:08 postmaster.opts
-rw-------  1 201000 domain users   79 Mar 19 00:08 postmaster.pid
[admin200 tmp.TMsoFC5xs8]$ podman stop pb16
pb16
[admin200 tmp.TMsoFC5xs8]$ cd ..
[admin200 ~]$ rm -rf ${TMPDIR}

The image you are using is fine seems. The problem seems like somewhere behind of my changes.