0

Good day!

I have a task to delimit user access to databases

for example, that user_1 would have access only to the database of "oranges" and user_2 only to the database of "watermelons"

I try to do this through pg_hba.conf, but I can still connect to the watermelon database through user_1

MY pg_hba.conf

# PostgreSQL Client Authentication Configuration File
# ===================================================
#
# Refer to the "Client Authentication" section in the PostgreSQL
# documentation for a complete description of this file.  A short
# synopsis follows.
#
# This file controls: which hosts are allowed to connect, how clients
# are 
#...



# TYPE  DATABASE        USER            ADDRESS                 METHOD

# "local" is for Unix domain socket connections only
# local   all             all                                     trust
# 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

# host all all all scram-sha-256

host    oranges user_1  password
host    watermelons user_2  password

MY DOCKERFILE

FROM postgres:14.1
RUN rm -f /var/lib/postgresql/data/pg_hba.conf
COPY ./pg_hba.conf /var/lib/postgresql/data/pg_hba.conf
ADD ./init.sql /docker-entrypoint-initdb.d/
ENTRYPOINT ["docker-entrypoint.sh"]
CMD ["postgres"]

MY DOCKER-COMPOSE

version: "3.9"
services:

  #DATABASE_SERVER
  postgres:
    build: ./databases/postgres
    hostname: postgres
    environment:
      POSTGRES_PASSWORD: root
      PGDATA: /var/lib/postgresql/data
    ports:
      - 5432:5432

What am I doing wrong? I will be grateful for any comment!

MiyRon
  • 99
  • 7
  • Check what is actually in the file matches what you think is there. – jjanes Feb 07 '22 at 17:55
  • `select * from pg_hba_file_rules;`, see: [How do I query the running pg_hba configuration?](https://dba.stackexchange.com/questions/181639/how-do-i-query-the-running-pg-hba-configuration) – Luuk Feb 07 '22 at 18:24
  • @Luuk indeed, my configuration does not seem to exist. How to enable my configuration? – MiyRon Feb 08 '22 at 02:25
  • @MiyRon: i am not really familiar with docker, but i would start [here](https://www.google.com/search?q=how+to+copy+a+file+to+docker+container), and then find [docker cp \[OPTIONS\] SRC_PATH CONTAINER:DEST_PATH](https://stackoverflow.com/a/70936011/724039) – Luuk Feb 08 '22 at 16:05

0 Answers0