From: Tom Lane <tgl@sss.pgh.pa.us>
To: Kris Deugau <kdeugau@vianet.ca>
Cc: pgsql-admin@postgresql.org
Subject: Re: Need reference doc on precedence/ordering for pg_hba.conf
Date: Wed, 01 Mar 2006 18:01:01 -0500
Message-ID: <16668.1141254061@sss.pgh.pa.us> (raw)
In-Reply-To: <44061CC3.1070300@vianet.ca>
References: <44061CC3.1070300@vianet.ca>
Kris Deugau <kdeugau@vianet.ca> writes:
> Failing that, a diagnostic poke to the head to tell me where in this
> config I should put entries that refer to both local socket connections
> and remote TCP/IP connections for one specific database that I want MD5
> (or crypt, for the old 6.x client :/ ) authentication on:
The rule is very simple: the first entry that is able to match an
incoming connection request is the one that's used. "Match" is on
the basis of connection type (local or TCP) and the requested database
name and user name. When the match occurs, the connection is checked
using the specified auth method, and if that fails then it's rejected.
The relative positioning of "local" and "host" entries is therefore
irrelevant, because they can never both match the same connection
request. The relative order of "local" entries is important, and
so is the relative order of "host" entries.
> # From Debian Sarge stock install
> local all postgres ident sameuser
> local all all ident sameuser
The first one is really redundant since the second one would match
all the same connections (ie, local connections with username postgres)
and it specifies the same handling.
> # Added for local software using PG
> local template1 all ident
> local sameuser all md5
> local all root trust
These three are all complete no-ops where you have them, because the
local/all/all entry will already have siphoned off every possible local
connection. You'd need to put them in front of the local/all/all entry
if you want them to do anything. Note however that you almost certainly
do not want that "trust" entry, since it'd allow anyone local to connect
by saying eg "psql -U root". There's not a lot of point in intermixing
trust and non-trust methods for connections from the same machine.
> # More entries from stock Debian package
> host all all 127.0.0.1 255.255.255.255 ident sameuser
> host all all ::1 ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff ident sameuser
> host all all ::ffff:127.0.0.1/128 ident sameuser
>
> # another local config - the real entry contains a real IP
> host all all [host IP] 255.255.255.255 trust
These seem reasonably sane assuming that's what you want. Their
relative order doesn't matter since no two can match the same
connection. (I think --- I don't recall at the moment if 127.0.0.1
can match an IPv6 connection on ::ffff:127.0.0.1.)
> # Last stock entry
> host all all 0.0.0.0 0.0.0.0 reject
This one is a waste of space, since the default is to reject anyway
if there's no match.
regards, tom lane
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-admin@postgresql.org
Cc: tgl@sss.pgh.pa.us, kdeugau@vianet.ca
Subject: Re: Need reference doc on precedence/ordering for pg_hba.conf
In-Reply-To: <16668.1141254061@sss.pgh.pa.us>
References: <44061CC3.1070300@vianet.ca> <16668.1141254061@sss.pgh.pa.us>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
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