Re: Why pg_dump 'trust' authentication fails under root and works under another user?

Lists: pgsql-admin
From: Jaroslav Záruba <jaroslav(dot)zaruba(at)gmail(dot)com>
To: pgsql-admin(at)postgresql(dot)org
Subject: Why pg_dump 'trust' authentication fails under root and works under another user?
Date: 2011-03-24 07:34:28
Message-ID: AANLkTikR5sO5zYYRpNOTLUS+jUdrJKUT-vPTMgm4b88=@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-admin

Hello

I have pg_dump command in cron that accesses PostgreSQL under user postgres
and does not provide a password.

pg_dump --username=postgres ...

I have set in pg_hba.conf that user postgres should be trusted for all
databases from localhost.

local all postgres trust

When I run the command under regular user it works.
When I run it under root (sudo -i) it requires password, and therefore the
crontab task fails to authenticate.

(I'm looking at both users' 'export' command output, and there seems to be
nothing related to PostgreSQL.)

Could someone explain to me what is happening here?

Regards
J. Záruba


From: Simon <simon(at)apricotwebsolutions(dot)com>
To: Postgres Admin <pgsql-admin(at)postgresql(dot)org>
Subject: Re: Why pg_dump 'trust' authentication fails under root and works under another user?
Date: 2011-03-24 07:49:51
Message-ID: AANLkTi=8gD=oNWQhO7-Y9-iNzzOyuR0Ut6N+pqfpg=wc@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-admin

I don't know why postgres is prompting for a password. But you could try
putting the following in your crontab:

su postgres -c 'pg_dump ...'

Simon

2011/3/24 Jaroslav Záruba <jaroslav(dot)zaruba(at)gmail(dot)com>

> Hello
>
> I have pg_dump command in cron that accesses PostgreSQL under user postgres
> and does not provide a password.
>
> pg_dump --username=postgres ...
>
> I have set in pg_hba.conf that user postgres should be trusted for all
> databases from localhost.
>
> local all postgres trust
>
> When I run the command under regular user it works.
> When I run it under root (sudo -i) it requires password, and therefore the
> crontab task fails to authenticate.
>
> (I'm looking at both users' 'export' command output, and there seems to be
> nothing related to PostgreSQL.)
>
> Could someone explain to me what is happening here?
>
> Regards
> J. Záruba


From: Guillaume Lelarge <guillaume(at)lelarge(dot)info>
To: Jaroslav Záruba <jaroslav(dot)zaruba(at)gmail(dot)com>
Cc: pgsql-admin(at)postgresql(dot)org
Subject: Re: Why pg_dump 'trust' authentication fails under root and works under another user?
Date: 2011-03-24 08:03:07
Message-ID: 4D8AFABB.1010002@lelarge.info
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-admin

Le 24/03/2011 08:34, Jaroslav Záruba a écrit :
> Hello
>
> I have pg_dump command in cron that accesses PostgreSQL under user postgres
> and does not provide a password.
>
> pg_dump --username=postgres ...
>
> I have set in pg_hba.conf that user postgres should be trusted for all
> databases from localhost.
>
> local all postgres trust
>
> When I run the command under regular user it works.
> When I run it under root (sudo -i) it requires password, and therefore the
> crontab task fails to authenticate.
>

Are you sure the password is not asked by the sudo command, rather than
by the pg_dump one?

--
Guillaume
http://www.postgresql.fr
http://dalibo.com


From: Guillaume Lelarge <guillaume(at)lelarge(dot)info>
To: Jaroslav Záruba <jaroslav(dot)zaruba(at)gmail(dot)com>
Cc: PostgreSQL - mailing list <pgsql-admin(at)postgresql(dot)org>
Subject: Re: Why pg_dump 'trust' authentication fails under root and works under another user?
Date: 2011-03-24 08:56:56
Message-ID: 4D8B0758.8020707@lelarge.info
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-admin

Please, answer to the list.

Le 24/03/2011 09:13, Jaroslav Záruba a écrit :
> Yes, it is the password for PostgreSQL.
>
> pg_dump: [archiver (db)] connection to database "db123" failed: FATAL:
> password authentication failed for user "postgres"
> FATAL: password authentication failed for user "postgres"
>

The error message says the authentication method used isn't trust. Can
you tell us the complete content of your pg_hba.conf (without the
comments of course), and the exact command lines (the one that work and
the one that doesn't work).

--
Guillaume
http://www.postgresql.fr
http://dalibo.com


From: Jaroslav Záruba <jaroslav(dot)zaruba(at)gmail(dot)com>
To:
Cc: PostgreSQL - mailing list <pgsql-admin(at)postgresql(dot)org>
Subject: Re: Why pg_dump 'trust' authentication fails under root and works under another user?
Date: 2011-03-24 09:05:00
Message-ID: AANLkTi=VQQiODWtE7P8mWLiG6M5KswidQiMFZa+P8T=c@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-admin

My pg_hba.conf looks like this:

local all postgres trust
host all postgres 192.168.1.0/24 md5
local all all ident
host all all 127.0.0.1/32 md5
host all all ::1/128 md5

2011/3/24 Guillaume Lelarge <guillaume(at)lelarge(dot)info>

> Please, answer to the list.
>

(Wrong button, I'm sorry for that.)

> Le 24/03/2011 09:13, Jaroslav Záruba a écrit :
> > Yes, it is the password for PostgreSQL.
> >
> > pg_dump: [archiver (db)] connection to database "db123" failed: FATAL:
> > password authentication failed for user "postgres"
> > FATAL: password authentication failed for user "postgres"
> >
>
> The error message says the authentication method used isn't trust. Can
> you tell us the complete content of your pg_hba.conf (without the
> comments of course), and the exact command lines (the one that work and
> the one that doesn't work).
>
>
> --
> Guillaume
> http://www.postgresql.fr
> http://dalibo.com
>


From: Guillaume Lelarge <guillaume(at)lelarge(dot)info>
To: Jaroslav Záruba <jaroslav(dot)zaruba(at)gmail(dot)com>
Cc: PostgreSQL - mailing list <pgsql-admin(at)postgresql(dot)org>
Subject: Re: Why pg_dump 'trust' authentication fails under root and works under another user?
Date: 2011-03-24 09:27:55
Message-ID: 4D8B0E9B.9050206@lelarge.info
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-admin

Le 24/03/2011 10:05, Jaroslav Záruba a écrit :
> My pg_hba.conf looks like this:
>
> local all postgres trust
> host all postgres 192.168.1.0/24 md5
> local all all ident
> host all all 127.0.0.1/32 md5
> host all all ::1/128 md5
>
>

Still lacks the complete pg_dump command lines (both of them, the good
and the bad one).

--
Guillaume
http://www.postgresql.fr
http://dalibo.com


From: Jaroslav Záruba <jaroslav(dot)zaruba(at)gmail(dot)com>
To: PostgreSQL - mailing list <pgsql-admin(at)postgresql(dot)org>
Subject: Re: Why pg_dump 'trust' authentication fails under root and works under another user?
Date: 2011-03-24 09:39:24
Message-ID: AANLkTindQcU+LEoVOfkn2-AtTE=8fzPS746RTDdQDuNS@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-admin

The command line is still the same, when executed under one user it does not
ask for password, when executed under another (root that is) it does:
pg_dump --ignore-version --host=localhost --port=5432 --username=postgres
--file="$BACKUP_FILE" --format=p --column-inserts --encoding=UTF-8 db123

2011/3/24 Guillaume Lelarge <guillaume(at)lelarge(dot)info>

> Le 24/03/2011 10:05, Jaroslav Záruba a écrit :
> > My pg_hba.conf looks like this:
> >
> > local all postgres trust
> > host all postgres 192.168.1.0/24 md5
> > local all all ident
> > host all all 127.0.0.1/32 md5
> > host all all ::1/128 md5
> >
> >
>
> Still lacks the complete pg_dump command lines (both of them, the good
> and the bad one).
>
>
> --
> Guillaume
> http://www.postgresql.fr
> http://dalibo.com
>


From: Brett Parker <iDunno(at)sommitrealweird(dot)co(dot)uk>
To: pgsql-admin(at)postgresql(dot)org
Subject: Re: Why pg_dump 'trust' authentication fails under root and works under another user?
Date: 2011-03-24 09:52:11
Message-ID: 20110324095211.GB5521@sommitrealweird.co.uk
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-admin

On 24 Mar 10:39, Jaroslav Záruba wrote:
> The command line is still the same, when executed under one user it does not
> ask for password, when executed under another (root that is) it does:
> pg_dump --ignore-version --host=localhost --port=5432 --username=postgres
> --file="$BACKUP_FILE" --format=p --column-inserts --encoding=UTF-8 db123

If you *really* want root to be able to login to the database as the
postgres user using ident authentication, then you're going to need to
add a line to pg_hba.conf using an ident map, then in the ident map
you're going to have to allow root to map to postgres.

root, per default, does not have a user in postgres. Run your script as
the postgres user if you *really* want super user access.

Thanks,
--
Brett Parker http://www.sommitrealweird.co.uk/
PGP Fingerprint 1A9E C066 EDEE 6746 36CB BD7F 479E C24F 95C7 1D61


From: Jaroslav Záruba <jaroslav(dot)zaruba(at)gmail(dot)com>
To: PostgreSQL - mailing list <pgsql-admin(at)postgresql(dot)org>
Subject: Re: Why pg_dump 'trust' authentication fails under root and works under another user?
Date: 2011-03-24 10:04:09
Message-ID: AANLkTinXpxHJV4eVv0idj2Wir6F0T=yC=Ro3Ox4wmT2J@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-admin

This is what pops up in postgres log whenever I run the command under root,
just when I get prompted for password:
--
could not receive data from client: Connection reset by peer
--

2011/3/24 Jaroslav Záruba <jaroslav(dot)zaruba(at)gmail(dot)com>

> The command line is still the same, when executed under one user it does
> not ask for password, when executed under another (root that is) it does:
> pg_dump --ignore-version --host=localhost --port=5432 --username=postgres
> --file="$BACKUP_FILE" --format=p --column-inserts --encoding=UTF-8 db123
>
> 2011/3/24 Guillaume Lelarge <guillaume(at)lelarge(dot)info>
>
>> Le 24/03/2011 10:05, Jaroslav Záruba a écrit :
>> > My pg_hba.conf looks like this:
>> >
>> > local all postgres trust
>> > host all postgres 192.168.1.0/24 md5
>> > local all all ident
>> > host all all 127.0.0.1/32 md5
>> > host all all ::1/128 md5
>> >
>> >
>>
>> Still lacks the complete pg_dump command lines (both of them, the good
>> and the bad one).
>>
>>
>> --
>> Guillaume
>> http://www.postgresql.fr
>> http://dalibo.com
>>
>
>


From: Guillaume Lelarge <guillaume(at)lelarge(dot)info>
To: Jaroslav Záruba <jaroslav(dot)zaruba(at)gmail(dot)com>
Cc: PostgreSQL - mailing list <pgsql-admin(at)postgresql(dot)org>
Subject: Re: Why pg_dump 'trust' authentication fails under root and works under another user?
Date: 2011-03-24 10:25:13
Message-ID: 4D8B1C09.4050609@lelarge.info
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-admin

Le 24/03/2011 10:39, Jaroslav Záruba a écrit :
> The command line is still the same, when executed under one user it does not
> ask for password, when executed under another (root that is) it does:
> pg_dump --ignore-version --host=localhost --port=5432 --username=postgres
> --file="$BACKUP_FILE" --format=p --column-inserts --encoding=UTF-8 db123
>

The "--host=localhost" option says you're using TCP/IP connection (so
the "host lines" of pg_hba.conf), so it's asking for md5 authentication.
Hence the password.

If one user is not asked for a password, it could be that this user has
a .pgpass file telling pg_dump which password to use.

--
Guillaume
http://www.postgresql.fr
http://dalibo.com


From: Guillaume Lelarge <guillaume(at)lelarge(dot)info>
To: Jaroslav Záruba <jaroslav(dot)zaruba(at)gmail(dot)com>
Cc: PostgreSQL - mailing list <pgsql-admin(at)postgresql(dot)org>
Subject: Re: Why pg_dump 'trust' authentication fails under root and works under another user?
Date: 2011-03-24 10:47:43
Message-ID: 4D8B214F.4060406@lelarge.info
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-admin

Le 24/03/2011 11:32, Jaroslav Záruba a écrit :
> You nailed it! :)
>
> My regular user has .pgpass, root does not.
> When I remove the --host (and --port) arguments it works like charm. :)
>
> Thanks a lot, Guillaume!
>

You're welcome :)

--
Guillaume
http://www.postgresql.fr
http://dalibo.com