pg.ddx.io  pgsql-admin@postgresql.org mailing list archive  
help / color / mirror / Atom feed
PAM
7+ messages / 6 participants
[nested] [flat]

* PAM
@ 2000-11-20 07:17  Jacopo Silva <jsilva@lynxtesoft.it>
  0 siblings, 0 replies; 7+ messages in thread

From: Jacopo Silva @ 2000-11-20 07:17 UTC (permalink / raw)
  To: pgsql-admin

Does anyone know of a PAM module that let you
authenticate vs a pgsql table with e.g. 
username/password fields ?

There is something similar for mysql but
I would rather use my pgsql ...

Jacopo S.






^ permalink  raw  reply  [nested|flat] 7+ messages in thread

* PAM
@ 2002-12-04 01:59  EMOTO Masahiko <emo@nifs.ac.jp>
  0 siblings, 1 reply; 7+ messages in thread

From: EMOTO Masahiko @ 2002-12-04 01:59 UTC (permalink / raw)
  To: pgsql-admin


Does anyone show me a sample of PAM authenticate file?

I want to use pam for client authentication, and I create pg_hba.cnf as,

>host    all         all         127.0.0.1         255.255.255.255   trust
>host    all         all         192.168.0.0        255.255.0.0   pam postgresql

and /etc/pam.d/postgresql as
>auth       required     /lib/security/pam_stack.so service=system-auth
>account    required     /lib/security/pam_stack.so service=system-auth

I tried to connect to the server, but failed. The messages I received were follows;

>[CLIENT]
>% psql -h dgpc1 db1 -U emo
>Password:
>psql: FATAL:  PAM authentication failed for user "emo"
>
>[SERVER]
>DEBUG:  reaping dead processes
>DEBUG:  child process (pid 15642) exited with exit code 0
>DEBUG:  BackendStartup: forked pid=15643 socket=8
>DEBUG:  received PAM packet
>LOG:  CheckPAMAuth: pam_authenticate failed: 'Authentication failure'
>FATAL:  PAM authentication failed for user "emo"
>DEBUG:  proc_exit(0)
>DEBUG:  shmem_exit(0)
>DEBUG:  exit(0)
>DEBUG:  reaping dead processes

The user account exists in the database, and I typed the system password.


Environment:
OS : Linux Kernel 2.4.19
PostgreSQL 7.3


By the way, what really I want to do is to configure the server behave like FTP servers;
All the users except the guest (anonymous) requires the password authentication.
The guest user can only read the data, and cannot alter the data.
Are there any solutions to do this?


                                                        --- EMOTO Masahiko ---



^ permalink  raw  reply  [nested|flat] 7+ messages in thread

* Re: PAM
@ 2002-12-05 14:01  Tim Frank <tfrank@registrar.uoguelph.ca>
  parent: EMOTO Masahiko <emo@nifs.ac.jp>
  0 siblings, 2 replies; 7+ messages in thread

From: Tim Frank @ 2002-12-05 14:01 UTC (permalink / raw)
  To: pgsql-admin

I was testing this on a 7.3 beta the other week to try to make it work 
with LDAP authentication, and I think I only got it working if I bypased 
the system-auth PAM file that everything was normally funneled through. 
  I don't know exactly why it wasn't working, but whenever I put a line 
that used pam_unix.so it would fail with the same error you are 
encountering.

I didn't invest a huge amount of time figuring out why pam_unix.so was 
causing a problem because I wanted to use pam_ldap.so anyways.

There doesn't seem to be many examples out there that I could find that 
I got to work.  FYI I am testing on RedHat 7.x and 8.0 machines.

Tim

EMOTO Masahiko wrote:
> Does anyone show me a sample of PAM authenticate file?
> 
> I want to use pam for client authentication, and I create pg_hba.cnf as,
> 
> 
>>host    all         all         127.0.0.1         255.255.255.255   trust
>>host    all         all         192.168.0.0        255.255.0.0   pam postgresql
> 
> 
> and /etc/pam.d/postgresql as
> 
>>auth       required     /lib/security/pam_stack.so service=system-auth
>>account    required     /lib/security/pam_stack.so service=system-auth
> 
> 
> I tried to connect to the server, but failed. The messages I received were follows;
> 
> 
>>[CLIENT]
>>% psql -h dgpc1 db1 -U emo
>>Password:
>>psql: FATAL:  PAM authentication failed for user "emo"
>>
>>[SERVER]
>>DEBUG:  reaping dead processes
>>DEBUG:  child process (pid 15642) exited with exit code 0
>>DEBUG:  BackendStartup: forked pid=15643 socket=8
>>DEBUG:  received PAM packet
>>LOG:  CheckPAMAuth: pam_authenticate failed: 'Authentication failure'
>>FATAL:  PAM authentication failed for user "emo"
>>DEBUG:  proc_exit(0)
>>DEBUG:  shmem_exit(0)
>>DEBUG:  exit(0)
>>DEBUG:  reaping dead processes
> 
> 
> The user account exists in the database, and I typed the system password.
> 
> 
> Environment:
> OS : Linux Kernel 2.4.19
> PostgreSQL 7.3
> 
> 
> By the way, what really I want to do is to configure the server behave like FTP servers;
> All the users except the guest (anonymous) requires the password authentication.
> The guest user can only read the data, and cannot alter the data.
> Are there any solutions to do this?
> 
> 
>                                                         --- EMOTO Masahiko ---
> 
> ---------------------------(end of broadcast)---------------------------
> TIP 1: subscribe and unsubscribe commands go to majordomo@postgresql.org




^ permalink  raw  reply  [nested|flat] 7+ messages in thread

* Re: [ADMIN] PAM
@ 2002-12-05 19:23  Bruce Momjian <pgman@candle.pha.pa.us>
  parent: Tim Frank <tfrank@registrar.uoguelph.ca>
  1 sibling, 0 replies; 7+ messages in thread

From: Bruce Momjian @ 2002-12-05 19:23 UTC (permalink / raw)
  To: Tim Frank <tfrank@registrar.uoguelph.ca>; +Cc: PostgreSQL-patches <pgsql-patches@postgresql.org>


I am not sure, but it is possible you are seeing a problem with the new
storage of passwords as MD5 encrypted on pg_shadow.  The attached patch
fixes this.

---------------------------------------------------------------------------

Tim Frank wrote:
> I was testing this on a 7.3 beta the other week to try to make it work 
> with LDAP authentication, and I think I only got it working if I bypased 
> the system-auth PAM file that everything was normally funneled through. 
>   I don't know exactly why it wasn't working, but whenever I put a line 
> that used pam_unix.so it would fail with the same error you are 
> encountering.
> 
> I didn't invest a huge amount of time figuring out why pam_unix.so was 
> causing a problem because I wanted to use pam_ldap.so anyways.
> 
> There doesn't seem to be many examples out there that I could find that 
> I got to work.  FYI I am testing on RedHat 7.x and 8.0 machines.
> 
> Tim
> 
> EMOTO Masahiko wrote:
> > Does anyone show me a sample of PAM authenticate file?
> > 
> > I want to use pam for client authentication, and I create pg_hba.cnf as,
> > 
> > 
> >>host    all         all         127.0.0.1         255.255.255.255   trust
> >>host    all         all         192.168.0.0        255.255.0.0   pam postgresql
> > 
> > 
> > and /etc/pam.d/postgresql as
> > 
> >>auth       required     /lib/security/pam_stack.so service=system-auth
> >>account    required     /lib/security/pam_stack.so service=system-auth
> > 
> > 
> > I tried to connect to the server, but failed. The messages I received were follows;
> > 
> > 
> >>[CLIENT]
> >>% psql -h dgpc1 db1 -U emo
> >>Password:
> >>psql: FATAL:  PAM authentication failed for user "emo"
> >>
> >>[SERVER]
> >>DEBUG:  reaping dead processes
> >>DEBUG:  child process (pid 15642) exited with exit code 0
> >>DEBUG:  BackendStartup: forked pid=15643 socket=8
> >>DEBUG:  received PAM packet
> >>LOG:  CheckPAMAuth: pam_authenticate failed: 'Authentication failure'
> >>FATAL:  PAM authentication failed for user "emo"
> >>DEBUG:  proc_exit(0)
> >>DEBUG:  shmem_exit(0)
> >>DEBUG:  exit(0)
> >>DEBUG:  reaping dead processes
> > 
> > 
> > The user account exists in the database, and I typed the system password.
> > 
> > 
> > Environment:
> > OS : Linux Kernel 2.4.19
> > PostgreSQL 7.3
> > 
> > 
> > By the way, what really I want to do is to configure the server behave like FTP servers;
> > All the users except the guest (anonymous) requires the password authentication.
> > The guest user can only read the data, and cannot alter the data.
> > Are there any solutions to do this?
> > 
> > 
> >                                                         --- EMOTO Masahiko ---
> > 
> > ---------------------------(end of broadcast)---------------------------
> > TIP 1: subscribe and unsubscribe commands go to majordomo@postgresql.org
> 
> 
> ---------------------------(end of broadcast)---------------------------
> TIP 3: if posting/reading through Usenet, please send an appropriate
> subscribe-nomail command to majordomo@postgresql.org so that your
> message can get through to the mailing list cleanly
> 

-- 
  Bruce Momjian                        |  http://candle.pha.pa.us
  pgman@candle.pha.pa.us               |  (610) 359-1001
  +  If your life is a hard drive,     |  13 Roberts Road
  +  Christ can be your backup.        |  Newtown Square, Pennsylvania 19073

Attachments:

/pgpatches/pass (text/plain, 3.8K) download Index: src/backend/libpq/crypt.c =================================================================== RCS file: /cvsroot/pgsql-server/src/backend/libpq/crypt.c,v retrieving revision 1.49 diff -c -c -r1.49 crypt.c *** src/backend/libpq/crypt.c 4 Sep 2002 20:31:19 -0000 1.49 --- src/backend/libpq/crypt.c 5 Dec 2002 18:03:53 -0000 *************** *** 29,35 **** int ! md5_crypt_verify(const Port *port, const char *user, const char *pgpass) { char *passwd = NULL, *valuntil = NULL, --- 29,35 ---- int ! md5_crypt_verify(const Port *port, const char *user, char *pgpass) { char *passwd = NULL, *valuntil = NULL, *************** *** 37,42 **** --- 37,43 ---- int retval = STATUS_ERROR; List **line; List *token; + char *crypt_pgpass = pgpass; if ((line = get_user_line(user)) == NULL) return STATUS_ERROR; *************** *** 54,64 **** if (passwd == NULL || *passwd == '\0') return STATUS_ERROR; ! /* If they encrypt their password, force MD5 */ ! if (isMD5(passwd) && port->auth_method != uaMD5) { elog(LOG, "Password is stored MD5 encrypted. " ! "'password' and 'crypt' auth methods cannot be used."); return STATUS_ERROR; } --- 55,65 ---- if (passwd == NULL || *passwd == '\0') return STATUS_ERROR; ! /* We can't do crypt with pg_shadow MD5 passwords */ ! if (isMD5(passwd) && port->auth_method == uaCrypt) { elog(LOG, "Password is stored MD5 encrypted. " ! "'crypt' auth method cannot be used."); return STATUS_ERROR; } *************** *** 72,77 **** --- 73,79 ---- crypt_pwd = palloc(MD5_PASSWD_LEN + 1); if (isMD5(passwd)) { + /* pg_shadow already encrypted, only do salt */ if (!EncryptMD5(passwd + strlen("md5"), (char *) port->md5Salt, sizeof(port->md5Salt), crypt_pwd)) *************** *** 82,87 **** --- 84,90 ---- } else { + /* pg_shadow plain, double-encrypt */ char *crypt_pwd2 = palloc(MD5_PASSWD_LEN + 1); if (!EncryptMD5(passwd, port->user, strlen(port->user), *************** *** 110,120 **** break; } default: crypt_pwd = passwd; break; } ! if (strcmp(pgpass, crypt_pwd) == 0) { /* * Password OK, now check to be sure we are not past valuntil --- 113,134 ---- break; } default: + if (isMD5(passwd)) + { + /* Encrypt user-supplied password to match MD5 in pg_shadow */ + crypt_pgpass = palloc(MD5_PASSWD_LEN + 1); + if (!EncryptMD5(pgpass, port->user, strlen(port->user), + crypt_pgpass)) + { + pfree(crypt_pgpass); + return STATUS_ERROR; + } + } crypt_pwd = passwd; break; } ! if (strcmp(crypt_pgpass, crypt_pwd) == 0) { /* * Password OK, now check to be sure we are not past valuntil *************** *** 136,141 **** --- 150,157 ---- if (port->auth_method == uaMD5) pfree(crypt_pwd); + if (crypt_pgpass != pgpass) + pfree(crypt_pgpass); return retval; } Index: src/include/libpq/crypt.h =================================================================== RCS file: /cvsroot/pgsql-server/src/include/libpq/crypt.h,v retrieving revision 1.22 diff -c -c -r1.22 crypt.h *** src/include/libpq/crypt.h 4 Sep 2002 20:31:42 -0000 1.22 --- src/include/libpq/crypt.h 5 Dec 2002 18:03:54 -0000 *************** *** 23,29 **** extern int md5_crypt_verify(const Port *port, const char *user, ! const char *pgpass); extern bool md5_hash(const void *buff, size_t len, char *hexsum); extern bool CheckMD5Pwd(char *passwd, char *storedpwd, char *seed); --- 23,29 ---- extern int md5_crypt_verify(const Port *port, const char *user, ! char *pgpass); extern bool md5_hash(const void *buff, size_t len, char *hexsum); extern bool CheckMD5Pwd(char *passwd, char *storedpwd, char *seed);
^ permalink raw reply [nested|flat] 7+ messages in thread

* Re: PAM
@ 2002-12-06 18:38  Tim Frank <tfrank@registrar.uoguelph.ca>
  parent: Tim Frank <tfrank@registrar.uoguelph.ca>
  1 sibling, 0 replies; 7+ messages in thread

From: Tim Frank @ 2002-12-06 18:38 UTC (permalink / raw)
  To: pgsql-admin

Here is a bit of a follow up to the PAM setup.  If you want to 
authenticate against an LDAP source then creatinga /etc/pam.d/postgresql 
file containing the following:

auth        required    /lib/security/pam_ldap.so
account     required    /lib/security/pam_ldap.so

This works fine and I love the feature :) The problem I am having is if 
I try to use pam_unix.so. If I set it up similarly,

auth        required    /lib/security/pam_unix.so
account     required    /lib/security/pam_unix.so

I get a bunch of errors from the system and postgres.  System errors are 
always of the form,

postgresql(pam_unix)[28219]: auth could not identify password for [myuser]
postgresql(pam_unix)[28220]: authentication failure; logname= uid=40 
euid=40 tty= ruser= rhost=  user=myuser

And the postgres logs show,

DEBUG:  BackendStartup: forked pid=28290 socket=8
LOG:  CheckPAMAuth: pam_authenticate failed: 'Conversation error'
FATAL:  PAM authentication failed for user "myuser"
DEBUG:  proc_exit(0)
DEBUG:  shmem_exit(0)
DEBUG:  exit(0)
DEBUG:  reaping dead processes
DEBUG:  child process (pid 28290) exited with exit code 0
DEBUG:  BackendStartup: forked pid=28291 socket=8
DEBUG:  received PAM packet
LOG:  CheckPAMAuth: pam_authenticate failed: 'Authentication failure'
FATAL:  PAM authentication failed for user "myuser"
DEBUG:  proc_exit(0)
DEBUG:  shmem_exit(0)
DEBUG:  exit(0)
DEBUG:  reaping dead processes
DEBUG:  child process (pid 28291) exited with exit code 0



If I try the same thing, but logging in as the "postgres" user rather 
than a normal user I get the following in the system logs,

postgresql(pam_unix)[28284]: auth could not identify password for [postgres]

and this in the postgres logs,

DEBUG:  BackendStartup: forked pid=28284 socket=8
LOG:  CheckPAMAuth: pam_authenticate failed: 'Conversation error'
FATAL:  PAM authentication failed for user "postgres"
DEBUG:  proc_exit(0)
DEBUG:  shmem_exit(0)
DEBUG:  exit(0)
DEBUG:  reaping dead processes
DEBUG:  child process (pid 28284) exited with exit code 0
DEBUG:  BackendStartup: forked pid=28285 socket=8
DEBUG:  received PAM packet
LOG:  CheckPAMAuth: pam_acct_mgmt failed: 'Authentication failure 
service cannot retrieve authentication info.'
FATAL:  PAM authentication failed for user "postgres"
DEBUG:  proc_exit(0)
DEBUG:  shmem_exit(0)
DEBUG:  exit(0)
DEBUG:  reaping dead processes
DEBUG:  child process (pid 28285) exited with exit code 0


Now, the good news is that if I modify the PAM configuration as follows,

auth        required    /lib/security/pam_unix.so
account     required    /lib/security/pam_permit.so

I can at least log in as the postgres user.  I still can't log in as a 
regular system user.  I think there is something to do with PAM not 
liking a system uid=40 for any user except the postgres user, but I 
really don't have any hard proof to base that on.  Even when the 
postgres user successfully logs in I still get "errors" in the system logs,

postgresql(pam_unix)[28315]: auth could not identify password for [postgres]

and "errors" in the postgres logs,

DEBUG:  BackendStartup: forked pid=28315 socket=8
LOG:  CheckPAMAuth: pam_authenticate failed: 'Conversation error'
FATAL:  PAM authentication failed for user "postgres"
DEBUG:  proc_exit(0)
DEBUG:  shmem_exit(0)
DEBUG:  exit(0)
DEBUG:  reaping dead processes
DEBUG:  child process (pid 28315) exited with exit code 0
DEBUG:  BackendStartup: forked pid=28316 socket=8
DEBUG:  received PAM packet
DEBUG:  /usr/local/pgsql73/bin/postmaster child[28316]: starting with (
DEBUG:          postgres
DEBUG:          -v131072
DEBUG:          -p
DEBUG:          test
DEBUG:  )
DEBUG:  InitPostgres
[ rest of successful connection messages ]

I am not a PAM expert, but this is the furthest I could get the 
pam_unix.so working.  I don't really need the functionality, but it 
would be nice to be able to funnel postgres PAM functionality through 
the system-auth stack on my RedHat systems, which has components for 
pam_unix.so instead of creating another authentication stream.

I did apply a crypt patch that Bruce sent me, so I can't comment if this 
work exactly the same way on the official 7.3 release.  I do know I had 
the same issues on the 7.3beta5 release.

Sorry for the long post, hopefully this will be of use to someone with 
some better knowledge of postgres authentication and PAM.

Tim Frank




^ permalink  raw  reply  [nested|flat] 7+ messages in thread

* pam
@ 2005-01-12 16:16  Kavan, Dan (IMS) <KavanD@imsweb.com>
  0 siblings, 1 reply; 7+ messages in thread

From: Kavan, Dan (IMS) @ 2005-01-12 16:16 UTC (permalink / raw)
  To: pgsql-admin

      Hi,

I configured Postgres with PAM.  I was wondering how to implement this.
Does this mean I will still need to create individual users on the
database or can I assign users rights from a LDAP server?  
    D.J. Kavan
    




^ permalink  raw  reply  [nested|flat] 7+ messages in thread

* Re: pam
@ 2005-01-14 13:59  Dick Davies <rasputnik@hellooperator.net>
  parent: Kavan, Dan (IMS) <KavanD@imsweb.com>
  0 siblings, 0 replies; 7+ messages in thread

From: Dick Davies @ 2005-01-14 13:59 UTC (permalink / raw)
  To: pgsql-admin

* Kavan, Dan (IMS) <KavanD@imsweb.com> [0122 05:22]:
>       Hi,
> 
> I configured Postgres with PAM.  I was wondering how to implement this.
> Does this mean I will still need to create individual users on the
> database or can I assign users rights from a LDAP server?  

in my experience, you still need to 'create user foo', you just don't need the
passwords.

-- 
'Oh how awful. Did he at least die peacefully? ....To shreds you say, tsk tsk tsk.
Well, how's his wife holding up? ....To shreds, you say...'
		-- Prof. Farnsworth
Rasputin :: Jack of All Trades - Master of Nuns



^ permalink  raw  reply  [nested|flat] 7+ messages in thread


end of thread, other threads:[~2005-01-14 13:59 UTC | newest]

Thread overview: 7+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2000-11-20 07:17 PAM Jacopo Silva <jsilva@lynxtesoft.it>
2002-12-04 01:59 PAM EMOTO Masahiko <emo@nifs.ac.jp>
2002-12-05 14:01 ` Tim Frank <tfrank@registrar.uoguelph.ca>
2002-12-05 19:23   ` Bruce Momjian <pgman@candle.pha.pa.us>
2002-12-06 18:38   ` Tim Frank <tfrank@registrar.uoguelph.ca>
2005-01-12 16:16 pam Kavan, Dan (IMS) <KavanD@imsweb.com>
2005-01-14 13:59 ` Re: pam Dick Davies <rasputnik@hellooperator.net>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox