I want to authenticate Linux host's users with the PostgreSQL database running in the docker container (If PG is installed natively, it works fine). I have a compose file like:
version: "3"
services:
postgres:
image: postgres:latest
container_name: pg
volumes:
- /etc/passwd:/etc/passwd
- /etc/shadow:/etc/shadow
- /etc/pam.d/:/etc/pam.d/
ports:
- 5432:5432
environment:
POSTGRES_USERNAME: postgres
POSTGRES_PASSWORD: postgres
My pg_hba.conf file is:
# "local" is for Unix domain socket connections only
local all all trust
# PAM Authentication
host all all 0.0.0.0/0 pam
# IPv4 local connections:
host all all 127.0.0.1/32 trust
# IPv6 local connections:
host all all ::1/128 trust
# Allow replication connections from localhost, by a user with the
# replication privilege.
local replication all trust
host replication all 127.0.0.1/32 trust
host replication all ::1/128 trust
Under /var/lib/postgresql/data but I get the error when executing inside the container:
root@21cdb0e36245:/var/lib/postgresql/data# psql -h 127.0.0.1 -U testuser
Password for user testuser:
psql: error: FATAL: PAM authentication failed for user "testuser"
Am I missing something in the volume mounts?
pg_hba.confline and describe your PAM setup.postgresql.