0

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?

8
  • You should show the pg_hba.conf line and describe your PAM setup. Commented Feb 2, 2021 at 11:35
  • Okay updated the question Commented Feb 2, 2021 at 11:41
  • Looks like you didn't configure the PAM service postgresql. Commented Feb 2, 2021 at 11:47
  • I followed the same when working with native postgres installed and it works but Not working in docker. Commented Feb 2, 2021 at 11:51
  • Then you didn't configure PAM correctly in the docker container. Commented Feb 2, 2021 at 11:53

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.