Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1i8j9Y-00041R-B5 for pgsql-general@arkaria.postgresql.org; Fri, 13 Sep 2019 10:50:12 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1i8j9V-0006BA-Aw for pgsql-general@arkaria.postgresql.org; Fri, 13 Sep 2019 10:50:09 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1i8j9U-0006Aq-Ql for pgsql-general@lists.postgresql.org; Fri, 13 Sep 2019 10:50:09 +0000 Received: from hermes.gatewaynet.com ([193.92.121.98]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.92) (envelope-from ) id 1i8j9M-0007il-Jn for pgsql-general@lists.postgresql.org; Fri, 13 Sep 2019 10:50:07 +0000 Received: from smadev.internal.net (pc131.internal.net [10.9.200.131]) by hermes.gatewaynet.com (8.15.2/8.15.2/Debian-8) with ESMTPS id x8DAnoue020579 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Fri, 13 Sep 2019 13:49:56 +0300 Received: from smadev.internal.net (smadev [10.9.200.131]) by smadev.internal.net (8.15.2/8.15.2) with ESMTP id x8DAnopg050345 for ; Fri, 13 Sep 2019 13:49:50 +0300 (EEST) (envelope-from achill@matrix.gatewaynet.com) Subject: Re: pgbouncer with ldap To: pgsql-general@lists.postgresql.org References: <20190909074003.GA2404@elch.exwg.net> <20190909080358.GB2404@elch.exwg.net> <4742aa69-f831-fbfb-40a8-82f88b6ef408@matrix.gatewaynet.com> <7741646c-bd71-6506-a161-6f7b6284618b@matrix.gatewaynet.com> From: Achilleas Mantzios Message-ID: <6c17fe6e-db20-be49-ebdf-2eb03273b984@matrix.gatewaynet.com> Date: Fri, 13 Sep 2019 13:49:50 +0300 User-Agent: Mozilla/5.0 (X11; FreeBSD amd64; rv:60.0) Gecko/20100101 Thunderbird/60.3.2 MIME-Version: 1.0 In-Reply-To: Content-Type: multipart/alternative; boundary="------------CEB6CE5EEFDDD9467FAA16E8" Content-Language: en-US X-Virus-Scanned: clamav-milter 0.100.3 at hermes X-Virus-Status: Clean X-Spam-Status: No, score=-36.8 required=5.0 tests=ALL_TRUSTED,DYN_HAM_COORD, DYN_HAM_IT,DYN_HAM_IT_PARTNERS,DYN_HAM_NAUTICAL,DYN_HAM_SIGNAT1, HTML_MESSAGE,TW_PG,TW_TD autolearn=unavailable autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on hermes.gatewaynet.com List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk This is a multi-part message in MIME format. --------------CEB6CE5EEFDDD9467FAA16E8 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit On 13/9/19 10:19 π.μ., Ayub M wrote: > Stumbled in the first step - PAM authentication via pgbouncer. After compiling pgbouncer with the pam plug-in, I am unable to login into the db - throws PAM error message. Please help. > > User created with the same password as linux user -- > localhost:~$ psql -h dbhost -p 3306 -U admin -W db1 > db1=> create user testuser password 'hello123'; > CREATE ROLE > > [ec2-user@ip-1.1.1.1 pam.d]$ psql -h localhost -p 5432 testdb -U testuser > Password for user testuser: > psql: ERROR:  auth failed ok, pgbouncer should be able to read /etc/pam* files. Did you miss the |# chown root:staff ~pgbouncer/pgbouncer-1.9.0/pgbouncer | |# chmod +s ~pgbouncer/pgbouncer-1.9.0/pgbouncer| part? > > Log entries - pgbouncer.log > 2019-09-13 06:51:47.180 UTC [5752] LOG C-0x1243020: testdb/testuser@[::1]:52408 login attempt: db=testdb user=testuser tls=no > 2019-09-13 06:51:47.180 UTC [5752] NOISE safe_send(12, 9) = 9 > 2019-09-13 06:51:47.180 UTC [5752] NOISE resync(12): done=86, parse=86, recv=86 > 2019-09-13 06:51:47.180 UTC [5752] NOISE resync(12): done=0, parse=0, recv=0 > 2019-09-13 06:51:47.180 UTC [5752] NOISE safe_recv(12, 4096) = 14 > 2019-09-13 06:51:47.180 UTC [5752] NOISE C-0x1243020: testdb/testuser@[::1]:52408 read pkt='p' len=14 > 2019-09-13 06:51:47.180 UTC [5752] DEBUG C-0x1243020: testdb/testuser@[::1]:52408 pam_auth_begin(): pam_first_taken_slot=1, pam_first_free_slot=1 > 2019-09-13 06:51:47.180 UTC [5752] DEBUG pam_auth_worker(): processing slot 1 > 2019-09-13 06:51:47.180 UTC [5752] WARNING pam_authenticate() failed: Authentication failure > 2019-09-13 06:51:47.181 UTC [5752] DEBUG pam_auth_worker(): authorization completed, status=3 > 2019-09-13 06:51:47.386 UTC [5752] LOG C-0x1243020: testdb/testuser@[::1]:52408 closing because: auth failed (age=0s) > 2019-09-13 06:51:47.386 UTC [5752] WARNING C-0x1243020: testdb/testuser@[::1]:52408 pooler error: auth failed > > Able to login as testuser > [ec2-user@ip-1.1.1.1 pam.d]$ su - testuser > Password: > Last login: Fri Sep 13 06:21:12 UTC 2019 on pts/1 > [testuser@ip-1.1.1.1 ~]$ id > uid=1001(testuser) gid=1001(testuser) groups=1001(testuser) context=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023 > > The user was created as follows > [root@ip-1.1.1.1 ~]# adduser -p hello123 testuser > [root@ip-1.1.1.1 ~]# id testuser > uid=1001(testuser) gid=1001(testuser) groups=1001(testuser) > > Here is the pgbouncer.ini config > [ec2-user@ip-1.1.1.1 etc]$ less pgbouncer.ini | grep -v '^$' | grep -v '^;' > [databases] > testdb = host=dbhost port=3306 dbname=db1 > [users] > [pgbouncer] > logfile = /var/log/pgbouncer/pgbouncer.log > pidfile = /var/run/pgbouncer/pgbouncer.pid > listen_addr = * > listen_port = 5432 > auth_type = pam > > Am I missing something? Any permissions? > > On Thu, Sep 12, 2019 at 4:54 AM Ayub M > wrote: > > Okay, thanks for the response. Unfortunately Aurora does not expose these files or I should say there is no concept of these files in AWS managed Aurora DB service. Anyway I will give a try and > let you know. > > On Thu, Sep 12, 2019 at 1:52 AM Achilleas Mantzios > wrote: > > On 11/9/19 2:47 μ.μ., Ayub M wrote: >> Achilleas, for this setup to work are changes to postgresql.conf and pg_hba.conf needed? I am trying to implement this for AWS rds Aurora where these files are not accessible. >> > Those files are needed in any case if you work with postgresql. Unfortunately no experience with Aurora. He have been building from source for ages. >> On Mon, Sep 9, 2019, 6:46 AM Achilleas Mantzios > wrote: >> >> On 9/9/19 12:41 μ.μ., Laurenz Albe wrote: >> > Christoph Moench-Tegeder wrote: >> >>> It has hba and via hba file one can specify ldap connections >> >>> >> >>> https://www.postgresql.org/docs/9.3/auth-pg-hba-conf.html >> >> https://pgbouncer.github.io/config.html#hba-file-format >> >> "Auth-method field: Only methods supported by PgBouncer’s auth_type >> >> are supported", and "ldap" is not supported. >> >> When there's no ldap support in pgbouncer, there's no ldap support >> >> in pgbouncer. >> > To throw in something less tautological: >> > >> > PgBouncer supports PAM authentication, so if you are on UNIX, >> > you could use PAM's LDAP module to do what you want. >> Right, I had written a blog about it : >> https://severalnines.com/database-blog/one-security-system-application-connection-pooling-and-postgresql-case-ldap >> >> However, I always wished (since my first endeavors with pgbouncer) it was less complicated. >> > >> > Yours, >> > Laurenz Albe >> >> >> -- >> Achilleas Mantzios >> IT DEV Lead >> IT DEPT >> Dynacom Tankers Mgmt >> >> >> > > > -- > Achilleas Mantzios > IT DEV Lead > IT DEPT > Dynacom Tankers Mgmt > > > > -- > Regards, > Ayub > > > > -- > Regards, > Ayub -- Achilleas Mantzios IT DEV Lead IT DEPT Dynacom Tankers Mgmt --------------CEB6CE5EEFDDD9467FAA16E8 Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: 8bit
On 13/9/19 10:19 π.μ., Ayub M wrote:
Stumbled in the first step - PAM authentication via pgbouncer. After compiling pgbouncer with the pam plug-in, I am unable to login into the db - throws PAM error message. Please help.

User created with the same password as linux user --
localhost:~$ psql -h dbhost -p 3306 -U admin -W db1
db1=> create user testuser password 'hello123';
CREATE ROLE

[ec2-user@ip-1.1.1.1 pam.d]$ psql -h localhost -p 5432 testdb -U testuser
Password for user testuser: 
psql: ERROR:  auth failed

ok, pgbouncer should be able to read /etc/pam* files.
Did you miss the
# chown root:staff ~pgbouncer/pgbouncer-1.9.0/pgbouncer    
# chmod +s ~pgbouncer/pgbouncer-1.9.0/pgbouncer
part?


Log entries - pgbouncer.log
2019-09-13 06:51:47.180 UTC [5752] LOG C-0x1243020: testdb/testuser@[::1]:52408 login attempt: db=testdb user=testuser tls=no
2019-09-13 06:51:47.180 UTC [5752] NOISE safe_send(12, 9) = 9
2019-09-13 06:51:47.180 UTC [5752] NOISE resync(12): done=86, parse=86, recv=86
2019-09-13 06:51:47.180 UTC [5752] NOISE resync(12): done=0, parse=0, recv=0
2019-09-13 06:51:47.180 UTC [5752] NOISE safe_recv(12, 4096) = 14
2019-09-13 06:51:47.180 UTC [5752] NOISE C-0x1243020: testdb/testuser@[::1]:52408 read pkt='p' len=14
2019-09-13 06:51:47.180 UTC [5752] DEBUG C-0x1243020: testdb/testuser@[::1]:52408 pam_auth_begin(): pam_first_taken_slot=1, pam_first_free_slot=1
2019-09-13 06:51:47.180 UTC [5752] DEBUG pam_auth_worker(): processing slot 1
2019-09-13 06:51:47.180 UTC [5752] WARNING pam_authenticate() failed: Authentication failure
2019-09-13 06:51:47.181 UTC [5752] DEBUG pam_auth_worker(): authorization completed, status=3
2019-09-13 06:51:47.386 UTC [5752] LOG C-0x1243020: testdb/testuser@[::1]:52408 closing because: auth failed (age=0s)
2019-09-13 06:51:47.386 UTC [5752] WARNING C-0x1243020: testdb/testuser@[::1]:52408 pooler error: auth failed

Able to login as testuser 
[ec2-user@ip-1.1.1.1 pam.d]$ su - testuser 
Password: 
Last login: Fri Sep 13 06:21:12 UTC 2019 on pts/1
uid=1001(testuser) gid=1001(testuser) groups=1001(testuser) context=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023

The user was created as follows
[root@ip-1.1.1.1 ~]# adduser -p hello123 testuser
[root@ip-1.1.1.1 ~]# id testuser
uid=1001(testuser) gid=1001(testuser) groups=1001(testuser)

Here is the pgbouncer.ini config
[ec2-user@ip-1.1.1.1 etc]$ less pgbouncer.ini | grep -v '^$' | grep -v '^;' 
[databases]
testdb = host=dbhost port=3306 dbname=db1
[users]
[pgbouncer]
logfile = /var/log/pgbouncer/pgbouncer.log
pidfile = /var/run/pgbouncer/pgbouncer.pid
listen_addr = *
listen_port = 5432
auth_type = pam

Am I missing something? Any permissions?

On Thu, Sep 12, 2019 at 4:54 AM Ayub M <hiayub@gmail.com> wrote:
Okay, thanks for the response. Unfortunately Aurora does not expose these files or I should say there is no concept of these files in AWS managed Aurora DB service. Anyway I will give a try and let you know.

On Thu, Sep 12, 2019 at 1:52 AM Achilleas Mantzios <achill@matrix.gatewaynet.com> wrote:
On 11/9/19 2:47 μ.μ., Ayub M wrote:
Achilleas, for this setup to work are changes to postgresql.conf and pg_hba.conf needed? I am trying to implement this for AWS rds Aurora where these files are not accessible. 

Those files are needed in any case if you work with postgresql. Unfortunately no experience with Aurora. He have been building from source for ages.
On Mon, Sep 9, 2019, 6:46 AM Achilleas Mantzios <achill@matrix.gatewaynet.com> wrote:
On 9/9/19 12:41 μ.μ., Laurenz Albe wrote:
> Christoph Moench-Tegeder wrote:
>>> It has hba and via hba file one can specify ldap connections
>>>
>>> https://www.postgresql.org/docs/9.3/auth-pg-hba-conf.html
>> https://pgbouncer.github.io/config.html#hba-file-format
>> "Auth-method field: Only methods supported by PgBouncer’s auth_type
>> are supported", and "ldap" is not supported.
>> When there's no ldap support in pgbouncer, there's no ldap support
>> in pgbouncer.
> To throw in something less tautological:
>
> PgBouncer supports PAM authentication, so if you are on UNIX,
> you could use PAM's LDAP module to do what you want.
Right, I had written a blog about it :
https://severalnines.com/database-blog/one-security-system-application-connection-pooling-and-postgresql-case-ldap

However, I always wished (since my first endeavors with pgbouncer) it was less complicated.
>
> Yours,
> Laurenz Albe


--
Achilleas Mantzios
IT DEV Lead
IT DEPT
Dynacom Tankers Mgmt





-- 
Achilleas Mantzios
IT DEV Lead
IT DEPT
Dynacom Tankers Mgmt


--
Regards,
Ayub


--
Regards,
Ayub


-- 
Achilleas Mantzios
IT DEV Lead
IT DEPT
Dynacom Tankers Mgmt
--------------CEB6CE5EEFDDD9467FAA16E8--