Re: How to make PostreSQL utilities honor home directories?

From: "Peter J(dot) Holzer" <hjp-pgsql(at)hjp(dot)at>
To: pgsql-general(at)lists(dot)postgresql(dot)org
Subject: Re: How to make PostreSQL utilities honor home directories?
Date: 2022-09-02 11:27:54
Message-ID: 20220902112754.2e7fnrclod73d2sh@hjp.at
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On 2022-09-01 21:10:44 -0700, Adrian Klaver wrote:
> On 9/1/22 6:31 PM, Jeffrey Walton wrote:
> > On Thu, Sep 1, 2022 at 8:51 PM Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:
> > > I concur with the other person asking why you want to sudo to postgres
> > > at all, though. It's generally safest if the client side isn't running
> > > as the same user as the server.
> >
> > The use case is an install of DefectDojo [2]. I _think_ they are
> > taking advantage of the fact that as root, you don't need to
> > authenticate because of postgresql's use of domain sockets. (Hat tip
> > for that, by the way). The installer code will install packages, setup
> > the database, install the DefectDojo programs, etc.
>
> You are not running as root(Postgres won't allow you do this anyway) you are
> running as postgres system user and the authentication is handled by
> pg_hba.conf. I'm also betting that if you look at pg_hba.conf it is set up
> to do peer authentication and hence the need to be postgres system user. You
> can obtain a similar result in pg_hba.conf with:
>
> TYPE DATABASE USER ADDRESS METHOD
> local all postgres trust
>
> Then you could eliminate the whole sudo dance.

OTOH it allows any user on the machine to connect as postgres, which may
or may not be a problem.

I like to use ident for local connections:

# TYPE DATABASE USER ADDRESS METHOD

# "local" is for Unix domain socket connections only
local all all ident map=localusers

and in pg_ident.conf:

# MAPNAME SYSTEM-USERNAME PG-USERNAME
localusers root postgres

Then root can invoke `psql -U postgres ...`, but other users can't.

hp

--
_ | Peter J. Holzer | Story must make more sense than reality.
|_|_) | |
| | | hjp(at)hjp(dot)at | -- Charles Stross, "Creative writing
__/ | http://www.hjp.at/ | challenge!"

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Peter J. Holzer 2022-09-02 11:34:38 Re: How to make PostreSQL utilities honor home directories?
Previous Message Peter J. Holzer 2022-09-02 11:16:25 Re: Missing query plan for auto_explain.