Re: worried about PGPASSWORD drop

Lists: pgsql-generalpgsql-patches
From: Christoph Dalitz <christoph(dot)dalitz(at)hs-niederrhein(dot)de>
To: PG Mailing List <pgsql-general(at)postgresql(dot)org>
Subject: worried about PGPASSWORD drop
Date: 2002-08-28 13:35:52
Message-ID: 20020828153552.2a1b1cc3.christoph.dalitz@hs-niederrhein.de
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-general pgsql-patches

In the TODO list on http://developer.postgresql.org/todo.php,
I found the following entry:

- Remove PGPASSWORD because it is insecure on some OS's, in 7.4

Why?

I see the following problems:
- This will make psql no longer usable in scripts as PGPASSWORD is
currently the *only* way to pass a password to psql
- The alternative (a new command line option for password) is much more insecure,
as then the password is readable by everybody from the process table

In case PGPASSWORD is dropped, there should be a working way to use psql
in scripts. Maybe you could manage to make the following code work:

psql -U user dbname <<EOF
password
/* SQL-Statements */
EOF

(For some strange reason this works with Oracle's sqlplus, but not with psql)

Christoph Dalitz


From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Christoph Dalitz <christoph(dot)dalitz(at)hs-niederrhein(dot)de>
Cc: PG Mailing List <pgsql-general(at)postgresql(dot)org>
Subject: Re: worried about PGPASSWORD drop
Date: 2002-08-28 13:46:44
Message-ID: 20748.1030542404@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-general pgsql-patches

Christoph Dalitz <christoph(dot)dalitz(at)hs-niederrhein(dot)de> writes:
> In the TODO list on http://developer.postgresql.org/todo.php,
> I found the following entry:
> - Remove PGPASSWORD because it is insecure on some OS's, in 7.4
> Why?

I don't agree with removing the feature either, since it's perfectly
useful on many OSes. However your assumption:

> - The alternative (a new command line option for password)

is completely wrong; that is not the alternative being introduced.
See http://candle.pha.pa.us/main/writings/pgsql/sgml/libpq-envars.html

regards, tom lane


From: Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)us>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Christoph Dalitz <christoph(dot)dalitz(at)hs-niederrhein(dot)de>, PG Mailing List <pgsql-general(at)postgresql(dot)org>
Subject: Re: worried about PGPASSWORD drop
Date: 2002-08-28 13:54:56
Message-ID: 200208281354.g7SDsu413639@candle.pha.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-general pgsql-patches

Tom Lane wrote:
> Christoph Dalitz <christoph(dot)dalitz(at)hs-niederrhein(dot)de> writes:
> > In the TODO list on http://developer.postgresql.org/todo.php,
> > I found the following entry:
> > - Remove PGPASSWORD because it is insecure on some OS's, in 7.4
> > Why?
>
> I don't agree with removing the feature either, since it's perfectly
> useful on many OSes. However your assumption:

The reason for the suggested removal is that we don't have a way of
knowing with OS's are secure, and which are not. If we could determine
which OS's were secure, and enable it only on those, it would be OK to
keep it.

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


From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)us>
Cc: Christoph Dalitz <christoph(dot)dalitz(at)hs-niederrhein(dot)de>, PG Mailing List <pgsql-general(at)postgresql(dot)org>
Subject: Re: worried about PGPASSWORD drop
Date: 2002-08-28 14:01:21
Message-ID: 20895.1030543281@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-general pgsql-patches

Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)us> writes:
> The reason for the suggested removal is that we don't have a way of
> knowing with OS's are secure, and which are not. If we could determine
> which OS's were secure, and enable it only on those, it would be OK to
> keep it.

It is not our job to dictate security policy to users. Even on a
platform where environment variables are insecure, the user might be
willing to use PGPASSWORD. For example, suppose it's a laptop with
only one user, connecting via psql to a remote server that demands
passwords. PGPASSWORD could be a perfectly convenient and safe
solution.

We should deprecate it, explain exactly why it's deprecated (which the
current docs fail to do), and leave it up to the user to decide whether
it's safe to use in his context.

If you want to put in security restrictions that are actually useful,
where is the code to verify that PGPASSWORDFILE points at a
non-world-readable file? That needs to be there now, not later, or
we'll have people moaning about backward compatibility when we finally
do plug that hole.

regards, tom lane


From: Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)us>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Christoph Dalitz <christoph(dot)dalitz(at)hs-niederrhein(dot)de>, PG Mailing List <pgsql-general(at)postgresql(dot)org>
Subject: Re: worried about PGPASSWORD drop
Date: 2002-08-28 14:13:12
Message-ID: 200208281413.g7SEDCL14546@candle.pha.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-general pgsql-patches

Tom Lane wrote:
> It is not our job to dictate security policy to users. Even on a
> platform where environment variables are insecure, the user might be
> willing to use PGPASSWORD. For example, suppose it's a laptop with
> only one user, connecting via psql to a remote server that demands
> passwords. PGPASSWORD could be a perfectly convenient and safe
> solution.

Good point.

> We should deprecate it, explain exactly why it's deprecated (which the
> current docs fail to do), and leave it up to the user to decide whether
> it's safe to use in his context.
>
> If you want to put in security restrictions that are actually useful,
> where is the code to verify that PGPASSWORDFILE points at a
> non-world-readable file? That needs to be there now, not later, or
> we'll have people moaning about backward compatibility when we finally
> do plug that hole.

Agreed.

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


From: Alvaro Herrera <alvherre(at)atentus(dot)com>
To: Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)us>
Cc: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Christoph Dalitz <christoph(dot)dalitz(at)hs-niederrhein(dot)de>, PG Mailing List <pgsql-general(at)postgresql(dot)org>
Subject: Re: worried about PGPASSWORD drop
Date: 2002-08-28 16:02:22
Message-ID: Pine.LNX.4.44.0208281201560.2175-100000@cm-lcon1-46-187.cm.vtr.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-general pgsql-patches

Bruce Momjian dijo:

> Tom Lane wrote:

> > If you want to put in security restrictions that are actually useful,
> > where is the code to verify that PGPASSWORDFILE points at a
> > non-world-readable file? That needs to be there now, not later, or
> > we'll have people moaning about backward compatibility when we finally
> > do plug that hole.
>
> Agreed.

Point taken, will look into it later.

--
Alvaro Herrera (<alvherre[a]atentus.com>)
"La realidad se compone de muchos sueños, todos ellos diferentes,
pero en cierto aspecto, parecidos..." (Yo, hablando de sueños eróticos)


From: Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)us>
To: Alvaro Herrera <alvherre(at)atentus(dot)com>
Cc: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Christoph Dalitz <christoph(dot)dalitz(at)hs-niederrhein(dot)de>, PG Mailing List <pgsql-general(at)postgresql(dot)org>
Subject: Re: worried about PGPASSWORD drop
Date: 2002-08-28 21:33:34
Message-ID: 200208282133.g7SLXYY12462@candle.pha.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-general pgsql-patches

Alvaro Herrera wrote:
> Bruce Momjian dijo:
>
> > Tom Lane wrote:
>
> > > If you want to put in security restrictions that are actually useful,
> > > where is the code to verify that PGPASSWORDFILE points at a
> > > non-world-readable file? That needs to be there now, not later, or
> > > we'll have people moaning about backward compatibility when we finally
> > > do plug that hole.
> >
> > Agreed.
>
> Point taken, will look into it later.

Here is some code from postmaster.c that may help:

if (stat(checkdir, &stat_buf) == -1)
{
if (errno == ENOENT)
elog(FATAL, "data directory %s was not found", checkdir);
else
elog(FATAL, "could not read permissions of directory %s: %m",
checkdir);
}

if (stat_buf.st_mode & (S_IRWXG | S_IRWXO))
elog(FATAL, "data directory %s has group or world access; permissions should be u=rwx (0700)",
checkdir);

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


From: Alvaro Herrera <alvherre(at)atentus(dot)com>
To: Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)us>
Cc: pgsql-patches(at)postgresql(dot)org
Subject: Re: [GENERAL] worried about PGPASSWORD drop
Date: 2002-08-29 02:05:55
Message-ID: 20020828220555.328b9352.alvherre@atentus.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-general pgsql-patches

En Wed, 28 Aug 2002 17:33:34 -0400 (EDT)
Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)us> escribió:

> Alvaro Herrera wrote:
> > Bruce Momjian dijo:
> >
> > > Tom Lane wrote:
> >
> > > > If you want to put in security restrictions that are actually useful,
> > > > where is the code to verify that PGPASSWORDFILE points at a
> > > > non-world-readable file? That needs to be there now, not later, or
> > > > we'll have people moaning about backward compatibility when we finally
> > > > do plug that hole.
> > >
> > > Agreed.
> >
> > Point taken, will look into it later.
>
> Here is some code from postmaster.c that may help:

Thank you. Patch attached. Note that it also checks group access; I think
that is desired as well.

--
Alvaro Herrera (<alvherre[a]atentus.com>)
"Cuando mañana llegue pelearemos segun lo que mañana exija" (Mowgli)

Attachment Content-Type Size
libpq-perm.patch application/octet-stream 1.4 KB

From: Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)us>
To: Alvaro Herrera <alvherre(at)atentus(dot)com>
Cc: pgsql-patches(at)postgresql(dot)org
Subject: Re: [GENERAL] worried about PGPASSWORD drop
Date: 2002-08-29 18:33:54
Message-ID: 200208291833.g7TIXsh13979@candle.pha.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-general pgsql-patches


Your patch has been added to the PostgreSQL unapplied patches list at:

http://candle.pha.pa.us/cgi-bin/pgpatches

I will try to apply it within the next 48 hours.

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

Alvaro Herrera wrote:
> En Wed, 28 Aug 2002 17:33:34 -0400 (EDT)
> Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)us> escribi?:
>
> > Alvaro Herrera wrote:
> > > Bruce Momjian dijo:
> > >
> > > > Tom Lane wrote:
> > >
> > > > > If you want to put in security restrictions that are actually useful,
> > > > > where is the code to verify that PGPASSWORDFILE points at a
> > > > > non-world-readable file? That needs to be there now, not later, or
> > > > > we'll have people moaning about backward compatibility when we finally
> > > > > do plug that hole.
> > > >
> > > > Agreed.
> > >
> > > Point taken, will look into it later.
> >
> > Here is some code from postmaster.c that may help:
>
> Thank you. Patch attached. Note that it also checks group access; I think
> that is desired as well.
>
> --
> Alvaro Herrera (<alvherre[a]atentus.com>)
> "Cuando ma?ana llegue pelearemos segun lo que ma?ana exija" (Mowgli)

[ Attachment, skipping... ]

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


From: "Nigel J(dot) Andrews" <nandrews(at)investsystems(dot)co(dot)uk>
To: Alvaro Herrera <alvherre(at)atentus(dot)com>
Cc: pgsql-patches(at)postgresql(dot)org
Subject: Re: [GENERAL] worried about PGPASSWORD drop
Date: 2002-08-29 21:01:55
Message-ID: Pine.LNX.4.21.0208292157240.667-100000@ponder.fairway2k.co.uk
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-general pgsql-patches

On Wed, 28 Aug 2002, Alvaro Herrera wrote:

> En Wed, 28 Aug 2002 17:33:34 -0400 (EDT)
>
> Thank you. Patch attached. Note that it also checks group access; I think
> that is desired as well.

+
+ /* If password file is insecure, alert the user and ignore it. */
+ if (stat_buf.st_mode & (S_IRWXG | S_IRWXO))

Should there also be a S_IFREG check to make sure no one is trying any other
tricks? I'm not sure of what an exploit would be but for the sake of paranoia
it seems a cheap test.

I take it no one wants to start checking directory tree permissions etc.

--
Nigel J. Andrews
Director

---
Logictree Systems Limited
Computer Consultants


From: Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)us>
To: "Nigel J(dot) Andrews" <nandrews(at)investsystems(dot)co(dot)uk>
Cc: Alvaro Herrera <alvherre(at)atentus(dot)com>, pgsql-patches(at)postgresql(dot)org
Subject: Re: [GENERAL] worried about PGPASSWORD drop
Date: 2002-08-29 21:42:27
Message-ID: 200208292142.g7TLgRd23655@candle.pha.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-general pgsql-patches

Nigel J. Andrews wrote:
> On Wed, 28 Aug 2002, Alvaro Herrera wrote:
>
> > En Wed, 28 Aug 2002 17:33:34 -0400 (EDT)
> >
> > Thank you. Patch attached. Note that it also checks group access; I think
> > that is desired as well.
>
> +
> + /* If password file is insecure, alert the user and ignore it. */
> + if (stat_buf.st_mode & (S_IRWXG | S_IRWXO))
>
>
> Should there also be a S_IFREG check to make sure no one is trying any other
> tricks? I'm not sure of what an exploit would be but for the sake of paranoia
> it seems a cheap test.
>
> I take it no one wants to start checking directory tree permissions etc.

They may want a symlink to point to somewhere else. I can see that. In
fact, I can see settings for Unix group sharing a password file but I am
not going to suggest loosening the group permissions until someone says
they want that.

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


From: "Nigel J(dot) Andrews" <nandrews(at)investsystems(dot)co(dot)uk>
To: Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)us>
Cc: Alvaro Herrera <alvherre(at)atentus(dot)com>, pgsql-patches(at)postgresql(dot)org
Subject: Re: [GENERAL] worried about PGPASSWORD drop
Date: 2002-08-29 22:06:15
Message-ID: Pine.LNX.4.21.0208292300310.667-100000@ponder.fairway2k.co.uk
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-general pgsql-patches

On Thu, 29 Aug 2002, Bruce Momjian wrote:

> Nigel J. Andrews wrote:
> > On Wed, 28 Aug 2002, Alvaro Herrera wrote:
> >
> > > En Wed, 28 Aug 2002 17:33:34 -0400 (EDT)
> > >
> > > Thank you. Patch attached. Note that it also checks group access; I think
> > > that is desired as well.
> >
> > +
> > + /* If password file is insecure, alert the user and ignore it. */
> > + if (stat_buf.st_mode & (S_IRWXG | S_IRWXO))
> >
> >
> > Should there also be a S_IFREG check to make sure no one is trying any other
> > tricks? I'm not sure of what an exploit would be but for the sake of paranoia
> > it seems a cheap test.
> >
> > I take it no one wants to start checking directory tree permissions etc.
>
> They may want a symlink to point to somewhere else. I can see that. In
> fact, I can see settings for Unix group sharing a password file but I am
> not going to suggest loosening the group permissions until someone says
> they want that.

Doesn't stat() resolve all symlinks?

I must admit it's not something I've check but I thought it went through until
it found a non symlink.

I'm probably just being too paranoid about pipes etc. though.

I'd wait and see about the group permissions as well. I can't really see the
need myself. I'm not very imaginative at times though. May be in a teaching
environment.

--
Nigel J. Andrews


From: Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)us>
To: Alvaro Herrera <alvherre(at)atentus(dot)com>
Cc: pgsql-patches(at)postgresql(dot)org
Subject: Re: [GENERAL] worried about PGPASSWORD drop
Date: 2002-08-29 23:06:35
Message-ID: 200208292306.g7TN6ZG08318@candle.pha.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-general pgsql-patches


Patch applied. Thanks.

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

Alvaro Herrera wrote:
> En Wed, 28 Aug 2002 17:33:34 -0400 (EDT)
> Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)us> escribi?:
>
> > Alvaro Herrera wrote:
> > > Bruce Momjian dijo:
> > >
> > > > Tom Lane wrote:
> > >
> > > > > If you want to put in security restrictions that are actually useful,
> > > > > where is the code to verify that PGPASSWORDFILE points at a
> > > > > non-world-readable file? That needs to be there now, not later, or
> > > > > we'll have people moaning about backward compatibility when we finally
> > > > > do plug that hole.
> > > >
> > > > Agreed.
> > >
> > > Point taken, will look into it later.
> >
> > Here is some code from postmaster.c that may help:
>
> Thank you. Patch attached. Note that it also checks group access; I think
> that is desired as well.
>
> --
> Alvaro Herrera (<alvherre[a]atentus.com>)
> "Cuando ma?ana llegue pelearemos segun lo que ma?ana exija" (Mowgli)

[ Attachment, skipping... ]

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


From: Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)us>
To: "Nigel J(dot) Andrews" <nandrews(at)investsystems(dot)co(dot)uk>
Cc: Alvaro Herrera <alvherre(at)atentus(dot)com>, pgsql-patches(at)postgresql(dot)org
Subject: Re: [GENERAL] worried about PGPASSWORD drop
Date: 2002-08-29 23:36:34
Message-ID: 200208292336.g7TNaYI08818@candle.pha.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-general pgsql-patches

Nigel J. Andrews wrote:
> > They may want a symlink to point to somewhere else. I can see that. In
> > fact, I can see settings for Unix group sharing a password file but I am
> > not going to suggest loosening the group permissions until someone says
> > they want that.
>
> Doesn't stat() resolve all symlinks?

Yep, only lstat() sees symlinks.

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