2010-09-20 22:08:53 +02:00
<!-- doc/src/sgml/client-auth.sgml -->
2000-06-18 23:24:54 +02:00
<chapter id="client-authentication">
<title>Client Authentication</title>
2001-05-13 00:51:36 +02:00
<indexterm zone="client-authentication">
<primary>client authentication</primary>
</indexterm>
2000-06-18 23:24:54 +02:00
<para>
2002-04-04 06:25:54 +02:00
When a client application connects to the database server, it
2005-08-15 01:35:38 +02:00
specifies which <productname>PostgreSQL</productname> database user name it
2002-04-04 06:25:54 +02:00
wants to connect as, much the same way one logs into a Unix computer
as a particular user. Within the SQL environment the active database
2004-11-15 07:32:15 +01:00
user name determines access privileges to database objects — see
2017-11-23 15:39:47 +01:00
<xref linkend="user-manag"/> for more information. Therefore, it is
2002-04-04 06:25:54 +02:00
essential to restrict which database users can connect.
2000-06-18 23:24:54 +02:00
</para>
2005-08-15 01:35:38 +02:00
<note>
<para>
2017-11-23 15:39:47 +01:00
As explained in <xref linkend="user-manag"/>,
2005-08-15 01:35:38 +02:00
<productname>PostgreSQL</productname> actually does privilege
2017-10-09 03:44:17 +02:00
management in terms of <quote>roles</quote>. In this chapter, we
consistently use <firstterm>database user</firstterm> to mean <quote>role with the
<literal>LOGIN</literal> privilege</quote>.
2005-08-15 01:35:38 +02:00
</para>
</note>
2000-06-18 23:24:54 +02:00
<para>
<firstterm>Authentication</firstterm> is the process by which the
database server establishes the identity of the client, and by
extension determines whether the client application (or the user
2000-11-21 21:44:32 +01:00
who runs the client application) is permitted to connect with the
2005-08-15 01:35:38 +02:00
database user name that was requested.
2000-06-18 23:24:54 +02:00
</para>
<para>
2001-11-21 06:53:41 +01:00
<productname>PostgreSQL</productname> offers a number of different
2002-08-16 06:48:16 +02:00
client authentication methods. The method used to authenticate a
particular client connection can be selected on the basis of
(client) host address, database, and user.
2000-06-18 23:24:54 +02:00
</para>
2000-11-21 21:44:32 +01:00
<para>
2005-08-15 01:35:38 +02:00
<productname>PostgreSQL</productname> database user names are logically
2000-11-21 21:44:32 +01:00
separate from user names of the operating system in which the server
2002-04-04 06:25:54 +02:00
runs. If all the users of a particular server also have accounts on
2000-11-21 21:44:32 +01:00
the server's machine, it makes sense to assign database user names
2002-04-04 06:25:54 +02:00
that match their operating system user names. However, a server that
Replace use of credential control messages with getsockopt(LOCAL_PEERCRED).
It turns out the reason we hadn't found out about the portability issues
with our credential-control-message code is that almost no modern platforms
use that code at all; the ones that used to need it now offer getpeereid(),
which we choose first. The last holdout was NetBSD, and they added
getpeereid() as of 5.0. So far as I can tell, the only live platform on
which that code was being exercised was Debian/kFreeBSD, ie, FreeBSD kernel
with Linux userland --- since glibc doesn't provide getpeereid(), we fell
back to the control message code. However, the FreeBSD kernel provides a
LOCAL_PEERCRED socket parameter that's functionally equivalent to Linux's
SO_PEERCRED. That is both much simpler to use than control messages, and
superior because it doesn't require receiving a message from the other end
at just the right time.
Therefore, add code to use LOCAL_PEERCRED when necessary, and rip out all
the credential-control-message code in the backend. (libpq still has such
code so that it can still talk to pre-9.1 servers ... but eventually we can
get rid of it there too.) Clean up related autoconf probes, too.
This means that libpq's requirepeer parameter now works on exactly the same
platforms where the backend supports peer authentication, so adjust the
documentation accordingly.
2011-05-31 22:10:46 +02:00
accepts remote connections might have many database users who have no local
operating system
2002-04-04 06:25:54 +02:00
account, and in such cases there need be no connection between
database user names and OS user names.
2000-11-21 21:44:32 +01:00
</para>
2002-09-14 20:35:46 +02:00
<sect1 id="auth-pg-hba-conf">
2011-01-29 19:00:18 +01:00
<title>The <filename>pg_hba.conf</filename> File</title>
2000-06-18 23:24:54 +02:00
2002-09-14 20:35:46 +02:00
<indexterm zone="auth-pg-hba-conf">
2001-05-13 00:51:36 +02:00
<primary>pg_hba.conf</primary>
</indexterm>
2000-06-18 23:24:54 +02:00
<para>
2004-12-27 00:06:56 +01:00
Client authentication is controlled by a configuration file,
which traditionally is named
<filename>pg_hba.conf</filename> and is stored in the database
cluster's data directory.
2017-10-09 03:44:17 +02:00
(<acronym>HBA</acronym> stands for host-based authentication.) A default
2002-08-16 06:48:16 +02:00
<filename>pg_hba.conf</filename> file is installed when the data
2022-05-14 09:03:16 +02:00
directory is initialized by <xref linkend="app-initdb"/>. It is
2004-12-27 00:06:56 +01:00
possible to place the authentication configuration file elsewhere,
2017-11-23 15:39:47 +01:00
however; see the <xref linkend="guc-hba-file"/> configuration parameter.
2000-06-18 23:24:54 +02:00
</para>
2023-11-03 19:03:22 +01:00
<para>
The <filename>pg_hba.conf</filename> file is read on start-up and when
the main server process receives a
<systemitem>SIGHUP</systemitem><indexterm><primary>SIGHUP</primary></indexterm>
signal. If you edit the file on an
active system, you will need to signal the postmaster
(using <literal>pg_ctl reload</literal>, calling the SQL function
<function>pg_reload_conf()</function>, or using <literal>kill
-HUP</literal>) to make it re-read the file.
</para>
<note>
<para>
The preceding statement is not true on Microsoft Windows: there, any
changes in the <filename>pg_hba.conf</filename> file are immediately
applied by subsequent new connections.
</para>
</note>
<para>
The system view
<link linkend="view-pg-hba-file-rules"><structname>pg_hba_file_rules</structname></link>
can be helpful for pre-testing changes to the <filename>pg_hba.conf</filename>
file, or for diagnosing problems if loading of the file did not have the
desired effects. Rows in the view with
non-null <structfield>error</structfield> fields indicate problems in the
corresponding lines of the file.
</para>
2000-06-18 23:24:54 +02:00
<para>
2002-11-11 21:14:04 +01:00
The general format of the <filename>pg_hba.conf</filename> file is
2002-04-04 06:25:54 +02:00
a set of records, one per line. Blank lines are ignored, as is any
2010-04-21 05:32:53 +02:00
text after the <literal>#</literal> comment character.
2020-09-03 18:16:48 +02:00
A record can be continued onto the next line by ending the line with
a backslash. (Backslashes are not special except at the end of a line.)
2010-04-21 05:32:53 +02:00
A record is made
2002-04-04 06:25:54 +02:00
up of a number of fields which are separated by spaces and/or tabs.
2012-08-15 17:23:04 +02:00
Fields can contain white space if the field value is double-quoted.
2010-10-15 21:53:39 +02:00
Quoting one of the keywords in a database, user, or address field (e.g.,
2017-10-09 03:44:17 +02:00
<literal>all</literal> or <literal>replication</literal>) makes the word lose its special
2014-01-31 23:08:27 +01:00
meaning, and just match a database, user, or host with that name.
2020-09-03 18:16:48 +02:00
Backslash line continuation applies even within quoted text or comments.
2000-06-18 23:24:54 +02:00
</para>
2001-11-02 19:39:57 +01:00
<para>
Add support for file inclusions in HBA and ident configuration files
pg_hba.conf and pg_ident.conf gain support for three record keywords:
- "include", to include a file.
- "include_if_exists", to include a file, ignoring it if missing.
- "include_dir", to include a directory of files. These are classified
by name (C locale, mostly) and need to be prefixed by ".conf", hence
following the same rules as GUCs.
This commit relies on the refactoring pieces done in efc9816, ad6c528,
783e8c6 and 1b73d0b, adding a small wrapper to build a list of
TokenizedAuthLines (tokenize_include_file), and the code is shaped to
offer some symmetry with what is done for GUCs with the same options.
pg_hba_file_rules and pg_ident_file_mappings gain a new field called
file_name, to track from which file a record is located, taking
advantage of the addition of rule_number in c591300 to offer an
organized view of the HBA or ident records loaded.
Bump catalog version.
Author: Julien Rouhaud
Reviewed-by: Michael Paquier
Discussion: https://postgr.es/m/20220223045959.35ipdsvbxcstrhya@jrouhaud
2022-11-24 05:51:34 +01:00
Each authentication record specifies a connection type, a client IP address
range (if relevant for the connection type), a database name, a user name,
2001-11-02 19:39:57 +01:00
and the authentication method to be used for connections matching
2002-04-04 06:25:54 +02:00
these parameters. The first record with a matching connection type,
client address, requested database, and user name is used to perform
2017-10-09 03:44:17 +02:00
authentication. There is no <quote>fall-through</quote> or
<quote>backup</quote>: if one record is chosen and the authentication
2002-04-04 06:25:54 +02:00
fails, subsequent records are not considered. If no record matches,
access is denied.
2001-11-02 19:39:57 +01:00
</para>
Add support for file inclusions in HBA and ident configuration files
pg_hba.conf and pg_ident.conf gain support for three record keywords:
- "include", to include a file.
- "include_if_exists", to include a file, ignoring it if missing.
- "include_dir", to include a directory of files. These are classified
by name (C locale, mostly) and need to be prefixed by ".conf", hence
following the same rules as GUCs.
This commit relies on the refactoring pieces done in efc9816, ad6c528,
783e8c6 and 1b73d0b, adding a small wrapper to build a list of
TokenizedAuthLines (tokenize_include_file), and the code is shaped to
offer some symmetry with what is done for GUCs with the same options.
pg_hba_file_rules and pg_ident_file_mappings gain a new field called
file_name, to track from which file a record is located, taking
advantage of the addition of rule_number in c591300 to offer an
organized view of the HBA or ident records loaded.
Bump catalog version.
Author: Julien Rouhaud
Reviewed-by: Michael Paquier
Discussion: https://postgr.es/m/20220223045959.35ipdsvbxcstrhya@jrouhaud
2022-11-24 05:51:34 +01:00
<para>
Each record can be an include directive or an authentication record.
Include directives specify files that can be included, that contain
additional records. The records will be inserted in place of the
2023-04-12 06:03:09 +02:00
include directives. Include directives only contain two fields:
Add support for file inclusions in HBA and ident configuration files
pg_hba.conf and pg_ident.conf gain support for three record keywords:
- "include", to include a file.
- "include_if_exists", to include a file, ignoring it if missing.
- "include_dir", to include a directory of files. These are classified
by name (C locale, mostly) and need to be prefixed by ".conf", hence
following the same rules as GUCs.
This commit relies on the refactoring pieces done in efc9816, ad6c528,
783e8c6 and 1b73d0b, adding a small wrapper to build a list of
TokenizedAuthLines (tokenize_include_file), and the code is shaped to
offer some symmetry with what is done for GUCs with the same options.
pg_hba_file_rules and pg_ident_file_mappings gain a new field called
file_name, to track from which file a record is located, taking
advantage of the addition of rule_number in c591300 to offer an
organized view of the HBA or ident records loaded.
Bump catalog version.
Author: Julien Rouhaud
Reviewed-by: Michael Paquier
Discussion: https://postgr.es/m/20220223045959.35ipdsvbxcstrhya@jrouhaud
2022-11-24 05:51:34 +01:00
<literal>include</literal>, <literal>include_if_exists</literal> or
<literal>include_dir</literal> directive and the file or directory to be
2023-04-12 06:03:09 +02:00
included. The file or directory can be a relative or absolute path, and can
Add support for file inclusions in HBA and ident configuration files
pg_hba.conf and pg_ident.conf gain support for three record keywords:
- "include", to include a file.
- "include_if_exists", to include a file, ignoring it if missing.
- "include_dir", to include a directory of files. These are classified
by name (C locale, mostly) and need to be prefixed by ".conf", hence
following the same rules as GUCs.
This commit relies on the refactoring pieces done in efc9816, ad6c528,
783e8c6 and 1b73d0b, adding a small wrapper to build a list of
TokenizedAuthLines (tokenize_include_file), and the code is shaped to
offer some symmetry with what is done for GUCs with the same options.
pg_hba_file_rules and pg_ident_file_mappings gain a new field called
file_name, to track from which file a record is located, taking
advantage of the addition of rule_number in c591300 to offer an
organized view of the HBA or ident records loaded.
Bump catalog version.
Author: Julien Rouhaud
Reviewed-by: Michael Paquier
Discussion: https://postgr.es/m/20220223045959.35ipdsvbxcstrhya@jrouhaud
2022-11-24 05:51:34 +01:00
be double-quoted. For the <literal>include_dir</literal> form, all files
not starting with a <literal>.</literal> and ending with
<literal>.conf</literal> will be included. Multiple files within an include
directory are processed in file name order (according to C locale rules,
i.e., numbers before letters, and uppercase letters before lowercase ones).
</para>
2000-06-18 23:24:54 +02:00
<para>
2020-05-26 02:19:28 +02:00
A record can have several formats:
2003-03-13 02:30:29 +01:00
<synopsis>
Add support for file inclusions in HBA and ident configuration files
pg_hba.conf and pg_ident.conf gain support for three record keywords:
- "include", to include a file.
- "include_if_exists", to include a file, ignoring it if missing.
- "include_dir", to include a directory of files. These are classified
by name (C locale, mostly) and need to be prefixed by ".conf", hence
following the same rules as GUCs.
This commit relies on the refactoring pieces done in efc9816, ad6c528,
783e8c6 and 1b73d0b, adding a small wrapper to build a list of
TokenizedAuthLines (tokenize_include_file), and the code is shaped to
offer some symmetry with what is done for GUCs with the same options.
pg_hba_file_rules and pg_ident_file_mappings gain a new field called
file_name, to track from which file a record is located, taking
advantage of the addition of rule_number in c591300 to offer an
organized view of the HBA or ident records loaded.
Bump catalog version.
Author: Julien Rouhaud
Reviewed-by: Michael Paquier
Discussion: https://postgr.es/m/20220223045959.35ipdsvbxcstrhya@jrouhaud
2022-11-24 05:51:34 +01:00
local <replaceable>database</replaceable> <replaceable>user</replaceable> <replaceable>auth-method</replaceable> <optional><replaceable>auth-options</replaceable></optional>
host <replaceable>database</replaceable> <replaceable>user</replaceable> <replaceable>address</replaceable> <replaceable>auth-method</replaceable> <optional><replaceable>auth-options</replaceable></optional>
hostssl <replaceable>database</replaceable> <replaceable>user</replaceable> <replaceable>address</replaceable> <replaceable>auth-method</replaceable> <optional><replaceable>auth-options</replaceable></optional>
hostnossl <replaceable>database</replaceable> <replaceable>user</replaceable> <replaceable>address</replaceable> <replaceable>auth-method</replaceable> <optional><replaceable>auth-options</replaceable></optional>
hostgssenc <replaceable>database</replaceable> <replaceable>user</replaceable> <replaceable>address</replaceable> <replaceable>auth-method</replaceable> <optional><replaceable>auth-options</replaceable></optional>
hostnogssenc <replaceable>database</replaceable> <replaceable>user</replaceable> <replaceable>address</replaceable> <replaceable>auth-method</replaceable> <optional><replaceable>auth-options</replaceable></optional>
host <replaceable>database</replaceable> <replaceable>user</replaceable> <replaceable>IP-address</replaceable> <replaceable>IP-mask</replaceable> <replaceable>auth-method</replaceable> <optional><replaceable>auth-options</replaceable></optional>
hostssl <replaceable>database</replaceable> <replaceable>user</replaceable> <replaceable>IP-address</replaceable> <replaceable>IP-mask</replaceable> <replaceable>auth-method</replaceable> <optional><replaceable>auth-options</replaceable></optional>
hostnossl <replaceable>database</replaceable> <replaceable>user</replaceable> <replaceable>IP-address</replaceable> <replaceable>IP-mask</replaceable> <replaceable>auth-method</replaceable> <optional><replaceable>auth-options</replaceable></optional>
hostgssenc <replaceable>database</replaceable> <replaceable>user</replaceable> <replaceable>IP-address</replaceable> <replaceable>IP-mask</replaceable> <replaceable>auth-method</replaceable> <optional><replaceable>auth-options</replaceable></optional>
hostnogssenc <replaceable>database</replaceable> <replaceable>user</replaceable> <replaceable>IP-address</replaceable> <replaceable>IP-mask</replaceable> <replaceable>auth-method</replaceable> <optional><replaceable>auth-options</replaceable></optional>
include <replaceable>file</replaceable>
include_if_exists <replaceable>file</replaceable>
include_dir <replaceable>directory</replaceable>
2003-03-13 02:30:29 +01:00
</synopsis>
2000-06-18 23:24:54 +02:00
The meaning of the fields is as follows:
<variablelist>
<varlistentry>
<term><literal>local</literal></term>
<listitem>
<para>
2003-03-13 02:30:29 +01:00
This record matches connection attempts using Unix-domain
2002-09-14 20:35:46 +02:00
sockets. Without a record of this type, Unix-domain socket
2003-09-13 18:43:38 +02:00
connections are disallowed.
2000-06-18 23:24:54 +02:00
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><literal>host</literal></term>
<listitem>
<para>
2003-12-14 00:59:07 +01:00
This record matches connection attempts made using TCP/IP.
GSSAPI encryption support
On both the frontend and backend, prepare for GSSAPI encryption
support by moving common code for error handling into a separate file.
Fix a TODO for handling multiple status messages in the process.
Eliminate the OIDs, which have not been needed for some time.
Add frontend and backend encryption support functions. Keep the
context initiation for authentication-only separate on both the
frontend and backend in order to avoid concerns about changing the
requested flags to include encryption support.
In postmaster, pull GSSAPI authorization checking into a shared
function. Also share the initiator name between the encryption and
non-encryption codepaths.
For HBA, add "hostgssenc" and "hostnogssenc" entries that behave
similarly to their SSL counterparts. "hostgssenc" requires either
"gss", "trust", or "reject" for its authentication.
Similarly, add a "gssencmode" parameter to libpq. Supported values are
"disable", "require", and "prefer". Notably, negotiation will only be
attempted if credentials can be acquired. Move credential acquisition
into its own function to support this behavior.
Add a simple pg_stat_gssapi view similar to pg_stat_ssl, for monitoring
if GSSAPI authentication was used, what principal was used, and if
encryption is being used on the connection.
Finally, add documentation for everything new, and update existing
documentation on connection security.
Thanks to Michael Paquier for the Windows fixes.
Author: Robbie Harwood, with changes to the read/write functions by me.
Reviewed in various forms and at different times by: Michael Paquier,
Andres Freund, David Steele.
Discussion: https://www.postgresql.org/message-id/flat/jlg1tgq1ktm.fsf@thriss.redhat.com
2019-04-03 21:02:33 +02:00
<literal>host</literal> records match
2003-12-14 00:59:07 +01:00
<acronym>SSL</acronym> or non-<acronym>SSL</acronym> connection
GSSAPI encryption support
On both the frontend and backend, prepare for GSSAPI encryption
support by moving common code for error handling into a separate file.
Fix a TODO for handling multiple status messages in the process.
Eliminate the OIDs, which have not been needed for some time.
Add frontend and backend encryption support functions. Keep the
context initiation for authentication-only separate on both the
frontend and backend in order to avoid concerns about changing the
requested flags to include encryption support.
In postmaster, pull GSSAPI authorization checking into a shared
function. Also share the initiator name between the encryption and
non-encryption codepaths.
For HBA, add "hostgssenc" and "hostnogssenc" entries that behave
similarly to their SSL counterparts. "hostgssenc" requires either
"gss", "trust", or "reject" for its authentication.
Similarly, add a "gssencmode" parameter to libpq. Supported values are
"disable", "require", and "prefer". Notably, negotiation will only be
attempted if credentials can be acquired. Move credential acquisition
into its own function to support this behavior.
Add a simple pg_stat_gssapi view similar to pg_stat_ssl, for monitoring
if GSSAPI authentication was used, what principal was used, and if
encryption is being used on the connection.
Finally, add documentation for everything new, and update existing
documentation on connection security.
Thanks to Michael Paquier for the Windows fixes.
Author: Robbie Harwood, with changes to the read/write functions by me.
Reviewed in various forms and at different times by: Michael Paquier,
Andres Freund, David Steele.
Discussion: https://www.postgresql.org/message-id/flat/jlg1tgq1ktm.fsf@thriss.redhat.com
2019-04-03 21:02:33 +02:00
attempts as well as <acronym>GSSAPI</acronym> encrypted or
non-<acronym>GSSAPI</acronym> encrypted connection attempts.
2000-06-18 23:24:54 +02:00
</para>
2004-03-23 02:23:48 +01:00
<note>
<para>
Remote TCP/IP connections will not be possible unless
the server is started with an appropriate value for the
2017-11-23 15:39:47 +01:00
<xref linkend="guc-listen-addresses"/> configuration parameter,
2004-03-23 02:23:48 +01:00
since the default behavior is to listen for TCP/IP connections
2017-10-09 03:44:17 +02:00
only on the local loopback address <literal>localhost</literal>.
2004-03-23 02:23:48 +01:00
</para>
</note>
2000-06-18 23:24:54 +02:00
</listitem>
</varlistentry>
2000-08-29 06:15:43 +02:00
<varlistentry>
<term><literal>hostssl</literal></term>
<listitem>
<para>
2004-03-23 02:23:48 +01:00
This record matches connection attempts made using TCP/IP,
but only when the connection is made with <acronym>SSL</acronym>
encryption.
2002-09-14 20:35:46 +02:00
</para>
<para>
2003-12-14 00:59:07 +01:00
To make use of this option the server must be built with
2004-03-23 02:23:48 +01:00
<acronym>SSL</acronym> support. Furthermore,
2017-01-03 03:37:12 +01:00
<acronym>SSL</acronym> must be enabled
2017-11-23 15:39:47 +01:00
by setting the <xref linkend="guc-ssl"/> configuration parameter (see
<xref linkend="ssl-tcp"/> for more information).
2017-01-03 03:37:12 +01:00
Otherwise, the <literal>hostssl</literal> record is ignored except for
logging a warning that it cannot match any connections.
2000-08-29 06:15:43 +02:00
</para>
</listitem>
</varlistentry>
At long last I put together a patch to support 4 client SSL negotiation
modes (and replace the requiressl boolean). The four options were first
spelled out by Magnus Hagander <mha@sollentuna.net> on 2000-08-23 in email
to pgsql-hackers, archived here:
http://archives.postgresql.org/pgsql-hackers/2000-08/msg00639.php
My original less-flexible patch and the ensuing thread are archived at:
http://dbforums.com/t623845.html
Attached is a new patch, including documentation.
To sum up, there's a new client parameter "sslmode" and environment
variable "PGSSLMODE", with these options:
sslmode description
------- -----------
disable Unencrypted non-SSL only
allow Negotiate, prefer non-SSL
prefer Negotiate, prefer SSL (default)
require Require SSL
The only change to the server is a new pg_hba.conf line type,
"hostnossl", for specifying connections that are not allowed to use SSL
(for example, to prevent servers on a local network from accidentally
using SSL and wasting cycles). Thus the 3 pg_hba.conf line types are:
pg_hba.conf line types
----------------------
host applies to either SSL or regular connections
hostssl applies only to SSL connections
hostnossl applies only to regular connections
These client and server options, the postgresql.conf ssl = false option,
and finally the possibility of compiling with no SSL support at all,
make quite a range of combinations to test. I threw together a test
script to try many of them out. It's in a separate tarball with its
config files, a patch to psql so it'll announce SSL connections even in
absence of a tty, and the test output. The test is especially informative
when run on the same tty the postmaster was started on, so the FATAL:
errors during negotiation are interleaved with the psql client output.
I saw Tom write that new submissions for 7.4 have to be in before midnight
local time, and since I'm on the east coast in the US, this just makes it
in before the bell. :)
Jon Jensen
2003-07-26 15:50:02 +02:00
<varlistentry>
<term><literal>hostnossl</literal></term>
<listitem>
<para>
2017-10-09 03:44:17 +02:00
This record type has the opposite behavior of <literal>hostssl</literal>;
2004-12-27 00:06:56 +01:00
it only matches connection attempts made over
2004-03-23 02:23:48 +01:00
TCP/IP that do not use <acronym>SSL</acronym>.
At long last I put together a patch to support 4 client SSL negotiation
modes (and replace the requiressl boolean). The four options were first
spelled out by Magnus Hagander <mha@sollentuna.net> on 2000-08-23 in email
to pgsql-hackers, archived here:
http://archives.postgresql.org/pgsql-hackers/2000-08/msg00639.php
My original less-flexible patch and the ensuing thread are archived at:
http://dbforums.com/t623845.html
Attached is a new patch, including documentation.
To sum up, there's a new client parameter "sslmode" and environment
variable "PGSSLMODE", with these options:
sslmode description
------- -----------
disable Unencrypted non-SSL only
allow Negotiate, prefer non-SSL
prefer Negotiate, prefer SSL (default)
require Require SSL
The only change to the server is a new pg_hba.conf line type,
"hostnossl", for specifying connections that are not allowed to use SSL
(for example, to prevent servers on a local network from accidentally
using SSL and wasting cycles). Thus the 3 pg_hba.conf line types are:
pg_hba.conf line types
----------------------
host applies to either SSL or regular connections
hostssl applies only to SSL connections
hostnossl applies only to regular connections
These client and server options, the postgresql.conf ssl = false option,
and finally the possibility of compiling with no SSL support at all,
make quite a range of combinations to test. I threw together a test
script to try many of them out. It's in a separate tarball with its
config files, a patch to psql so it'll announce SSL connections even in
absence of a tty, and the test output. The test is especially informative
when run on the same tty the postmaster was started on, so the FATAL:
errors during negotiation are interleaved with the psql client output.
I saw Tom write that new submissions for 7.4 have to be in before midnight
local time, and since I'm on the east coast in the US, this just makes it
in before the bell. :)
Jon Jensen
2003-07-26 15:50:02 +02:00
</para>
</listitem>
</varlistentry>
GSSAPI encryption support
On both the frontend and backend, prepare for GSSAPI encryption
support by moving common code for error handling into a separate file.
Fix a TODO for handling multiple status messages in the process.
Eliminate the OIDs, which have not been needed for some time.
Add frontend and backend encryption support functions. Keep the
context initiation for authentication-only separate on both the
frontend and backend in order to avoid concerns about changing the
requested flags to include encryption support.
In postmaster, pull GSSAPI authorization checking into a shared
function. Also share the initiator name between the encryption and
non-encryption codepaths.
For HBA, add "hostgssenc" and "hostnogssenc" entries that behave
similarly to their SSL counterparts. "hostgssenc" requires either
"gss", "trust", or "reject" for its authentication.
Similarly, add a "gssencmode" parameter to libpq. Supported values are
"disable", "require", and "prefer". Notably, negotiation will only be
attempted if credentials can be acquired. Move credential acquisition
into its own function to support this behavior.
Add a simple pg_stat_gssapi view similar to pg_stat_ssl, for monitoring
if GSSAPI authentication was used, what principal was used, and if
encryption is being used on the connection.
Finally, add documentation for everything new, and update existing
documentation on connection security.
Thanks to Michael Paquier for the Windows fixes.
Author: Robbie Harwood, with changes to the read/write functions by me.
Reviewed in various forms and at different times by: Michael Paquier,
Andres Freund, David Steele.
Discussion: https://www.postgresql.org/message-id/flat/jlg1tgq1ktm.fsf@thriss.redhat.com
2019-04-03 21:02:33 +02:00
<varlistentry>
<term><literal>hostgssenc</literal></term>
<listitem>
<para>
This record matches connection attempts made using TCP/IP,
but only when the connection is made with <acronym>GSSAPI</acronym>
encryption.
</para>
<para>
To make use of this option the server must be built with
<acronym>GSSAPI</acronym> support. Otherwise,
the <literal>hostgssenc</literal> record is ignored except for logging
a warning that it cannot match any connections.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><literal>hostnogssenc</literal></term>
<listitem>
<para>
This record type has the opposite behavior of <literal>hostgssenc</literal>;
it only matches connection attempts made over
TCP/IP that do not use <acronym>GSSAPI</acronym> encryption.
</para>
</listitem>
</varlistentry>
2000-06-18 23:24:54 +02:00
<varlistentry>
<term><replaceable>database</replaceable></term>
<listitem>
<para>
2009-05-16 23:17:21 +02:00
Specifies which database name(s) this record matches. The value
2002-09-14 20:35:46 +02:00
<literal>all</literal> specifies that it matches all databases.
2017-10-09 03:44:17 +02:00
The value <literal>sameuser</literal> specifies that the record
2002-09-14 20:35:46 +02:00
matches if the requested database has the same name as the
2017-10-09 03:44:17 +02:00
requested user. The value <literal>samerole</literal> specifies that
2005-08-15 01:35:38 +02:00
the requested user must be a member of the role with the same
2017-10-09 03:44:17 +02:00
name as the requested database. (<literal>samegroup</literal> is an
obsolete but still accepted spelling of <literal>samerole</literal>.)
2011-11-03 21:29:41 +01:00
Superusers are not considered to be members of a role for the
2017-10-09 03:44:17 +02:00
purposes of <literal>samerole</literal> unless they are explicitly
2012-05-15 21:19:04 +02:00
members of the role, directly or indirectly, and not just by
2011-11-03 21:29:41 +01:00
virtue of being a superuser.
2017-10-09 03:44:17 +02:00
The value <literal>replication</literal> specifies that the record
2021-02-23 04:41:22 +01:00
matches if a physical replication connection is requested, however, it
doesn't match with logical replication connections. Note that physical
replication connections do not specify any particular database whereas
logical replication connections do specify it.
Add support for regexps on database and user entries in pg_hba.conf
As of this commit, any database or user entry beginning with a slash (/)
is considered as a regular expression. This is particularly useful for
users, as now there is no clean way to match pattern on multiple HBA
lines. For example, a user name mapping with a regular expression needs
first to match with a HBA line, and we would skip the follow-up HBA
entries if the ident regexp does *not* match with what has matched in
the HBA line.
pg_hba.conf is able to handle multiple databases and roles with a
comma-separated list of these, hence individual regular expressions that
include commas need to be double-quoted.
At authentication time, user and database names are now checked in the
following order:
- Arbitrary keywords (like "all", the ones beginning by '+' for
membership check), that we know will never have a regexp. A fancy case
is for physical WAL senders, we *have* to only match "replication" for
the database.
- Regular expression matching.
- Exact match.
The previous logic did the same, but without the regexp step.
We have discussed as well the possibility to support regexp pattern
matching for host names, but these happen to lead to tricky issues based
on what I understand, particularly with host entries that have CIDRs.
This commit relies heavily on the refactoring done in a903971 and
fc579e1, so as the amount of code required to compile and execute
regular expressions is now minimal. When parsing pg_hba.conf, all the
computed regexps needs to explicitely free()'d, same as pg_ident.conf.
Documentation and TAP tests are added to cover this feature, including
cases where the regexps use commas (for clarity in the docs, coverage
for the parsing logic in the tests).
Note that this introduces a breakage with older versions, where a
database or user name beginning with a slash are treated as something to
check for an equal match. Per discussion, we have discarded this as
being much of an issue in practice as it would require a cluster to
have database and/or role names that begin with a slash, as well as HBA
entries using these. Hence, the consistency gained with regexps in
pg_ident.conf is more appealing in the long term.
**This compatibility change should be mentioned in the release notes.**
Author: Bertrand Drouvot
Reviewed-by: Jacob Champion, Tom Lane, Michael Paquier
Discussion: https://postgr.es/m/fff0d7c1-8ad4-76a1-9db3-0ab6ec338bf7@amazon.com
2022-10-24 04:45:31 +02:00
Otherwise, this is the name of a specific
<productname>PostgreSQL</productname> database or a regular expression.
Multiple database names and/or regular expressions can be supplied by
separating them with commas.
</para>
<para>
If the database name starts with a slash (<literal>/</literal>), the
remainder of the name is treated as a regular expression.
(See <xref linkend="posix-syntax-details"/> for details of
<productname>PostgreSQL</productname>'s regular expression syntax.)
</para>
<para>
A separate file containing database names and/or regular expressions
can be specified by preceding the file name with <literal>@</literal>.
2002-04-04 06:25:54 +02:00
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><replaceable>user</replaceable></term>
<listitem>
<para>
2009-05-16 23:17:21 +02:00
Specifies which database user name(s) this record
2002-11-15 04:11:18 +01:00
matches. The value <literal>all</literal> specifies that it
2005-08-15 01:35:38 +02:00
matches all users. Otherwise, this is either the name of a specific
Add support for regexps on database and user entries in pg_hba.conf
As of this commit, any database or user entry beginning with a slash (/)
is considered as a regular expression. This is particularly useful for
users, as now there is no clean way to match pattern on multiple HBA
lines. For example, a user name mapping with a regular expression needs
first to match with a HBA line, and we would skip the follow-up HBA
entries if the ident regexp does *not* match with what has matched in
the HBA line.
pg_hba.conf is able to handle multiple databases and roles with a
comma-separated list of these, hence individual regular expressions that
include commas need to be double-quoted.
At authentication time, user and database names are now checked in the
following order:
- Arbitrary keywords (like "all", the ones beginning by '+' for
membership check), that we know will never have a regexp. A fancy case
is for physical WAL senders, we *have* to only match "replication" for
the database.
- Regular expression matching.
- Exact match.
The previous logic did the same, but without the regexp step.
We have discussed as well the possibility to support regexp pattern
matching for host names, but these happen to lead to tricky issues based
on what I understand, particularly with host entries that have CIDRs.
This commit relies heavily on the refactoring done in a903971 and
fc579e1, so as the amount of code required to compile and execute
regular expressions is now minimal. When parsing pg_hba.conf, all the
computed regexps needs to explicitely free()'d, same as pg_ident.conf.
Documentation and TAP tests are added to cover this feature, including
cases where the regexps use commas (for clarity in the docs, coverage
for the parsing logic in the tests).
Note that this introduces a breakage with older versions, where a
database or user name beginning with a slash are treated as something to
check for an equal match. Per discussion, we have discarded this as
being much of an issue in practice as it would require a cluster to
have database and/or role names that begin with a slash, as well as HBA
entries using these. Hence, the consistency gained with regexps in
pg_ident.conf is more appealing in the long term.
**This compatibility change should be mentioned in the release notes.**
Author: Bertrand Drouvot
Reviewed-by: Jacob Champion, Tom Lane, Michael Paquier
Discussion: https://postgr.es/m/fff0d7c1-8ad4-76a1-9db3-0ab6ec338bf7@amazon.com
2022-10-24 04:45:31 +02:00
database user, a regular expression (when starting with a slash
(<literal>/</literal>), or a group name preceded by <literal>+</literal>.
2005-08-15 01:35:38 +02:00
(Recall that there is no real distinction between users and groups
2017-10-09 03:44:17 +02:00
in <productname>PostgreSQL</productname>; a <literal>+</literal> mark really means
2005-08-15 01:35:38 +02:00
<quote>match any of the roles that are directly or indirectly members
2017-10-09 03:44:17 +02:00
of this role</quote>, while a name without a <literal>+</literal> mark matches
2011-11-03 17:45:02 +01:00
only that specific role.) For this purpose, a superuser is only
considered to be a member of a role if they are explicitly a member
of the role, directly or indirectly, and not just by virtue of
being a superuser.
Add support for regexps on database and user entries in pg_hba.conf
As of this commit, any database or user entry beginning with a slash (/)
is considered as a regular expression. This is particularly useful for
users, as now there is no clean way to match pattern on multiple HBA
lines. For example, a user name mapping with a regular expression needs
first to match with a HBA line, and we would skip the follow-up HBA
entries if the ident regexp does *not* match with what has matched in
the HBA line.
pg_hba.conf is able to handle multiple databases and roles with a
comma-separated list of these, hence individual regular expressions that
include commas need to be double-quoted.
At authentication time, user and database names are now checked in the
following order:
- Arbitrary keywords (like "all", the ones beginning by '+' for
membership check), that we know will never have a regexp. A fancy case
is for physical WAL senders, we *have* to only match "replication" for
the database.
- Regular expression matching.
- Exact match.
The previous logic did the same, but without the regexp step.
We have discussed as well the possibility to support regexp pattern
matching for host names, but these happen to lead to tricky issues based
on what I understand, particularly with host entries that have CIDRs.
This commit relies heavily on the refactoring done in a903971 and
fc579e1, so as the amount of code required to compile and execute
regular expressions is now minimal. When parsing pg_hba.conf, all the
computed regexps needs to explicitely free()'d, same as pg_ident.conf.
Documentation and TAP tests are added to cover this feature, including
cases where the regexps use commas (for clarity in the docs, coverage
for the parsing logic in the tests).
Note that this introduces a breakage with older versions, where a
database or user name beginning with a slash are treated as something to
check for an equal match. Per discussion, we have discarded this as
being much of an issue in practice as it would require a cluster to
have database and/or role names that begin with a slash, as well as HBA
entries using these. Hence, the consistency gained with regexps in
pg_ident.conf is more appealing in the long term.
**This compatibility change should be mentioned in the release notes.**
Author: Bertrand Drouvot
Reviewed-by: Jacob Champion, Tom Lane, Michael Paquier
Discussion: https://postgr.es/m/fff0d7c1-8ad4-76a1-9db3-0ab6ec338bf7@amazon.com
2022-10-24 04:45:31 +02:00
Multiple user names and/or regular expressions can be supplied by
separating them with commas.
</para>
<para>
If the user name starts with a slash (<literal>/</literal>), the
remainder of the name is treated as a regular expression.
(See <xref linkend="posix-syntax-details"/> for details of
<productname>PostgreSQL</productname>'s regular expression syntax.)
</para>
<para>
A separate file containing user names and/or regular expressions can
be specified by preceding the file name with <literal>@</literal>.
2000-06-18 23:24:54 +02:00
</para>
</listitem>
</varlistentry>
<varlistentry>
2010-10-15 21:53:39 +02:00
<term><replaceable>address</replaceable></term>
2000-06-18 23:24:54 +02:00
<listitem>
<para>
2015-02-17 18:49:18 +01:00
Specifies the client machine address(es) that this record
2010-10-15 21:53:39 +02:00
matches. This field can contain either a host name, an IP
address range, or one of the special key words mentioned below.
</para>
<para>
2015-02-17 18:49:18 +01:00
An IP address range is specified using standard numeric notation
for the range's starting address, then a slash (<literal>/</literal>)
2017-10-09 03:44:17 +02:00
and a <acronym>CIDR</acronym> mask length. The mask
2004-12-27 00:06:56 +01:00
length indicates the number of high-order bits of the client
2011-06-14 02:54:45 +02:00
IP address that must match. Bits to the right of this should
2004-12-27 00:06:56 +01:00
be zero in the given IP address.
There must not be any white space between the IP address, the
<literal>/</literal>, and the CIDR mask length.
2004-08-26 18:50:05 +02:00
</para>
2009-10-01 03:58:58 +02:00
<para>
2015-02-17 18:49:18 +01:00
Typical examples of an IPv4 address range specified this way are
2004-12-27 00:06:56 +01:00
<literal>172.20.143.89/32</literal> for a single host, or
2006-11-18 00:25:17 +01:00
<literal>172.20.143.0/24</literal> for a small network, or
2010-04-21 05:32:53 +02:00
<literal>10.6.0.0/16</literal> for a larger one.
2015-02-17 18:49:18 +01:00
An IPv6 address range might look like <literal>::1/128</literal>
for a single host (in this case the IPv6 loopback address) or
<literal>fe80::7a31:c1ff:0000:0000/96</literal> for a small
network.
2011-03-19 15:04:34 +01:00
<literal>0.0.0.0/0</literal> represents all
2015-02-17 18:49:18 +01:00
IPv4 addresses, and <literal>::0/0</literal> represents
2011-03-18 23:41:02 +01:00
all IPv6 addresses.
2015-02-17 18:49:18 +01:00
To specify a single host, use a mask length of 32 for IPv4 or
2006-11-18 00:25:17 +01:00
128 for IPv6. In a network address, do not omit trailing zeroes.
2003-09-05 22:31:36 +02:00
</para>
<para>
2015-02-17 18:49:18 +01:00
An entry given in IPv4 format will match only IPv4 connections,
and an entry given in IPv6 format will match only IPv6 connections,
even if the represented address is in the IPv4-in-IPv6 range.
2002-09-14 20:35:46 +02:00
</para>
2010-10-15 21:53:39 +02:00
<para>
2010-10-18 21:14:47 +02:00
You can also write <literal>all</literal> to match any IP address,
2010-10-15 21:53:39 +02:00
<literal>samehost</literal> to match any of the server's own IP
addresses, or <literal>samenet</literal> to match any address in any
subnet that the server is directly connected to.
</para>
<para>
If a host name is specified (anything that is not an IP address
2015-02-17 18:49:18 +01:00
range or a special key word is treated as a host name),
2010-10-15 21:53:39 +02:00
that name is compared with the result of a reverse name
resolution of the client's IP address (e.g., reverse DNS
lookup, if DNS is used). Host name comparisons are case
insensitive. If there is a match, then a forward name
resolution (e.g., forward DNS lookup) is performed on the host
name to check whether any of the addresses it resolves to are
equal to the client's IP address. If both directions match,
then the entry is considered to match. (The host name that is
used in <filename>pg_hba.conf</filename> should be the one that
address-to-name resolution of the client's IP address returns,
otherwise the line won't be matched. Some host name databases
allow associating an IP address with multiple host names, but
the operating system will only return one host name when asked
to resolve an IP address.)
</para>
2010-10-24 14:54:00 +02:00
<para>
A host name specification that starts with a dot
(<literal>.</literal>) matches a suffix of the actual host
name. So <literal>.example.com</literal> would match
<literal>foo.example.com</literal> (but not just
<literal>example.com</literal>).
</para>
2010-10-15 21:53:39 +02:00
<para>
When host names are specified
in <filename>pg_hba.conf</filename>, you should make sure that
name resolution is reasonably fast. It can be of advantage to
set up a local name resolution cache such
as <command>nscd</command>. Also, you may wish to enable the
configuration parameter <varname>log_hostname</varname> to see
the client's host name instead of the IP address in the log.
</para>
2014-04-01 21:20:30 +02:00
<para>
2020-05-26 02:19:28 +02:00
These fields do not apply to <literal>local</literal> records.
2014-04-01 21:20:30 +02:00
</para>
2017-08-30 01:33:24 +02:00
<note>
2010-10-15 21:53:39 +02:00
<para>
2014-04-01 21:20:30 +02:00
Users sometimes wonder why host names are handled
in this seemingly complicated way, with two name resolutions
including a reverse lookup of the client's IP address. This
complicates use of the feature in case the client's reverse DNS
entry is not set up or yields some undesirable host name.
It is done primarily for efficiency: this way, a connection attempt
requires at most two resolver lookups, one reverse and one forward.
If there is a resolver problem with some address, it becomes only
2010-10-15 21:53:39 +02:00
that client's problem. A hypothetical alternative
2014-04-01 21:20:30 +02:00
implementation that only did forward lookups would have to
2010-10-15 21:53:39 +02:00
resolve every host name mentioned in
2014-04-01 21:20:30 +02:00
<filename>pg_hba.conf</filename> during every connection attempt.
That could be quite slow if many names are listed.
And if there is a resolver problem with one of the host names,
it becomes everyone's problem.
2010-10-15 21:53:39 +02:00
</para>
2010-10-24 14:54:00 +02:00
<para>
Also, a reverse lookup is necessary to implement the suffix
matching feature, because the actual client host name needs to
be known in order to match it against the pattern.
</para>
2010-10-15 21:53:39 +02:00
<para>
Note that this behavior is consistent with other popular
implementations of host name-based access control, such as the
Apache HTTP Server and TCP Wrappers.
</para>
2017-08-30 01:33:24 +02:00
</note>
2000-06-18 23:24:54 +02:00
</listitem>
</varlistentry>
2003-06-25 03:20:50 +02:00
<varlistentry>
2004-08-26 18:50:05 +02:00
<term><replaceable>IP-address</replaceable></term>
2004-12-27 00:06:56 +01:00
<term><replaceable>IP-mask</replaceable></term>
2003-06-25 03:20:50 +02:00
<listitem>
<para>
2015-02-17 18:49:18 +01:00
These two fields can be used as an alternative to the
2017-10-09 03:44:17 +02:00
<replaceable>IP-address</replaceable><literal>/</literal><replaceable>mask-length</replaceable>
2015-02-17 18:49:18 +01:00
notation. Instead of
2004-08-26 18:50:05 +02:00
specifying the mask length, the actual mask is specified in a
2017-10-09 03:44:17 +02:00
separate column. For example, <literal>255.0.0.0</literal> represents an IPv4
CIDR mask length of 8, and <literal>255.255.255.255</literal> represents a
2004-12-27 00:06:56 +01:00
CIDR mask length of 32.
2003-06-25 03:20:50 +02:00
</para>
<para>
2020-05-26 02:19:28 +02:00
These fields do not apply to <literal>local</literal> records.
2003-06-25 03:20:50 +02:00
</para>
</listitem>
2009-05-16 23:17:21 +02:00
</varlistentry>
2003-06-25 03:20:50 +02:00
2000-06-18 23:24:54 +02:00
<varlistentry>
2005-08-15 01:35:38 +02:00
<term><replaceable>auth-method</replaceable></term>
2000-06-18 23:24:54 +02:00
<listitem>
<para>
2009-05-16 23:17:21 +02:00
Specifies the authentication method to use when a connection matches
2002-04-04 06:25:54 +02:00
this record. The possible choices are summarized here; details
2022-07-21 19:58:20 +02:00
are in <xref linkend="auth-methods"/>. All the options
are lower case and treated case sensitively, so even acronyms like
<literal>ldap</literal> must be specified as lower case.
2000-09-06 21:54:52 +02:00
<variablelist>
<varlistentry>
2017-10-09 03:44:17 +02:00
<term><literal>trust</literal></term>
2000-09-06 21:54:52 +02:00
<listitem>
<para>
2004-12-27 00:06:56 +01:00
Allow the connection unconditionally. This method
2002-08-16 06:48:16 +02:00
allows anyone that can connect to the
2003-03-13 02:30:29 +01:00
<productname>PostgreSQL</productname> database server to login as
2010-02-03 18:25:06 +01:00
any <productname>PostgreSQL</productname> user they wish,
without the need for a password or any other authentication. See <xref
2017-11-23 15:39:47 +01:00
linkend="auth-trust"/> for details.
2000-09-06 21:54:52 +02:00
</para>
</listitem>
</varlistentry>
<varlistentry>
2017-10-09 03:44:17 +02:00
<term><literal>reject</literal></term>
2000-09-06 21:54:52 +02:00
<listitem>
<para>
2004-12-27 00:06:56 +01:00
Reject the connection unconditionally. This is useful for
2017-10-09 03:44:17 +02:00
<quote>filtering out</quote> certain hosts from a group, for example a
<literal>reject</literal> line could block a specific host from connecting,
2010-05-27 01:49:19 +02:00
while a later line allows the remaining hosts in a specific
2010-02-03 18:25:06 +01:00
network to connect.
2000-09-06 21:54:52 +02:00
</para>
</listitem>
</varlistentry>
<varlistentry>
2017-10-09 03:44:17 +02:00
<term><literal>scram-sha-256</literal></term>
2000-09-06 21:54:52 +02:00
<listitem>
<para>
Allow SCRAM authentication, when pg_hba.conf says 'md5'.
If a user has a SCRAM verifier in pg_authid.rolpassword, there's no reason
we cannot attempt to perform SCRAM authentication instead of MD5. The worst
that can happen is that the client doesn't support SCRAM, and the
authentication will fail. But previously, it would fail for sure, because
we would not even try. SCRAM is strictly more secure than MD5, so there's
no harm in trying it. This allows for a more graceful transition from MD5
passwords to SCRAM, as user passwords can be changed to SCRAM verifiers
incrementally, without changing pg_hba.conf.
Refactor the code in auth.c to support that better. Notably, we now have to
look up the user's pg_authid entry before sending the password challenge,
also when performing MD5 authentication. Also simplify the concept of a
"doomed" authentication. Previously, if a user had a password, but it had
expired, we still performed SCRAM authentication (but always returned error
at the end) using the salt and iteration count from the expired password.
Now we construct a fake salt, like we do when the user doesn't have a
password or doesn't exist at all. That simplifies get_role_password(), and
we can don't need to distinguish the "user has expired password", and
"user does not exist" cases in auth.c.
On second thoughts, also rename uaSASL to uaSCRAM. It refers to the
mechanism specified in pg_hba.conf, and while we use SASL for SCRAM
authentication at the protocol level, the mechanism should be called SCRAM,
not SASL. As a comparison, we have uaLDAP, even though it looks like the
plain 'password' authentication at the protocol level.
Discussion: https://www.postgresql.org/message-id/6425.1489506016@sss.pgh.pa.us
Reviewed-by: Michael Paquier
2017-03-24 12:32:21 +01:00
Perform SCRAM-SHA-256 authentication to verify the user's
2017-11-23 15:39:47 +01:00
password. See <xref linkend="auth-password"/> for details.
2000-09-06 21:54:52 +02:00
</para>
</listitem>
</varlistentry>
Support SCRAM-SHA-256 authentication (RFC 5802 and 7677).
This introduces a new generic SASL authentication method, similar to the
GSS and SSPI methods. The server first tells the client which SASL
authentication mechanism to use, and then the mechanism-specific SASL
messages are exchanged in AuthenticationSASLcontinue and PasswordMessage
messages. Only SCRAM-SHA-256 is supported at the moment, but this allows
adding more SASL mechanisms in the future, without changing the overall
protocol.
Support for channel binding, aka SCRAM-SHA-256-PLUS is left for later.
The SASLPrep algorithm, for pre-processing the password, is not yet
implemented. That could cause trouble, if you use a password with
non-ASCII characters, and a client library that does implement SASLprep.
That will hopefully be added later.
Authorization identities, as specified in the SCRAM-SHA-256 specification,
are ignored. SET SESSION AUTHORIZATION provides more or less the same
functionality, anyway.
If a user doesn't exist, perform a "mock" authentication, by constructing
an authentic-looking challenge on the fly. The challenge is derived from
a new system-wide random value, "mock authentication nonce", which is
created at initdb, and stored in the control file. We go through these
motions, in order to not give away the information on whether the user
exists, to unauthenticated users.
Bumps PG_CONTROL_VERSION, because of the new field in control file.
Patch by Michael Paquier and Heikki Linnakangas, reviewed at different
stages by Robert Haas, Stephen Frost, David Steele, Aleksander Alekseev,
and many others.
Discussion: https://www.postgresql.org/message-id/CAB7nPqRbR3GmFYdedCAhzukfKrgBLTLtMvENOmPrVWREsZkF8g%40mail.gmail.com
Discussion: https://www.postgresql.org/message-id/CAB7nPqSMXU35g%3DW9X74HVeQp0uvgJxvYOuA4A-A3M%2B0wfEBv-w%40mail.gmail.com
Discussion: https://www.postgresql.org/message-id/55192AFE.6080106@iki.fi
2017-03-07 13:25:40 +01:00
<varlistentry>
2017-10-09 03:44:17 +02:00
<term><literal>md5</literal></term>
Support SCRAM-SHA-256 authentication (RFC 5802 and 7677).
This introduces a new generic SASL authentication method, similar to the
GSS and SSPI methods. The server first tells the client which SASL
authentication mechanism to use, and then the mechanism-specific SASL
messages are exchanged in AuthenticationSASLcontinue and PasswordMessage
messages. Only SCRAM-SHA-256 is supported at the moment, but this allows
adding more SASL mechanisms in the future, without changing the overall
protocol.
Support for channel binding, aka SCRAM-SHA-256-PLUS is left for later.
The SASLPrep algorithm, for pre-processing the password, is not yet
implemented. That could cause trouble, if you use a password with
non-ASCII characters, and a client library that does implement SASLprep.
That will hopefully be added later.
Authorization identities, as specified in the SCRAM-SHA-256 specification,
are ignored. SET SESSION AUTHORIZATION provides more or less the same
functionality, anyway.
If a user doesn't exist, perform a "mock" authentication, by constructing
an authentic-looking challenge on the fly. The challenge is derived from
a new system-wide random value, "mock authentication nonce", which is
created at initdb, and stored in the control file. We go through these
motions, in order to not give away the information on whether the user
exists, to unauthenticated users.
Bumps PG_CONTROL_VERSION, because of the new field in control file.
Patch by Michael Paquier and Heikki Linnakangas, reviewed at different
stages by Robert Haas, Stephen Frost, David Steele, Aleksander Alekseev,
and many others.
Discussion: https://www.postgresql.org/message-id/CAB7nPqRbR3GmFYdedCAhzukfKrgBLTLtMvENOmPrVWREsZkF8g%40mail.gmail.com
Discussion: https://www.postgresql.org/message-id/CAB7nPqSMXU35g%3DW9X74HVeQp0uvgJxvYOuA4A-A3M%2B0wfEBv-w%40mail.gmail.com
Discussion: https://www.postgresql.org/message-id/55192AFE.6080106@iki.fi
2017-03-07 13:25:40 +01:00
<listitem>
<para>
Allow SCRAM authentication, when pg_hba.conf says 'md5'.
If a user has a SCRAM verifier in pg_authid.rolpassword, there's no reason
we cannot attempt to perform SCRAM authentication instead of MD5. The worst
that can happen is that the client doesn't support SCRAM, and the
authentication will fail. But previously, it would fail for sure, because
we would not even try. SCRAM is strictly more secure than MD5, so there's
no harm in trying it. This allows for a more graceful transition from MD5
passwords to SCRAM, as user passwords can be changed to SCRAM verifiers
incrementally, without changing pg_hba.conf.
Refactor the code in auth.c to support that better. Notably, we now have to
look up the user's pg_authid entry before sending the password challenge,
also when performing MD5 authentication. Also simplify the concept of a
"doomed" authentication. Previously, if a user had a password, but it had
expired, we still performed SCRAM authentication (but always returned error
at the end) using the salt and iteration count from the expired password.
Now we construct a fake salt, like we do when the user doesn't have a
password or doesn't exist at all. That simplifies get_role_password(), and
we can don't need to distinguish the "user has expired password", and
"user does not exist" cases in auth.c.
On second thoughts, also rename uaSASL to uaSCRAM. It refers to the
mechanism specified in pg_hba.conf, and while we use SASL for SCRAM
authentication at the protocol level, the mechanism should be called SCRAM,
not SASL. As a comparison, we have uaLDAP, even though it looks like the
plain 'password' authentication at the protocol level.
Discussion: https://www.postgresql.org/message-id/6425.1489506016@sss.pgh.pa.us
Reviewed-by: Michael Paquier
2017-03-24 12:32:21 +01:00
Perform SCRAM-SHA-256 or MD5 authentication to verify the
2017-11-23 15:39:47 +01:00
user's password. See <xref linkend="auth-password"/>
Allow SCRAM authentication, when pg_hba.conf says 'md5'.
If a user has a SCRAM verifier in pg_authid.rolpassword, there's no reason
we cannot attempt to perform SCRAM authentication instead of MD5. The worst
that can happen is that the client doesn't support SCRAM, and the
authentication will fail. But previously, it would fail for sure, because
we would not even try. SCRAM is strictly more secure than MD5, so there's
no harm in trying it. This allows for a more graceful transition from MD5
passwords to SCRAM, as user passwords can be changed to SCRAM verifiers
incrementally, without changing pg_hba.conf.
Refactor the code in auth.c to support that better. Notably, we now have to
look up the user's pg_authid entry before sending the password challenge,
also when performing MD5 authentication. Also simplify the concept of a
"doomed" authentication. Previously, if a user had a password, but it had
expired, we still performed SCRAM authentication (but always returned error
at the end) using the salt and iteration count from the expired password.
Now we construct a fake salt, like we do when the user doesn't have a
password or doesn't exist at all. That simplifies get_role_password(), and
we can don't need to distinguish the "user has expired password", and
"user does not exist" cases in auth.c.
On second thoughts, also rename uaSASL to uaSCRAM. It refers to the
mechanism specified in pg_hba.conf, and while we use SASL for SCRAM
authentication at the protocol level, the mechanism should be called SCRAM,
not SASL. As a comparison, we have uaLDAP, even though it looks like the
plain 'password' authentication at the protocol level.
Discussion: https://www.postgresql.org/message-id/6425.1489506016@sss.pgh.pa.us
Reviewed-by: Michael Paquier
2017-03-24 12:32:21 +01:00
for details.
Support SCRAM-SHA-256 authentication (RFC 5802 and 7677).
This introduces a new generic SASL authentication method, similar to the
GSS and SSPI methods. The server first tells the client which SASL
authentication mechanism to use, and then the mechanism-specific SASL
messages are exchanged in AuthenticationSASLcontinue and PasswordMessage
messages. Only SCRAM-SHA-256 is supported at the moment, but this allows
adding more SASL mechanisms in the future, without changing the overall
protocol.
Support for channel binding, aka SCRAM-SHA-256-PLUS is left for later.
The SASLPrep algorithm, for pre-processing the password, is not yet
implemented. That could cause trouble, if you use a password with
non-ASCII characters, and a client library that does implement SASLprep.
That will hopefully be added later.
Authorization identities, as specified in the SCRAM-SHA-256 specification,
are ignored. SET SESSION AUTHORIZATION provides more or less the same
functionality, anyway.
If a user doesn't exist, perform a "mock" authentication, by constructing
an authentic-looking challenge on the fly. The challenge is derived from
a new system-wide random value, "mock authentication nonce", which is
created at initdb, and stored in the control file. We go through these
motions, in order to not give away the information on whether the user
exists, to unauthenticated users.
Bumps PG_CONTROL_VERSION, because of the new field in control file.
Patch by Michael Paquier and Heikki Linnakangas, reviewed at different
stages by Robert Haas, Stephen Frost, David Steele, Aleksander Alekseev,
and many others.
Discussion: https://www.postgresql.org/message-id/CAB7nPqRbR3GmFYdedCAhzukfKrgBLTLtMvENOmPrVWREsZkF8g%40mail.gmail.com
Discussion: https://www.postgresql.org/message-id/CAB7nPqSMXU35g%3DW9X74HVeQp0uvgJxvYOuA4A-A3M%2B0wfEBv-w%40mail.gmail.com
Discussion: https://www.postgresql.org/message-id/55192AFE.6080106@iki.fi
2017-03-07 13:25:40 +01:00
</para>
</listitem>
</varlistentry>
2001-08-16 18:24:16 +02:00
<varlistentry>
2017-10-09 03:44:17 +02:00
<term><literal>password</literal></term>
2001-08-16 18:24:16 +02:00
<listitem>
<para>
2004-12-27 00:06:56 +01:00
Require the client to supply an unencrypted password for
authentication.
Since the password is sent in clear text over the
network, this should not be used on untrusted networks.
2017-11-23 15:39:47 +01:00
See <xref linkend="auth-password"/> for details.
2002-04-04 06:25:54 +02:00
</para>
2001-08-16 18:24:16 +02:00
</listitem>
</varlistentry>
2007-07-18 14:00:47 +02:00
<varlistentry>
2017-10-09 03:44:17 +02:00
<term><literal>gss</literal></term>
2007-07-18 14:00:47 +02:00
<listitem>
<para>
2009-05-16 23:17:21 +02:00
Use GSSAPI to authenticate the user. This is only
2019-08-20 05:36:31 +02:00
available for TCP/IP connections. See <xref
GSSAPI encryption support
On both the frontend and backend, prepare for GSSAPI encryption
support by moving common code for error handling into a separate file.
Fix a TODO for handling multiple status messages in the process.
Eliminate the OIDs, which have not been needed for some time.
Add frontend and backend encryption support functions. Keep the
context initiation for authentication-only separate on both the
frontend and backend in order to avoid concerns about changing the
requested flags to include encryption support.
In postmaster, pull GSSAPI authorization checking into a shared
function. Also share the initiator name between the encryption and
non-encryption codepaths.
For HBA, add "hostgssenc" and "hostnogssenc" entries that behave
similarly to their SSL counterparts. "hostgssenc" requires either
"gss", "trust", or "reject" for its authentication.
Similarly, add a "gssencmode" parameter to libpq. Supported values are
"disable", "require", and "prefer". Notably, negotiation will only be
attempted if credentials can be acquired. Move credential acquisition
into its own function to support this behavior.
Add a simple pg_stat_gssapi view similar to pg_stat_ssl, for monitoring
if GSSAPI authentication was used, what principal was used, and if
encryption is being used on the connection.
Finally, add documentation for everything new, and update existing
documentation on connection security.
Thanks to Michael Paquier for the Windows fixes.
Author: Robbie Harwood, with changes to the read/write functions by me.
Reviewed in various forms and at different times by: Michael Paquier,
Andres Freund, David Steele.
Discussion: https://www.postgresql.org/message-id/flat/jlg1tgq1ktm.fsf@thriss.redhat.com
2019-04-03 21:02:33 +02:00
linkend="gssapi-auth"/> for details. It can be used in conjunction
with GSSAPI encryption.
2007-07-18 14:00:47 +02:00
</para>
</listitem>
</varlistentry>
2007-07-23 12:16:54 +02:00
<varlistentry>
2017-10-09 03:44:17 +02:00
<term><literal>sspi</literal></term>
2007-07-23 12:16:54 +02:00
<listitem>
<para>
Use SSPI to authenticate the user. This is only
available on Windows. See <xref
2017-11-23 15:39:47 +01:00
linkend="sspi-auth"/> for details.
2007-07-23 12:16:54 +02:00
</para>
</listitem>
</varlistentry>
2000-09-06 21:54:52 +02:00
<varlistentry>
2017-10-09 03:44:17 +02:00
<term><literal>ident</literal></term>
2000-09-06 21:54:52 +02:00
<listitem>
2002-09-14 20:35:46 +02:00
<para>
2011-03-19 18:44:35 +01:00
Obtain the operating system user name of the client
by contacting the ident server on the client
and check if it matches the requested database user name.
Ident authentication can only be used on TCP/IP
connections. When specified for local connections, peer
authentication will be used instead.
2017-11-23 15:39:47 +01:00
See <xref linkend="auth-ident"/> for details.
2000-09-06 21:54:52 +02:00
</para>
</listitem>
</varlistentry>
2001-09-06 05:23:38 +02:00
2011-03-19 18:44:35 +01:00
<varlistentry>
2017-10-09 03:44:17 +02:00
<term><literal>peer</literal></term>
2011-03-19 18:44:35 +01:00
<listitem>
<para>
Replace use of credential control messages with getsockopt(LOCAL_PEERCRED).
It turns out the reason we hadn't found out about the portability issues
with our credential-control-message code is that almost no modern platforms
use that code at all; the ones that used to need it now offer getpeereid(),
which we choose first. The last holdout was NetBSD, and they added
getpeereid() as of 5.0. So far as I can tell, the only live platform on
which that code was being exercised was Debian/kFreeBSD, ie, FreeBSD kernel
with Linux userland --- since glibc doesn't provide getpeereid(), we fell
back to the control message code. However, the FreeBSD kernel provides a
LOCAL_PEERCRED socket parameter that's functionally equivalent to Linux's
SO_PEERCRED. That is both much simpler to use than control messages, and
superior because it doesn't require receiving a message from the other end
at just the right time.
Therefore, add code to use LOCAL_PEERCRED when necessary, and rip out all
the credential-control-message code in the backend. (libpq still has such
code so that it can still talk to pre-9.1 servers ... but eventually we can
get rid of it there too.) Clean up related autoconf probes, too.
This means that libpq's requirepeer parameter now works on exactly the same
platforms where the backend supports peer authentication, so adjust the
documentation accordingly.
2011-05-31 22:10:46 +02:00
Obtain the client's operating system user name from the operating
system and check if it matches the requested database user name.
2011-03-19 18:44:35 +01:00
This is only available for local connections.
2017-11-23 15:39:47 +01:00
See <xref linkend="auth-peer"/> for details.
2011-03-19 18:44:35 +01:00
</para>
</listitem>
</varlistentry>
2006-06-16 17:16:16 +02:00
<varlistentry>
2017-10-09 03:44:17 +02:00
<term><literal>ldap</literal></term>
2006-06-16 17:16:16 +02:00
<listitem>
<para>
2017-10-09 03:44:17 +02:00
Authenticate using an <acronym>LDAP</acronym> server. See <xref
2017-11-23 15:39:47 +01:00
linkend="auth-ldap"/> for details.
2006-06-16 17:16:16 +02:00
</para>
</listitem>
</varlistentry>
2010-01-27 13:12:00 +01:00
<varlistentry>
2017-10-09 03:44:17 +02:00
<term><literal>radius</literal></term>
2010-01-27 13:12:00 +01:00
<listitem>
<para>
Authenticate using a RADIUS server. See <xref
2017-11-23 15:39:47 +01:00
linkend="auth-radius"/> for details.
2010-01-27 13:12:00 +01:00
</para>
</listitem>
</varlistentry>
2008-11-20 12:48:26 +01:00
<varlistentry>
2017-10-09 03:44:17 +02:00
<term><literal>cert</literal></term>
2008-11-20 12:48:26 +01:00
<listitem>
<para>
Authenticate using SSL client certificates. See
2017-11-23 15:39:47 +01:00
<xref linkend="auth-cert"/> for details.
2008-11-20 12:48:26 +01:00
</para>
</listitem>
</varlistentry>
2001-09-06 05:23:38 +02:00
<varlistentry>
2017-10-09 03:44:17 +02:00
<term><literal>pam</literal></term>
2001-09-06 05:23:38 +02:00
<listitem>
<para>
2002-09-14 20:35:46 +02:00
Authenticate using the Pluggable Authentication Modules
(PAM) service provided by the operating system. See <xref
2017-11-23 15:39:47 +01:00
linkend="auth-pam"/> for details.
2001-09-06 05:23:38 +02:00
</para>
</listitem>
</varlistentry>
2016-04-08 19:51:54 +02:00
<varlistentry>
2017-10-09 03:44:17 +02:00
<term><literal>bsd</literal></term>
2016-04-08 19:51:54 +02:00
<listitem>
<para>
Authenticate using the BSD Authentication service provided by the
2017-11-23 15:39:47 +01:00
operating system. See <xref linkend="auth-bsd"/> for details.
2016-04-08 19:51:54 +02:00
</para>
</listitem>
</varlistentry>
2000-09-06 21:54:52 +02:00
</variablelist>
2000-06-18 23:24:54 +02:00
</para>
</listitem>
</varlistentry>
2002-09-14 20:35:46 +02:00
<varlistentry>
2008-10-23 15:31:10 +02:00
<term><replaceable>auth-options</replaceable></term>
2002-09-14 20:35:46 +02:00
<listitem>
<para>
2017-10-09 03:44:17 +02:00
After the <replaceable>auth-method</replaceable> field, there can be field(s) of
the form <replaceable>name</replaceable><literal>=</literal><replaceable>value</replaceable> that
2009-05-16 23:17:21 +02:00
specify options for the authentication method. Details about which
2010-05-27 01:49:19 +02:00
options are available for which authentication methods appear below.
2002-09-14 20:35:46 +02:00
</para>
2016-07-16 20:12:44 +02:00
<para>
2021-03-29 21:31:22 +02:00
In addition to the method-specific options listed below, there is a
2017-10-09 03:44:17 +02:00
method-independent authentication option <literal>clientcert</literal>, which
2019-03-09 21:09:10 +01:00
can be specified in any <literal>hostssl</literal> record.
This option can be set to <literal>verify-ca</literal> or
<literal>verify-full</literal>. Both options require the client
to present a valid (trusted) SSL certificate, while
<literal>verify-full</literal> additionally enforces that the
<literal>cn</literal> (Common Name) in the certificate matches
the username or an applicable mapping.
2019-08-20 05:36:31 +02:00
This behavior is similar to the <literal>cert</literal> authentication
method (see <xref linkend="auth-cert"/>) but enables pairing
2019-03-09 21:09:10 +01:00
the verification of client certificates with any authentication
method that supports <literal>hostssl</literal> entries.
2016-07-16 20:12:44 +02:00
</para>
2021-03-29 21:31:22 +02:00
<para>
On any record using client certificate authentication (i.e. one
using the <literal>cert</literal> authentication method or one
using the <literal>clientcert</literal> option), you can specify
which part of the client certificate credentials to match using
the <literal>clientname</literal> option. This option can have one
of two values. If you specify <literal>clientname=CN</literal>, which
is the default, the username is matched against the certificate's
<literal>Common Name (CN)</literal>. If instead you specify
<literal>clientname=DN</literal> the username is matched against the
entire <literal>Distinguished Name (DN)</literal> of the certificate.
This option is probably best used in conjunction with a username map.
The comparison is done with the <literal>DN</literal> in
2024-04-10 13:53:25 +02:00
<ulink url="https://datatracker.ietf.org/doc/html/rfc2253">RFC 2253</ulink>
2021-03-29 21:31:22 +02:00
format. To see the <literal>DN</literal> of a client certificate
in this format, do
<programlisting>
2024-02-01 09:36:34 +01:00
openssl x509 -in myclient.crt -noout -subject -nameopt RFC2253 | sed "s/^subject=//"
2021-03-29 21:31:22 +02:00
</programlisting>
Care needs to be taken when using this option, especially when using
regular expression matching against the <literal>DN</literal>.
</para>
2002-09-14 20:35:46 +02:00
</listitem>
</varlistentry>
Add support for file inclusions in HBA and ident configuration files
pg_hba.conf and pg_ident.conf gain support for three record keywords:
- "include", to include a file.
- "include_if_exists", to include a file, ignoring it if missing.
- "include_dir", to include a directory of files. These are classified
by name (C locale, mostly) and need to be prefixed by ".conf", hence
following the same rules as GUCs.
This commit relies on the refactoring pieces done in efc9816, ad6c528,
783e8c6 and 1b73d0b, adding a small wrapper to build a list of
TokenizedAuthLines (tokenize_include_file), and the code is shaped to
offer some symmetry with what is done for GUCs with the same options.
pg_hba_file_rules and pg_ident_file_mappings gain a new field called
file_name, to track from which file a record is located, taking
advantage of the addition of rule_number in c591300 to offer an
organized view of the HBA or ident records loaded.
Bump catalog version.
Author: Julien Rouhaud
Reviewed-by: Michael Paquier
Discussion: https://postgr.es/m/20220223045959.35ipdsvbxcstrhya@jrouhaud
2022-11-24 05:51:34 +01:00
<varlistentry>
<term><literal>include</literal></term>
<listitem>
<para>
This line will be replaced by the contents of the given file.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><literal>include_if_exists</literal></term>
<listitem>
<para>
This line will be replaced by the content of the given file if the
file exists. Otherwise, a message is logged to indicate that the file
has been skipped.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><literal>include_dir</literal></term>
<listitem>
<para>
This line will be replaced by the contents of all the files found in
the directory, if they don't start with a <literal>.</literal> and end
with <literal>.conf</literal>, processed in file name order (according
to C locale rules, i.e., numbers before letters, and uppercase letters
before lowercase ones).
</para>
</listitem>
</varlistentry>
2000-06-18 23:24:54 +02:00
</variablelist>
2001-11-02 19:39:57 +01:00
</para>
2000-06-18 23:24:54 +02:00
2001-11-02 19:39:57 +01:00
<para>
2017-10-09 03:44:17 +02:00
Files included by <literal>@</literal> constructs are read as lists of names,
2004-12-27 20:19:24 +01:00
which can be separated by either whitespace or commas. Comments are
introduced by <literal>#</literal>, just as in
2017-10-09 03:44:17 +02:00
<filename>pg_hba.conf</filename>, and nested <literal>@</literal> constructs are
allowed. Unless the file name following <literal>@</literal> is an absolute
2004-12-27 20:19:24 +01:00
path, it is taken to be relative to the directory containing the
referencing file.
</para>
<para>
2001-11-02 19:39:57 +01:00
Since the <filename>pg_hba.conf</filename> records are examined
2001-11-28 21:49:10 +01:00
sequentially for each connection attempt, the order of the records is
2002-04-04 06:25:54 +02:00
significant. Typically, earlier records will have tight connection
match parameters and weaker authentication methods, while later
records will have looser match parameters and stronger authentication
2017-10-09 03:44:17 +02:00
methods. For example, one might wish to use <literal>trust</literal>
2003-03-13 02:30:29 +01:00
authentication for local TCP/IP connections but require a password for
remote TCP/IP connections. In this case a record specifying
2017-10-09 03:44:17 +02:00
<literal>trust</literal> authentication for connections from 127.0.0.1 would
2002-04-04 06:25:54 +02:00
appear before a record specifying password authentication for a wider
range of allowed client IP addresses.
2000-06-18 23:24:54 +02:00
</para>
2006-04-30 23:15:33 +02:00
<tip>
<para>
To connect to a particular database, a user must not only pass the
<filename>pg_hba.conf</filename> checks, but must have the
2017-10-09 03:44:17 +02:00
<literal>CONNECT</literal> privilege for the database. If you wish to
2006-04-30 23:15:33 +02:00
restrict which users can connect to which databases, it's usually
2017-10-09 03:44:17 +02:00
easier to control this by granting/revoking <literal>CONNECT</literal> privilege
2010-02-03 18:25:06 +01:00
than to put the rules in <filename>pg_hba.conf</filename> entries.
2006-04-30 23:15:33 +02:00
</para>
</tip>
2000-06-18 23:24:54 +02:00
<para>
2004-12-27 00:06:56 +01:00
Some examples of <filename>pg_hba.conf</filename> entries are shown in
2017-11-23 15:39:47 +01:00
<xref linkend="example-pg-hba.conf"/>. See the next section for details on the
2000-06-18 23:24:54 +02:00
different authentication methods.
2003-03-13 02:30:29 +01:00
</para>
2000-06-18 23:24:54 +02:00
<example id="example-pg-hba.conf">
2011-01-29 19:00:18 +01:00
<title>Example <filename>pg_hba.conf</filename> Entries</title>
2000-06-18 23:24:54 +02:00
<programlisting>
2010-02-03 18:25:06 +01:00
# Allow any user on the local system to connect to any database with
2005-08-15 01:35:38 +02:00
# any database user name using Unix-domain sockets (the default for local
2002-09-14 20:35:46 +02:00
# connections).
#
2010-10-15 21:53:39 +02:00
# TYPE DATABASE USER ADDRESS METHOD
2010-01-26 07:45:31 +01:00
local all all trust
2002-09-14 20:35:46 +02:00
# The same using local loopback TCP/IP connections.
#
2010-10-15 21:53:39 +02:00
# TYPE DATABASE USER ADDRESS METHOD
2010-01-26 07:45:31 +01:00
host all all 127.0.0.1/32 trust
2002-09-14 20:35:46 +02:00
2009-05-16 23:17:21 +02:00
# The same as the previous line, but using a separate netmask column
2003-08-17 06:39:11 +02:00
#
2010-01-26 07:45:31 +01:00
# TYPE DATABASE USER IP-ADDRESS IP-MASK METHOD
host all all 127.0.0.1 255.255.255.255 trust
2003-08-17 06:39:11 +02:00
2010-10-15 21:53:39 +02:00
# The same over IPv6.
#
# TYPE DATABASE USER ADDRESS METHOD
host all all ::1/128 trust
# The same using a host name (would typically cover both IPv4 and IPv6).
#
# TYPE DATABASE USER ADDRESS METHOD
host all all localhost trust
Add support for regexps on database and user entries in pg_hba.conf
As of this commit, any database or user entry beginning with a slash (/)
is considered as a regular expression. This is particularly useful for
users, as now there is no clean way to match pattern on multiple HBA
lines. For example, a user name mapping with a regular expression needs
first to match with a HBA line, and we would skip the follow-up HBA
entries if the ident regexp does *not* match with what has matched in
the HBA line.
pg_hba.conf is able to handle multiple databases and roles with a
comma-separated list of these, hence individual regular expressions that
include commas need to be double-quoted.
At authentication time, user and database names are now checked in the
following order:
- Arbitrary keywords (like "all", the ones beginning by '+' for
membership check), that we know will never have a regexp. A fancy case
is for physical WAL senders, we *have* to only match "replication" for
the database.
- Regular expression matching.
- Exact match.
The previous logic did the same, but without the regexp step.
We have discussed as well the possibility to support regexp pattern
matching for host names, but these happen to lead to tricky issues based
on what I understand, particularly with host entries that have CIDRs.
This commit relies heavily on the refactoring done in a903971 and
fc579e1, so as the amount of code required to compile and execute
regular expressions is now minimal. When parsing pg_hba.conf, all the
computed regexps needs to explicitely free()'d, same as pg_ident.conf.
Documentation and TAP tests are added to cover this feature, including
cases where the regexps use commas (for clarity in the docs, coverage
for the parsing logic in the tests).
Note that this introduces a breakage with older versions, where a
database or user name beginning with a slash are treated as something to
check for an equal match. Per discussion, we have discarded this as
being much of an issue in practice as it would require a cluster to
have database and/or role names that begin with a slash, as well as HBA
entries using these. Hence, the consistency gained with regexps in
pg_ident.conf is more appealing in the long term.
**This compatibility change should be mentioned in the release notes.**
Author: Bertrand Drouvot
Reviewed-by: Jacob Champion, Tom Lane, Michael Paquier
Discussion: https://postgr.es/m/fff0d7c1-8ad4-76a1-9db3-0ab6ec338bf7@amazon.com
2022-10-24 04:45:31 +02:00
# The same using a regular expression for DATABASE, that allows connection
2023-04-12 06:03:09 +02:00
# to the database db1, db2 and any databases with a name beginning with "db"
Add support for regexps on database and user entries in pg_hba.conf
As of this commit, any database or user entry beginning with a slash (/)
is considered as a regular expression. This is particularly useful for
users, as now there is no clean way to match pattern on multiple HBA
lines. For example, a user name mapping with a regular expression needs
first to match with a HBA line, and we would skip the follow-up HBA
entries if the ident regexp does *not* match with what has matched in
the HBA line.
pg_hba.conf is able to handle multiple databases and roles with a
comma-separated list of these, hence individual regular expressions that
include commas need to be double-quoted.
At authentication time, user and database names are now checked in the
following order:
- Arbitrary keywords (like "all", the ones beginning by '+' for
membership check), that we know will never have a regexp. A fancy case
is for physical WAL senders, we *have* to only match "replication" for
the database.
- Regular expression matching.
- Exact match.
The previous logic did the same, but without the regexp step.
We have discussed as well the possibility to support regexp pattern
matching for host names, but these happen to lead to tricky issues based
on what I understand, particularly with host entries that have CIDRs.
This commit relies heavily on the refactoring done in a903971 and
fc579e1, so as the amount of code required to compile and execute
regular expressions is now minimal. When parsing pg_hba.conf, all the
computed regexps needs to explicitely free()'d, same as pg_ident.conf.
Documentation and TAP tests are added to cover this feature, including
cases where the regexps use commas (for clarity in the docs, coverage
for the parsing logic in the tests).
Note that this introduces a breakage with older versions, where a
database or user name beginning with a slash are treated as something to
check for an equal match. Per discussion, we have discarded this as
being much of an issue in practice as it would require a cluster to
have database and/or role names that begin with a slash, as well as HBA
entries using these. Hence, the consistency gained with regexps in
pg_ident.conf is more appealing in the long term.
**This compatibility change should be mentioned in the release notes.**
Author: Bertrand Drouvot
Reviewed-by: Jacob Champion, Tom Lane, Michael Paquier
Discussion: https://postgr.es/m/fff0d7c1-8ad4-76a1-9db3-0ab6ec338bf7@amazon.com
2022-10-24 04:45:31 +02:00
# and finishing with a number using two to four digits (like "db1234" or
# "db12").
#
# TYPE DATABASE USER ADDRESS METHOD
local db1,"/^db\d{2,4}$",db2 all localhost trust
2002-09-14 20:35:46 +02:00
# Allow any user from any host with IP address 192.168.93.x to connect
2005-06-21 06:02:34 +02:00
# to database "postgres" as the same user name that ident reports for
2010-02-03 18:25:06 +01:00
# the connection (typically the operating system user name).
2009-05-16 23:17:21 +02:00
#
2010-10-15 21:53:39 +02:00
# TYPE DATABASE USER ADDRESS METHOD
2010-01-26 07:45:31 +01:00
host postgres all 192.168.93.0/24 ident
2002-09-14 20:35:46 +02:00
2009-05-16 23:17:21 +02:00
# Allow any user from host 192.168.12.10 to connect to database
2005-06-21 06:02:34 +02:00
# "postgres" if the user's password is correctly supplied.
2009-05-16 23:17:21 +02:00
#
2010-10-15 21:53:39 +02:00
# TYPE DATABASE USER ADDRESS METHOD
2017-04-18 13:50:50 +02:00
host postgres all 192.168.12.10/32 scram-sha-256
2002-09-14 20:35:46 +02:00
2010-10-24 14:54:00 +02:00
# Allow any user from hosts in the example.com domain to connect to
# any database if the user's password is correctly supplied.
#
Allow SCRAM authentication, when pg_hba.conf says 'md5'.
If a user has a SCRAM verifier in pg_authid.rolpassword, there's no reason
we cannot attempt to perform SCRAM authentication instead of MD5. The worst
that can happen is that the client doesn't support SCRAM, and the
authentication will fail. But previously, it would fail for sure, because
we would not even try. SCRAM is strictly more secure than MD5, so there's
no harm in trying it. This allows for a more graceful transition from MD5
passwords to SCRAM, as user passwords can be changed to SCRAM verifiers
incrementally, without changing pg_hba.conf.
Refactor the code in auth.c to support that better. Notably, we now have to
look up the user's pg_authid entry before sending the password challenge,
also when performing MD5 authentication. Also simplify the concept of a
"doomed" authentication. Previously, if a user had a password, but it had
expired, we still performed SCRAM authentication (but always returned error
at the end) using the salt and iteration count from the expired password.
Now we construct a fake salt, like we do when the user doesn't have a
password or doesn't exist at all. That simplifies get_role_password(), and
we can don't need to distinguish the "user has expired password", and
"user does not exist" cases in auth.c.
On second thoughts, also rename uaSASL to uaSCRAM. It refers to the
mechanism specified in pg_hba.conf, and while we use SASL for SCRAM
authentication at the protocol level, the mechanism should be called SCRAM,
not SASL. As a comparison, we have uaLDAP, even though it looks like the
plain 'password' authentication at the protocol level.
Discussion: https://www.postgresql.org/message-id/6425.1489506016@sss.pgh.pa.us
Reviewed-by: Michael Paquier
2017-03-24 12:32:21 +01:00
# Require SCRAM authentication for most users, but make an exception
# for user 'mike', who uses an older client that doesn't support SCRAM
# authentication.
Support SCRAM-SHA-256 authentication (RFC 5802 and 7677).
This introduces a new generic SASL authentication method, similar to the
GSS and SSPI methods. The server first tells the client which SASL
authentication mechanism to use, and then the mechanism-specific SASL
messages are exchanged in AuthenticationSASLcontinue and PasswordMessage
messages. Only SCRAM-SHA-256 is supported at the moment, but this allows
adding more SASL mechanisms in the future, without changing the overall
protocol.
Support for channel binding, aka SCRAM-SHA-256-PLUS is left for later.
The SASLPrep algorithm, for pre-processing the password, is not yet
implemented. That could cause trouble, if you use a password with
non-ASCII characters, and a client library that does implement SASLprep.
That will hopefully be added later.
Authorization identities, as specified in the SCRAM-SHA-256 specification,
are ignored. SET SESSION AUTHORIZATION provides more or less the same
functionality, anyway.
If a user doesn't exist, perform a "mock" authentication, by constructing
an authentic-looking challenge on the fly. The challenge is derived from
a new system-wide random value, "mock authentication nonce", which is
created at initdb, and stored in the control file. We go through these
motions, in order to not give away the information on whether the user
exists, to unauthenticated users.
Bumps PG_CONTROL_VERSION, because of the new field in control file.
Patch by Michael Paquier and Heikki Linnakangas, reviewed at different
stages by Robert Haas, Stephen Frost, David Steele, Aleksander Alekseev,
and many others.
Discussion: https://www.postgresql.org/message-id/CAB7nPqRbR3GmFYdedCAhzukfKrgBLTLtMvENOmPrVWREsZkF8g%40mail.gmail.com
Discussion: https://www.postgresql.org/message-id/CAB7nPqSMXU35g%3DW9X74HVeQp0uvgJxvYOuA4A-A3M%2B0wfEBv-w%40mail.gmail.com
Discussion: https://www.postgresql.org/message-id/55192AFE.6080106@iki.fi
2017-03-07 13:25:40 +01:00
#
2010-10-24 14:54:00 +02:00
# TYPE DATABASE USER ADDRESS METHOD
Allow SCRAM authentication, when pg_hba.conf says 'md5'.
If a user has a SCRAM verifier in pg_authid.rolpassword, there's no reason
we cannot attempt to perform SCRAM authentication instead of MD5. The worst
that can happen is that the client doesn't support SCRAM, and the
authentication will fail. But previously, it would fail for sure, because
we would not even try. SCRAM is strictly more secure than MD5, so there's
no harm in trying it. This allows for a more graceful transition from MD5
passwords to SCRAM, as user passwords can be changed to SCRAM verifiers
incrementally, without changing pg_hba.conf.
Refactor the code in auth.c to support that better. Notably, we now have to
look up the user's pg_authid entry before sending the password challenge,
also when performing MD5 authentication. Also simplify the concept of a
"doomed" authentication. Previously, if a user had a password, but it had
expired, we still performed SCRAM authentication (but always returned error
at the end) using the salt and iteration count from the expired password.
Now we construct a fake salt, like we do when the user doesn't have a
password or doesn't exist at all. That simplifies get_role_password(), and
we can don't need to distinguish the "user has expired password", and
"user does not exist" cases in auth.c.
On second thoughts, also rename uaSASL to uaSCRAM. It refers to the
mechanism specified in pg_hba.conf, and while we use SASL for SCRAM
authentication at the protocol level, the mechanism should be called SCRAM,
not SASL. As a comparison, we have uaLDAP, even though it looks like the
plain 'password' authentication at the protocol level.
Discussion: https://www.postgresql.org/message-id/6425.1489506016@sss.pgh.pa.us
Reviewed-by: Michael Paquier
2017-03-24 12:32:21 +01:00
host all mike .example.com md5
2017-04-18 13:50:50 +02:00
host all all .example.com scram-sha-256
2010-10-24 14:54:00 +02:00
GSSAPI encryption support
On both the frontend and backend, prepare for GSSAPI encryption
support by moving common code for error handling into a separate file.
Fix a TODO for handling multiple status messages in the process.
Eliminate the OIDs, which have not been needed for some time.
Add frontend and backend encryption support functions. Keep the
context initiation for authentication-only separate on both the
frontend and backend in order to avoid concerns about changing the
requested flags to include encryption support.
In postmaster, pull GSSAPI authorization checking into a shared
function. Also share the initiator name between the encryption and
non-encryption codepaths.
For HBA, add "hostgssenc" and "hostnogssenc" entries that behave
similarly to their SSL counterparts. "hostgssenc" requires either
"gss", "trust", or "reject" for its authentication.
Similarly, add a "gssencmode" parameter to libpq. Supported values are
"disable", "require", and "prefer". Notably, negotiation will only be
attempted if credentials can be acquired. Move credential acquisition
into its own function to support this behavior.
Add a simple pg_stat_gssapi view similar to pg_stat_ssl, for monitoring
if GSSAPI authentication was used, what principal was used, and if
encryption is being used on the connection.
Finally, add documentation for everything new, and update existing
documentation on connection security.
Thanks to Michael Paquier for the Windows fixes.
Author: Robbie Harwood, with changes to the read/write functions by me.
Reviewed in various forms and at different times by: Michael Paquier,
Andres Freund, David Steele.
Discussion: https://www.postgresql.org/message-id/flat/jlg1tgq1ktm.fsf@thriss.redhat.com
2019-04-03 21:02:33 +02:00
# In the absence of preceding "host" lines, these three lines will
2009-05-16 23:17:21 +02:00
# reject all connections from 192.168.54.1 (since that entry will be
GSSAPI encryption support
On both the frontend and backend, prepare for GSSAPI encryption
support by moving common code for error handling into a separate file.
Fix a TODO for handling multiple status messages in the process.
Eliminate the OIDs, which have not been needed for some time.
Add frontend and backend encryption support functions. Keep the
context initiation for authentication-only separate on both the
frontend and backend in order to avoid concerns about changing the
requested flags to include encryption support.
In postmaster, pull GSSAPI authorization checking into a shared
function. Also share the initiator name between the encryption and
non-encryption codepaths.
For HBA, add "hostgssenc" and "hostnogssenc" entries that behave
similarly to their SSL counterparts. "hostgssenc" requires either
"gss", "trust", or "reject" for its authentication.
Similarly, add a "gssencmode" parameter to libpq. Supported values are
"disable", "require", and "prefer". Notably, negotiation will only be
attempted if credentials can be acquired. Move credential acquisition
into its own function to support this behavior.
Add a simple pg_stat_gssapi view similar to pg_stat_ssl, for monitoring
if GSSAPI authentication was used, what principal was used, and if
encryption is being used on the connection.
Finally, add documentation for everything new, and update existing
documentation on connection security.
Thanks to Michael Paquier for the Windows fixes.
Author: Robbie Harwood, with changes to the read/write functions by me.
Reviewed in various forms and at different times by: Michael Paquier,
Andres Freund, David Steele.
Discussion: https://www.postgresql.org/message-id/flat/jlg1tgq1ktm.fsf@thriss.redhat.com
2019-04-03 21:02:33 +02:00
# matched first), but allow GSSAPI-encrypted connections from anywhere else
# on the Internet. The zero mask causes no bits of the host IP address to
2019-04-08 22:27:35 +02:00
# be considered, so it matches any host. Unencrypted GSSAPI connections
GSSAPI encryption support
On both the frontend and backend, prepare for GSSAPI encryption
support by moving common code for error handling into a separate file.
Fix a TODO for handling multiple status messages in the process.
Eliminate the OIDs, which have not been needed for some time.
Add frontend and backend encryption support functions. Keep the
context initiation for authentication-only separate on both the
frontend and backend in order to avoid concerns about changing the
requested flags to include encryption support.
In postmaster, pull GSSAPI authorization checking into a shared
function. Also share the initiator name between the encryption and
non-encryption codepaths.
For HBA, add "hostgssenc" and "hostnogssenc" entries that behave
similarly to their SSL counterparts. "hostgssenc" requires either
"gss", "trust", or "reject" for its authentication.
Similarly, add a "gssencmode" parameter to libpq. Supported values are
"disable", "require", and "prefer". Notably, negotiation will only be
attempted if credentials can be acquired. Move credential acquisition
into its own function to support this behavior.
Add a simple pg_stat_gssapi view similar to pg_stat_ssl, for monitoring
if GSSAPI authentication was used, what principal was used, and if
encryption is being used on the connection.
Finally, add documentation for everything new, and update existing
documentation on connection security.
Thanks to Michael Paquier for the Windows fixes.
Author: Robbie Harwood, with changes to the read/write functions by me.
Reviewed in various forms and at different times by: Michael Paquier,
Andres Freund, David Steele.
Discussion: https://www.postgresql.org/message-id/flat/jlg1tgq1ktm.fsf@thriss.redhat.com
2019-04-03 21:02:33 +02:00
# (which "fall through" to the third line since "hostgssenc" only matches
2019-04-08 22:27:35 +02:00
# encrypted GSSAPI connections) are allowed, but only from 192.168.12.10.
2009-05-16 23:17:21 +02:00
#
2010-10-15 21:53:39 +02:00
# TYPE DATABASE USER ADDRESS METHOD
2010-01-26 07:45:31 +01:00
host all all 192.168.54.1/32 reject
GSSAPI encryption support
On both the frontend and backend, prepare for GSSAPI encryption
support by moving common code for error handling into a separate file.
Fix a TODO for handling multiple status messages in the process.
Eliminate the OIDs, which have not been needed for some time.
Add frontend and backend encryption support functions. Keep the
context initiation for authentication-only separate on both the
frontend and backend in order to avoid concerns about changing the
requested flags to include encryption support.
In postmaster, pull GSSAPI authorization checking into a shared
function. Also share the initiator name between the encryption and
non-encryption codepaths.
For HBA, add "hostgssenc" and "hostnogssenc" entries that behave
similarly to their SSL counterparts. "hostgssenc" requires either
"gss", "trust", or "reject" for its authentication.
Similarly, add a "gssencmode" parameter to libpq. Supported values are
"disable", "require", and "prefer". Notably, negotiation will only be
attempted if credentials can be acquired. Move credential acquisition
into its own function to support this behavior.
Add a simple pg_stat_gssapi view similar to pg_stat_ssl, for monitoring
if GSSAPI authentication was used, what principal was used, and if
encryption is being used on the connection.
Finally, add documentation for everything new, and update existing
documentation on connection security.
Thanks to Michael Paquier for the Windows fixes.
Author: Robbie Harwood, with changes to the read/write functions by me.
Reviewed in various forms and at different times by: Michael Paquier,
Andres Freund, David Steele.
Discussion: https://www.postgresql.org/message-id/flat/jlg1tgq1ktm.fsf@thriss.redhat.com
2019-04-03 21:02:33 +02:00
hostgssenc all all 0.0.0.0/0 gss
host all all 192.168.12.10/32 gss
2002-09-14 20:35:46 +02:00
# Allow users from 192.168.x.x hosts to connect to any database, if
# they pass the ident check. If, for example, ident says the user is
# "bryanh" and he requests to connect as PostgreSQL user "guest1", the
# connection is allowed if there is an entry in pg_ident.conf for map
# "omicron" that says "bryanh" is allowed to connect as "guest1".
#
2010-10-15 21:53:39 +02:00
# TYPE DATABASE USER ADDRESS METHOD
2010-01-26 07:45:31 +01:00
host all all 192.168.0.0/16 ident map=omicron
2002-09-14 20:35:46 +02:00
Add support for regexps on database and user entries in pg_hba.conf
As of this commit, any database or user entry beginning with a slash (/)
is considered as a regular expression. This is particularly useful for
users, as now there is no clean way to match pattern on multiple HBA
lines. For example, a user name mapping with a regular expression needs
first to match with a HBA line, and we would skip the follow-up HBA
entries if the ident regexp does *not* match with what has matched in
the HBA line.
pg_hba.conf is able to handle multiple databases and roles with a
comma-separated list of these, hence individual regular expressions that
include commas need to be double-quoted.
At authentication time, user and database names are now checked in the
following order:
- Arbitrary keywords (like "all", the ones beginning by '+' for
membership check), that we know will never have a regexp. A fancy case
is for physical WAL senders, we *have* to only match "replication" for
the database.
- Regular expression matching.
- Exact match.
The previous logic did the same, but without the regexp step.
We have discussed as well the possibility to support regexp pattern
matching for host names, but these happen to lead to tricky issues based
on what I understand, particularly with host entries that have CIDRs.
This commit relies heavily on the refactoring done in a903971 and
fc579e1, so as the amount of code required to compile and execute
regular expressions is now minimal. When parsing pg_hba.conf, all the
computed regexps needs to explicitely free()'d, same as pg_ident.conf.
Documentation and TAP tests are added to cover this feature, including
cases where the regexps use commas (for clarity in the docs, coverage
for the parsing logic in the tests).
Note that this introduces a breakage with older versions, where a
database or user name beginning with a slash are treated as something to
check for an equal match. Per discussion, we have discarded this as
being much of an issue in practice as it would require a cluster to
have database and/or role names that begin with a slash, as well as HBA
entries using these. Hence, the consistency gained with regexps in
pg_ident.conf is more appealing in the long term.
**This compatibility change should be mentioned in the release notes.**
Author: Bertrand Drouvot
Reviewed-by: Jacob Champion, Tom Lane, Michael Paquier
Discussion: https://postgr.es/m/fff0d7c1-8ad4-76a1-9db3-0ab6ec338bf7@amazon.com
2022-10-24 04:45:31 +02:00
# If these are the only four lines for local connections, they will
2002-09-14 20:35:46 +02:00
# allow local users to connect only to their own databases (databases
Add support for regexps on database and user entries in pg_hba.conf
As of this commit, any database or user entry beginning with a slash (/)
is considered as a regular expression. This is particularly useful for
users, as now there is no clean way to match pattern on multiple HBA
lines. For example, a user name mapping with a regular expression needs
first to match with a HBA line, and we would skip the follow-up HBA
entries if the ident regexp does *not* match with what has matched in
the HBA line.
pg_hba.conf is able to handle multiple databases and roles with a
comma-separated list of these, hence individual regular expressions that
include commas need to be double-quoted.
At authentication time, user and database names are now checked in the
following order:
- Arbitrary keywords (like "all", the ones beginning by '+' for
membership check), that we know will never have a regexp. A fancy case
is for physical WAL senders, we *have* to only match "replication" for
the database.
- Regular expression matching.
- Exact match.
The previous logic did the same, but without the regexp step.
We have discussed as well the possibility to support regexp pattern
matching for host names, but these happen to lead to tricky issues based
on what I understand, particularly with host entries that have CIDRs.
This commit relies heavily on the refactoring done in a903971 and
fc579e1, so as the amount of code required to compile and execute
regular expressions is now minimal. When parsing pg_hba.conf, all the
computed regexps needs to explicitely free()'d, same as pg_ident.conf.
Documentation and TAP tests are added to cover this feature, including
cases where the regexps use commas (for clarity in the docs, coverage
for the parsing logic in the tests).
Note that this introduces a breakage with older versions, where a
database or user name beginning with a slash are treated as something to
check for an equal match. Per discussion, we have discarded this as
being much of an issue in practice as it would require a cluster to
have database and/or role names that begin with a slash, as well as HBA
entries using these. Hence, the consistency gained with regexps in
pg_ident.conf is more appealing in the long term.
**This compatibility change should be mentioned in the release notes.**
Author: Bertrand Drouvot
Reviewed-by: Jacob Champion, Tom Lane, Michael Paquier
Discussion: https://postgr.es/m/fff0d7c1-8ad4-76a1-9db3-0ab6ec338bf7@amazon.com
2022-10-24 04:45:31 +02:00
# with the same name as their database user name) except for users whose
# name end with "helpdesk", administrators and members of role "support",
# who can connect to all databases. The file $PGDATA/admins contains a
# list of names of administrators. Passwords are required in all cases.
2002-09-14 20:35:46 +02:00
#
2010-10-15 21:53:39 +02:00
# TYPE DATABASE USER ADDRESS METHOD
2010-01-26 07:45:31 +01:00
local sameuser all md5
Add support for regexps on database and user entries in pg_hba.conf
As of this commit, any database or user entry beginning with a slash (/)
is considered as a regular expression. This is particularly useful for
users, as now there is no clean way to match pattern on multiple HBA
lines. For example, a user name mapping with a regular expression needs
first to match with a HBA line, and we would skip the follow-up HBA
entries if the ident regexp does *not* match with what has matched in
the HBA line.
pg_hba.conf is able to handle multiple databases and roles with a
comma-separated list of these, hence individual regular expressions that
include commas need to be double-quoted.
At authentication time, user and database names are now checked in the
following order:
- Arbitrary keywords (like "all", the ones beginning by '+' for
membership check), that we know will never have a regexp. A fancy case
is for physical WAL senders, we *have* to only match "replication" for
the database.
- Regular expression matching.
- Exact match.
The previous logic did the same, but without the regexp step.
We have discussed as well the possibility to support regexp pattern
matching for host names, but these happen to lead to tricky issues based
on what I understand, particularly with host entries that have CIDRs.
This commit relies heavily on the refactoring done in a903971 and
fc579e1, so as the amount of code required to compile and execute
regular expressions is now minimal. When parsing pg_hba.conf, all the
computed regexps needs to explicitely free()'d, same as pg_ident.conf.
Documentation and TAP tests are added to cover this feature, including
cases where the regexps use commas (for clarity in the docs, coverage
for the parsing logic in the tests).
Note that this introduces a breakage with older versions, where a
database or user name beginning with a slash are treated as something to
check for an equal match. Per discussion, we have discarded this as
being much of an issue in practice as it would require a cluster to
have database and/or role names that begin with a slash, as well as HBA
entries using these. Hence, the consistency gained with regexps in
pg_ident.conf is more appealing in the long term.
**This compatibility change should be mentioned in the release notes.**
Author: Bertrand Drouvot
Reviewed-by: Jacob Champion, Tom Lane, Michael Paquier
Discussion: https://postgr.es/m/fff0d7c1-8ad4-76a1-9db3-0ab6ec338bf7@amazon.com
2022-10-24 04:45:31 +02:00
local all /^.*helpdesk$ md5
2010-01-26 07:45:31 +01:00
local all @admins md5
local all +support md5
2002-09-14 20:35:46 +02:00
# The last two lines above can be combined into a single line:
2010-01-26 07:45:31 +01:00
local all @admins,+support md5
2002-09-14 20:35:46 +02:00
2005-08-15 01:35:38 +02:00
# The database column can also use lists and file names:
2010-01-26 07:45:31 +01:00
local db1,db2,@demodbs all md5
2000-06-18 23:24:54 +02:00
</programlisting>
</example>
</sect1>
2008-10-23 15:31:10 +02:00
<sect1 id="auth-username-maps">
2011-01-29 19:00:18 +01:00
<title>User Name Maps</title>
2008-10-23 15:31:10 +02:00
<indexterm zone="auth-username-maps">
2010-08-17 06:37:21 +02:00
<primary>User name maps</primary>
2008-10-23 15:31:10 +02:00
</indexterm>
<para>
2015-09-22 04:57:29 +02:00
When using an external authentication system such as Ident or GSSAPI,
2009-05-16 23:17:21 +02:00
the name of the operating system user that initiated the connection
2016-10-11 16:33:59 +02:00
might not be the same as the database user (role) that is to be used.
2008-10-23 15:31:10 +02:00
In this case, a user name map can be applied to map the operating system
2010-08-17 06:37:21 +02:00
user name to a database user. To use user name mapping, specify
2008-10-23 15:31:10 +02:00
<literal>map</literal>=<replaceable>map-name</replaceable>
in the options field in <filename>pg_hba.conf</filename>. This option is
2010-08-17 06:37:21 +02:00
supported for all authentication methods that receive external user names.
2009-05-16 23:17:21 +02:00
Since different mappings might be needed for different connections,
2008-10-23 15:31:10 +02:00
the name of the map to be used is specified in the
<replaceable>map-name</replaceable> parameter in <filename>pg_hba.conf</filename>
to indicate which map to use for each individual connection.
</para>
<para>
2010-08-17 06:37:21 +02:00
User name maps are defined in the ident map file, which by default is named
2017-10-09 03:44:17 +02:00
<filename>pg_ident.conf</filename><indexterm><primary>pg_ident.conf</primary></indexterm>
2008-10-23 15:31:10 +02:00
and is stored in the
cluster's data directory. (It is possible to place the map file
2017-11-23 15:39:47 +01:00
elsewhere, however; see the <xref linkend="guc-ident-file"/>
2008-10-23 15:31:10 +02:00
configuration parameter.)
Add support for file inclusions in HBA and ident configuration files
pg_hba.conf and pg_ident.conf gain support for three record keywords:
- "include", to include a file.
- "include_if_exists", to include a file, ignoring it if missing.
- "include_dir", to include a directory of files. These are classified
by name (C locale, mostly) and need to be prefixed by ".conf", hence
following the same rules as GUCs.
This commit relies on the refactoring pieces done in efc9816, ad6c528,
783e8c6 and 1b73d0b, adding a small wrapper to build a list of
TokenizedAuthLines (tokenize_include_file), and the code is shaped to
offer some symmetry with what is done for GUCs with the same options.
pg_hba_file_rules and pg_ident_file_mappings gain a new field called
file_name, to track from which file a record is located, taking
advantage of the addition of rule_number in c591300 to offer an
organized view of the HBA or ident records loaded.
Bump catalog version.
Author: Julien Rouhaud
Reviewed-by: Michael Paquier
Discussion: https://postgr.es/m/20220223045959.35ipdsvbxcstrhya@jrouhaud
2022-11-24 05:51:34 +01:00
The ident map file contains lines of the general forms:
2008-10-23 15:31:10 +02:00
<synopsis>
2017-10-09 03:44:17 +02:00
<replaceable>map-name</replaceable> <replaceable>system-username</replaceable> <replaceable>database-username</replaceable>
Add support for file inclusions in HBA and ident configuration files
pg_hba.conf and pg_ident.conf gain support for three record keywords:
- "include", to include a file.
- "include_if_exists", to include a file, ignoring it if missing.
- "include_dir", to include a directory of files. These are classified
by name (C locale, mostly) and need to be prefixed by ".conf", hence
following the same rules as GUCs.
This commit relies on the refactoring pieces done in efc9816, ad6c528,
783e8c6 and 1b73d0b, adding a small wrapper to build a list of
TokenizedAuthLines (tokenize_include_file), and the code is shaped to
offer some symmetry with what is done for GUCs with the same options.
pg_hba_file_rules and pg_ident_file_mappings gain a new field called
file_name, to track from which file a record is located, taking
advantage of the addition of rule_number in c591300 to offer an
organized view of the HBA or ident records loaded.
Bump catalog version.
Author: Julien Rouhaud
Reviewed-by: Michael Paquier
Discussion: https://postgr.es/m/20220223045959.35ipdsvbxcstrhya@jrouhaud
2022-11-24 05:51:34 +01:00
<replaceable>include</replaceable> <replaceable>file</replaceable>
<replaceable>include_if_exists</replaceable> <replaceable>file</replaceable>
<replaceable>include_dir</replaceable> <replaceable>directory</replaceable>
2008-10-23 15:31:10 +02:00
</synopsis>
2020-09-03 18:16:48 +02:00
Comments, whitespace and line continuations are handled in the same way as in
2017-10-09 03:44:17 +02:00
<filename>pg_hba.conf</filename>. The
<replaceable>map-name</replaceable> is an arbitrary name that will be used to
2008-10-23 15:31:10 +02:00
refer to this mapping in <filename>pg_hba.conf</filename>. The other
2009-05-16 23:17:21 +02:00
two fields specify an operating system user name and a matching
2017-10-09 03:44:17 +02:00
database user name. The same <replaceable>map-name</replaceable> can be
2009-05-16 23:17:21 +02:00
used repeatedly to specify multiple user-mappings within a single map.
</para>
Add support for file inclusions in HBA and ident configuration files
pg_hba.conf and pg_ident.conf gain support for three record keywords:
- "include", to include a file.
- "include_if_exists", to include a file, ignoring it if missing.
- "include_dir", to include a directory of files. These are classified
by name (C locale, mostly) and need to be prefixed by ".conf", hence
following the same rules as GUCs.
This commit relies on the refactoring pieces done in efc9816, ad6c528,
783e8c6 and 1b73d0b, adding a small wrapper to build a list of
TokenizedAuthLines (tokenize_include_file), and the code is shaped to
offer some symmetry with what is done for GUCs with the same options.
pg_hba_file_rules and pg_ident_file_mappings gain a new field called
file_name, to track from which file a record is located, taking
advantage of the addition of rule_number in c591300 to offer an
organized view of the HBA or ident records loaded.
Bump catalog version.
Author: Julien Rouhaud
Reviewed-by: Michael Paquier
Discussion: https://postgr.es/m/20220223045959.35ipdsvbxcstrhya@jrouhaud
2022-11-24 05:51:34 +01:00
<para>
As for <filename>pg_hba.conf</filename>, the lines in this file can
be include directives, following the same rules.
</para>
2023-11-03 19:03:22 +01:00
<para>
The <filename>pg_ident.conf</filename> file is read on start-up and
when the main server process receives a
<systemitem>SIGHUP</systemitem><indexterm><primary>SIGHUP</primary></indexterm>
signal. If you edit the file on an
active system, you will need to signal the postmaster
(using <literal>pg_ctl reload</literal>, calling the SQL function
<function>pg_reload_conf()</function>, or using <literal>kill
-HUP</literal>) to make it re-read the file.
</para>
<para>
The system view
<link linkend="view-pg-ident-file-mappings"><structname>pg_ident_file_mappings</structname></link>
can be helpful for pre-testing changes to the
<filename>pg_ident.conf</filename> file, or for diagnosing problems if
loading of the file did not have the desired effects. Rows in the view with
non-null <structfield>error</structfield> fields indicate problems in the
corresponding lines of the file.
</para>
2009-05-16 23:17:21 +02:00
<para>
2008-10-23 15:31:10 +02:00
There is no restriction regarding how many database users a given
2009-05-16 23:17:21 +02:00
operating system user can correspond to, nor vice versa. Thus, entries
in a map should be thought of as meaning <quote>this operating system
user is allowed to connect as this database user</quote>, rather than
implying that they are equivalent. The connection will be allowed if
2010-05-27 01:49:19 +02:00
there is any map entry that pairs the user name obtained from the
external authentication system with the database user name that the
Support the same patterns for pg-user in pg_ident.conf as in pg_hba.conf
While pg_hba.conf has support for non-literal username matches, and
this commit extends the capabilities that are supported for the
PostgreSQL user listed in an ident entry part of pg_ident.conf, with
support for:
1. The "all" keyword, where all the requested users are allowed.
2. Membership checks using the + prefix.
3. Using a regex to match against multiple roles.
1. is a feature that has been requested by Jelte Fennema, 2. something
that has been mentioned independently by Andrew Dunstan, and 3. is
something I came up with while discussing how to extend the first one,
whose implementation is facilitated by 8fea868.
This allows matching certain system users against many different
postgres users with a single line in pg_ident.conf. Without this, one
would need one line for each of the postgres users that a system user
can log in as, which can be cumbersome to maintain.
Tests are added to the TAP test of peer authentication to provide
coverage for all that.
Note that this introduces a set of backward-incompatible changes to be
able to detect the new patterns, for the following cases:
- A role named "all".
- A role prefixed with '+' characters, which is something that would not
have worked in HBA entries anyway.
- A role prefixed by a slash character, similarly to 8fea868.
Any of these can be still be handled by using quotes in the Postgres
role defined in an ident entry.
A huge advantage of this change is that the code applies the same checks
for the Postgres roles in HBA and ident entries, via the common routine
check_role().
**This compatibility change should be mentioned in the release notes.**
Author: Jelte Fennema
Discussion: https://postgr.es/m/DBBPR83MB0507FEC2E8965012990A80D0F7FC9@DBBPR83MB0507.EURPRD83.prod.outlook.com
2023-01-20 03:21:55 +01:00
user has requested to connect as. The value <literal>all</literal>
can be used as the <replaceable>database-username</replaceable> to specify
2024-02-20 03:59:03 +01:00
that if the <replaceable>system-username</replaceable> matches, then this
user is allowed to log in as any of the existing database users. Quoting
Support the same patterns for pg-user in pg_ident.conf as in pg_hba.conf
While pg_hba.conf has support for non-literal username matches, and
this commit extends the capabilities that are supported for the
PostgreSQL user listed in an ident entry part of pg_ident.conf, with
support for:
1. The "all" keyword, where all the requested users are allowed.
2. Membership checks using the + prefix.
3. Using a regex to match against multiple roles.
1. is a feature that has been requested by Jelte Fennema, 2. something
that has been mentioned independently by Andrew Dunstan, and 3. is
something I came up with while discussing how to extend the first one,
whose implementation is facilitated by 8fea868.
This allows matching certain system users against many different
postgres users with a single line in pg_ident.conf. Without this, one
would need one line for each of the postgres users that a system user
can log in as, which can be cumbersome to maintain.
Tests are added to the TAP test of peer authentication to provide
coverage for all that.
Note that this introduces a set of backward-incompatible changes to be
able to detect the new patterns, for the following cases:
- A role named "all".
- A role prefixed with '+' characters, which is something that would not
have worked in HBA entries anyway.
- A role prefixed by a slash character, similarly to 8fea868.
Any of these can be still be handled by using quotes in the Postgres
role defined in an ident entry.
A huge advantage of this change is that the code applies the same checks
for the Postgres roles in HBA and ident entries, via the common routine
check_role().
**This compatibility change should be mentioned in the release notes.**
Author: Jelte Fennema
Discussion: https://postgr.es/m/DBBPR83MB0507FEC2E8965012990A80D0F7FC9@DBBPR83MB0507.EURPRD83.prod.outlook.com
2023-01-20 03:21:55 +01:00
<literal>all</literal> makes the keyword lose its special meaning.
</para>
<para>
If the <replaceable>database-username</replaceable> begins with a
<literal>+</literal> character, then the operating system user can login as
any user belonging to that role, similarly to how user names beginning with
<literal>+</literal> are treated in <literal>pg_hba.conf</literal>.
Thus, a <literal>+</literal> mark means <quote>match any of the roles that
are directly or indirectly members of this role</quote>, while a name
without a <literal>+</literal> mark matches only that specific role. Quoting
a username starting with a <literal>+</literal> makes the
<literal>+</literal> lose its special meaning.
2008-10-23 15:31:10 +02:00
</para>
2008-11-28 15:26:58 +01:00
<para>
2017-10-09 03:44:17 +02:00
If the <replaceable>system-username</replaceable> field starts with a slash (<literal>/</literal>),
2009-05-16 23:17:21 +02:00
the remainder of the field is treated as a regular expression.
2017-11-23 15:39:47 +01:00
(See <xref linkend="posix-syntax-details"/> for details of
2017-10-09 03:44:17 +02:00
<productname>PostgreSQL</productname>'s regular expression syntax.) The regular
2009-05-16 23:17:21 +02:00
expression can include a single capture, or parenthesized subexpression,
2017-10-09 03:44:17 +02:00
which can then be referenced in the <replaceable>database-username</replaceable>
field as <literal>\1</literal> (backslash-one). This allows the mapping of
2010-08-17 06:37:21 +02:00
multiple user names in a single line, which is particularly useful for
2009-05-16 23:17:21 +02:00
simple syntax substitutions. For example, these entries
<programlisting>
mymap /^(.*)@mydomain\.com$ \1
mymap /^(.*)@otherdomain\.com$ guest
</programlisting>
2010-08-17 06:37:21 +02:00
will remove the domain part for users with system user names that end with
2017-10-09 03:44:17 +02:00
<literal>@mydomain.com</literal>, and allow any user whose system name ends with
<literal>@otherdomain.com</literal> to log in as <literal>guest</literal>.
2023-01-17 05:41:09 +01:00
Quoting a <replaceable>database-username</replaceable> containing
<literal>\1</literal> <emphasis>does not</emphasis> make
<literal>\1</literal> lose its special meaning.
2008-11-28 15:26:58 +01:00
</para>
Support the same patterns for pg-user in pg_ident.conf as in pg_hba.conf
While pg_hba.conf has support for non-literal username matches, and
this commit extends the capabilities that are supported for the
PostgreSQL user listed in an ident entry part of pg_ident.conf, with
support for:
1. The "all" keyword, where all the requested users are allowed.
2. Membership checks using the + prefix.
3. Using a regex to match against multiple roles.
1. is a feature that has been requested by Jelte Fennema, 2. something
that has been mentioned independently by Andrew Dunstan, and 3. is
something I came up with while discussing how to extend the first one,
whose implementation is facilitated by 8fea868.
This allows matching certain system users against many different
postgres users with a single line in pg_ident.conf. Without this, one
would need one line for each of the postgres users that a system user
can log in as, which can be cumbersome to maintain.
Tests are added to the TAP test of peer authentication to provide
coverage for all that.
Note that this introduces a set of backward-incompatible changes to be
able to detect the new patterns, for the following cases:
- A role named "all".
- A role prefixed with '+' characters, which is something that would not
have worked in HBA entries anyway.
- A role prefixed by a slash character, similarly to 8fea868.
Any of these can be still be handled by using quotes in the Postgres
role defined in an ident entry.
A huge advantage of this change is that the code applies the same checks
for the Postgres roles in HBA and ident entries, via the common routine
check_role().
**This compatibility change should be mentioned in the release notes.**
Author: Jelte Fennema
Discussion: https://postgr.es/m/DBBPR83MB0507FEC2E8965012990A80D0F7FC9@DBBPR83MB0507.EURPRD83.prod.outlook.com
2023-01-20 03:21:55 +01:00
<para>
If the <replaceable>database-username</replaceable> field starts with
a slash (<literal>/</literal>), the remainder of the field is treated
as a regular expression (see <xref linkend="posix-syntax-details"/>
for details of <productname>PostgreSQL</productname>'s regular
2023-10-25 02:40:55 +02:00
expression syntax). It is not possible to use <literal>\1</literal>
Support the same patterns for pg-user in pg_ident.conf as in pg_hba.conf
While pg_hba.conf has support for non-literal username matches, and
this commit extends the capabilities that are supported for the
PostgreSQL user listed in an ident entry part of pg_ident.conf, with
support for:
1. The "all" keyword, where all the requested users are allowed.
2. Membership checks using the + prefix.
3. Using a regex to match against multiple roles.
1. is a feature that has been requested by Jelte Fennema, 2. something
that has been mentioned independently by Andrew Dunstan, and 3. is
something I came up with while discussing how to extend the first one,
whose implementation is facilitated by 8fea868.
This allows matching certain system users against many different
postgres users with a single line in pg_ident.conf. Without this, one
would need one line for each of the postgres users that a system user
can log in as, which can be cumbersome to maintain.
Tests are added to the TAP test of peer authentication to provide
coverage for all that.
Note that this introduces a set of backward-incompatible changes to be
able to detect the new patterns, for the following cases:
- A role named "all".
- A role prefixed with '+' characters, which is something that would not
have worked in HBA entries anyway.
- A role prefixed by a slash character, similarly to 8fea868.
Any of these can be still be handled by using quotes in the Postgres
role defined in an ident entry.
A huge advantage of this change is that the code applies the same checks
for the Postgres roles in HBA and ident entries, via the common routine
check_role().
**This compatibility change should be mentioned in the release notes.**
Author: Jelte Fennema
Discussion: https://postgr.es/m/DBBPR83MB0507FEC2E8965012990A80D0F7FC9@DBBPR83MB0507.EURPRD83.prod.outlook.com
2023-01-20 03:21:55 +01:00
to use a capture from regular expression on
<replaceable>system-username</replaceable> for a regular expression
on <replaceable>database-username</replaceable>.
</para>
2008-10-23 15:31:10 +02:00
2009-05-16 23:17:21 +02:00
<tip>
<para>
Keep in mind that by default, a regular expression can match just part of
2017-10-09 03:44:17 +02:00
a string. It's usually wise to use <literal>^</literal> and <literal>$</literal>, as
2009-05-16 23:17:21 +02:00
shown in the above example, to force the match to be to the entire
2010-08-17 06:37:21 +02:00
system user name.
2009-05-16 23:17:21 +02:00
</para>
</tip>
2008-10-23 15:31:10 +02:00
<para>
A <filename>pg_ident.conf</filename> file that could be used in
2017-10-09 03:44:17 +02:00
conjunction with the <filename>pg_hba.conf</filename> file in <xref
2017-11-23 15:39:47 +01:00
linkend="example-pg-hba.conf"/> is shown in <xref
linkend="example-pg-ident.conf"/>. In this example, anyone
2008-10-23 15:31:10 +02:00
logged in to a machine on the 192.168 network that does not have the
2017-10-09 03:44:17 +02:00
operating system user name <literal>bryanh</literal>, <literal>ann</literal>, or
<literal>robert</literal> would not be granted access. Unix user
<literal>robert</literal> would only be allowed access when he tries to
connect as <productname>PostgreSQL</productname> user <literal>bob</literal>, not
as <literal>robert</literal> or anyone else. <literal>ann</literal> would
only be allowed to connect as <literal>ann</literal>. User
<literal>bryanh</literal> would be allowed to connect as either
<literal>bryanh</literal> or as <literal>guest1</literal>.
2008-10-23 15:31:10 +02:00
</para>
<example id="example-pg-ident.conf">
2017-10-09 03:44:17 +02:00
<title>An Example <filename>pg_ident.conf</filename> File</title>
2008-10-23 15:31:10 +02:00
<programlisting>
2010-01-26 07:45:31 +01:00
# MAPNAME SYSTEM-USERNAME PG-USERNAME
2008-10-23 15:31:10 +02:00
2010-01-26 07:45:31 +01:00
omicron bryanh bryanh
omicron ann ann
2008-10-23 15:31:10 +02:00
# bob has user name robert on these machines
2010-01-26 07:45:31 +01:00
omicron robert bob
2008-10-23 15:31:10 +02:00
# bryanh can also connect as guest1
2010-01-26 07:45:31 +01:00
omicron bryanh guest1
2008-10-23 15:31:10 +02:00
</programlisting>
</example>
</sect1>
2000-06-18 23:24:54 +02:00
<sect1 id="auth-methods">
2011-01-29 19:00:18 +01:00
<title>Authentication Methods</title>
2019-12-19 15:42:39 +01:00
<para>
<productname>PostgreSQL</productname> provides various methods for
authenticating users:
<itemizedlist>
<listitem>
<para>
<link linkend="auth-trust">Trust authentication</link>, which
simply trusts that users are who they say they are.
</para>
</listitem>
<listitem>
<para>
<link linkend="auth-password">Password authentication</link>, which
requires that users send a password.
</para>
</listitem>
<listitem>
<para>
<link linkend="gssapi-auth">GSSAPI authentication</link>, which
relies on a GSSAPI-compatible security library. Typically this is
used to access an authentication server such as a Kerberos or
Microsoft Active Directory server.
</para>
</listitem>
<listitem>
<para>
<link linkend="sspi-auth">SSPI authentication</link>, which
uses a Windows-specific protocol similar to GSSAPI.
</para>
</listitem>
<listitem>
<para>
<link linkend="auth-ident">Ident authentication</link>, which
2020-12-01 13:36:30 +01:00
relies on an <quote>Identification Protocol</quote>
2024-04-10 13:53:25 +02:00
(<ulink url="https://datatracker.ietf.org/doc/html/rfc1413">RFC 1413</ulink>)
2019-12-19 15:42:39 +01:00
service on the client's machine. (On local Unix-socket connections,
this is treated as peer authentication.)
</para>
</listitem>
<listitem>
<para>
<link linkend="auth-peer">Peer authentication</link>, which
relies on operating system facilities to identify the process at the
other end of a local connection. This is not supported for remote
connections.
</para>
</listitem>
<listitem>
<para>
<link linkend="auth-ldap">LDAP authentication</link>, which
relies on an LDAP authentication server.
</para>
</listitem>
<listitem>
<para>
<link linkend="auth-radius">RADIUS authentication</link>, which
relies on a RADIUS authentication server.
</para>
</listitem>
<listitem>
<para>
<link linkend="auth-cert">Certificate authentication</link>, which
requires an SSL connection and authenticates users by checking the
SSL certificate they send.
</para>
</listitem>
<listitem>
<para>
<link linkend="auth-pam">PAM authentication</link>, which
relies on a PAM (Pluggable Authentication Modules) library.
</para>
</listitem>
<listitem>
<para>
<link linkend="auth-bsd">BSD authentication</link>, which
relies on the BSD Authentication framework (currently available
only on OpenBSD).
</para>
</listitem>
</itemizedlist>
</para>
<para>
Peer authentication is usually recommendable for local connections,
though trust authentication might be sufficient in some circumstances.
Password authentication is the easiest choice for remote connections.
All the other options require some kind of external security
infrastructure (usually an authentication server or a certificate
authority for issuing SSL certificates), or are platform-specific.
</para>
2000-06-18 23:24:54 +02:00
<para>
2019-12-19 15:42:39 +01:00
The following sections describe each of these authentication methods
in more detail.
2000-06-18 23:24:54 +02:00
</para>
2018-04-12 02:33:53 +02:00
</sect1>
2000-06-18 23:24:54 +02:00
2018-04-12 02:33:53 +02:00
<sect1 id="auth-trust">
2011-01-29 19:00:18 +01:00
<title>Trust Authentication</title>
2001-12-27 22:37:34 +01:00
<para>
2017-10-09 03:44:17 +02:00
When <literal>trust</literal> authentication is specified,
2001-12-27 22:37:34 +01:00
<productname>PostgreSQL</productname> assumes that anyone who can
2004-01-26 06:35:15 +01:00
connect to the server is authorized to access the database with
2009-05-16 23:17:21 +02:00
whatever database user name they specify (even superuser names).
2017-10-09 03:44:17 +02:00
Of course, restrictions made in the <literal>database</literal> and
<literal>user</literal> columns still apply.
2004-12-27 00:06:56 +01:00
This method should only be used when there is adequate
operating-system-level protection on connections to the server.
2001-12-27 22:37:34 +01:00
</para>
<para>
2017-10-09 03:44:17 +02:00
<literal>trust</literal> authentication is appropriate and very
2003-01-19 01:13:31 +01:00
convenient for local connections on a single-user workstation. It
2017-10-09 03:44:17 +02:00
is usually <emphasis>not</emphasis> appropriate by itself on a multiuser
machine. However, you might be able to use <literal>trust</literal> even
2003-03-13 02:30:29 +01:00
on a multiuser machine, if you restrict access to the server's
Unix-domain socket file using file-system permissions. To do this, set the
2001-12-27 22:37:34 +01:00
<varname>unix_socket_permissions</varname> (and possibly
2003-01-19 01:13:31 +01:00
<varname>unix_socket_group</varname>) configuration parameters as
2017-11-23 15:39:47 +01:00
described in <xref linkend="runtime-config-connection"/>. Or you
2012-08-10 23:26:44 +02:00
could set the <varname>unix_socket_directories</varname>
2003-01-19 01:13:31 +01:00
configuration parameter to place the socket file in a suitably
restricted directory.
2001-12-27 22:37:34 +01:00
</para>
<para>
2002-01-20 23:19:57 +01:00
Setting file-system permissions only helps for Unix-socket connections.
2009-05-16 23:17:21 +02:00
Local TCP/IP connections are not restricted by file-system permissions.
Therefore, if you want to use file-system permissions for local security,
2017-10-09 03:44:17 +02:00
remove the <literal>host ... 127.0.0.1 ...</literal> line from
<filename>pg_hba.conf</filename>, or change it to a
non-<literal>trust</literal> authentication method.
2001-12-27 22:37:34 +01:00
</para>
<para>
2017-10-09 03:44:17 +02:00
<literal>trust</literal> authentication is only suitable for TCP/IP connections
2001-12-27 22:37:34 +01:00
if you trust every user on every machine that is allowed to connect
2017-10-09 03:44:17 +02:00
to the server by the <filename>pg_hba.conf</filename> lines that specify
<literal>trust</literal>. It is seldom reasonable to use <literal>trust</literal>
for any TCP/IP connections other than those from <systemitem>localhost</systemitem> (127.0.0.1).
2001-12-27 22:37:34 +01:00
</para>
2018-04-12 02:33:53 +02:00
</sect1>
2001-12-27 22:37:34 +01:00
2018-04-12 02:33:53 +02:00
<sect1 id="auth-password">
2011-01-29 19:00:18 +01:00
<title>Password Authentication</title>
2001-05-13 00:51:36 +02:00
<indexterm>
2017-10-09 03:44:17 +02:00
<primary>MD5</primary>
2001-05-13 00:51:36 +02:00
</indexterm>
2017-09-24 06:29:59 +02:00
<indexterm>
2017-10-09 03:44:17 +02:00
<primary>SCRAM</primary>
2017-09-24 06:29:59 +02:00
</indexterm>
2002-04-04 06:25:54 +02:00
<indexterm>
<primary>password</primary>
2003-08-31 19:32:24 +02:00
<secondary>authentication</secondary>
2001-11-12 20:19:39 +01:00
</indexterm>
2001-05-13 00:51:36 +02:00
2001-12-27 22:37:34 +01:00
<para>
2017-09-24 06:29:59 +02:00
There are several password-based authentication methods. These methods
operate similarly but differ in how the users' passwords are stored on the
server and how the password provided by a client is sent across the
Support SCRAM-SHA-256 authentication (RFC 5802 and 7677).
This introduces a new generic SASL authentication method, similar to the
GSS and SSPI methods. The server first tells the client which SASL
authentication mechanism to use, and then the mechanism-specific SASL
messages are exchanged in AuthenticationSASLcontinue and PasswordMessage
messages. Only SCRAM-SHA-256 is supported at the moment, but this allows
adding more SASL mechanisms in the future, without changing the overall
protocol.
Support for channel binding, aka SCRAM-SHA-256-PLUS is left for later.
The SASLPrep algorithm, for pre-processing the password, is not yet
implemented. That could cause trouble, if you use a password with
non-ASCII characters, and a client library that does implement SASLprep.
That will hopefully be added later.
Authorization identities, as specified in the SCRAM-SHA-256 specification,
are ignored. SET SESSION AUTHORIZATION provides more or less the same
functionality, anyway.
If a user doesn't exist, perform a "mock" authentication, by constructing
an authentic-looking challenge on the fly. The challenge is derived from
a new system-wide random value, "mock authentication nonce", which is
created at initdb, and stored in the control file. We go through these
motions, in order to not give away the information on whether the user
exists, to unauthenticated users.
Bumps PG_CONTROL_VERSION, because of the new field in control file.
Patch by Michael Paquier and Heikki Linnakangas, reviewed at different
stages by Robert Haas, Stephen Frost, David Steele, Aleksander Alekseev,
and many others.
Discussion: https://www.postgresql.org/message-id/CAB7nPqRbR3GmFYdedCAhzukfKrgBLTLtMvENOmPrVWREsZkF8g%40mail.gmail.com
Discussion: https://www.postgresql.org/message-id/CAB7nPqSMXU35g%3DW9X74HVeQp0uvgJxvYOuA4A-A3M%2B0wfEBv-w%40mail.gmail.com
Discussion: https://www.postgresql.org/message-id/55192AFE.6080106@iki.fi
2017-03-07 13:25:40 +01:00
connection.
</para>
2017-09-24 06:29:59 +02:00
<variablelist>
<varlistentry>
<term><literal>scram-sha-256</literal></term>
<listitem>
<para>
2017-10-09 03:44:17 +02:00
The method <literal>scram-sha-256</literal> performs SCRAM-SHA-256
2017-09-24 06:29:59 +02:00
authentication, as described in
2024-04-10 13:53:25 +02:00
<ulink url="https://datatracker.ietf.org/doc/html/rfc7677">RFC 7677</ulink>. It
2017-09-24 06:29:59 +02:00
is a challenge-response scheme that prevents password sniffing on
untrusted connections and supports storing passwords on the server in a
cryptographically hashed form that is thought to be secure.
</para>
Support SCRAM-SHA-256 authentication (RFC 5802 and 7677).
This introduces a new generic SASL authentication method, similar to the
GSS and SSPI methods. The server first tells the client which SASL
authentication mechanism to use, and then the mechanism-specific SASL
messages are exchanged in AuthenticationSASLcontinue and PasswordMessage
messages. Only SCRAM-SHA-256 is supported at the moment, but this allows
adding more SASL mechanisms in the future, without changing the overall
protocol.
Support for channel binding, aka SCRAM-SHA-256-PLUS is left for later.
The SASLPrep algorithm, for pre-processing the password, is not yet
implemented. That could cause trouble, if you use a password with
non-ASCII characters, and a client library that does implement SASLprep.
That will hopefully be added later.
Authorization identities, as specified in the SCRAM-SHA-256 specification,
are ignored. SET SESSION AUTHORIZATION provides more or less the same
functionality, anyway.
If a user doesn't exist, perform a "mock" authentication, by constructing
an authentic-looking challenge on the fly. The challenge is derived from
a new system-wide random value, "mock authentication nonce", which is
created at initdb, and stored in the control file. We go through these
motions, in order to not give away the information on whether the user
exists, to unauthenticated users.
Bumps PG_CONTROL_VERSION, because of the new field in control file.
Patch by Michael Paquier and Heikki Linnakangas, reviewed at different
stages by Robert Haas, Stephen Frost, David Steele, Aleksander Alekseev,
and many others.
Discussion: https://www.postgresql.org/message-id/CAB7nPqRbR3GmFYdedCAhzukfKrgBLTLtMvENOmPrVWREsZkF8g%40mail.gmail.com
Discussion: https://www.postgresql.org/message-id/CAB7nPqSMXU35g%3DW9X74HVeQp0uvgJxvYOuA4A-A3M%2B0wfEBv-w%40mail.gmail.com
Discussion: https://www.postgresql.org/message-id/55192AFE.6080106@iki.fi
2017-03-07 13:25:40 +01:00
2017-09-24 06:29:59 +02:00
<para>
This is the most secure of the currently provided methods, but it is
not supported by older client libraries.
</para>
</listitem>
</varlistentry>
Support SCRAM-SHA-256 authentication (RFC 5802 and 7677).
This introduces a new generic SASL authentication method, similar to the
GSS and SSPI methods. The server first tells the client which SASL
authentication mechanism to use, and then the mechanism-specific SASL
messages are exchanged in AuthenticationSASLcontinue and PasswordMessage
messages. Only SCRAM-SHA-256 is supported at the moment, but this allows
adding more SASL mechanisms in the future, without changing the overall
protocol.
Support for channel binding, aka SCRAM-SHA-256-PLUS is left for later.
The SASLPrep algorithm, for pre-processing the password, is not yet
implemented. That could cause trouble, if you use a password with
non-ASCII characters, and a client library that does implement SASLprep.
That will hopefully be added later.
Authorization identities, as specified in the SCRAM-SHA-256 specification,
are ignored. SET SESSION AUTHORIZATION provides more or less the same
functionality, anyway.
If a user doesn't exist, perform a "mock" authentication, by constructing
an authentic-looking challenge on the fly. The challenge is derived from
a new system-wide random value, "mock authentication nonce", which is
created at initdb, and stored in the control file. We go through these
motions, in order to not give away the information on whether the user
exists, to unauthenticated users.
Bumps PG_CONTROL_VERSION, because of the new field in control file.
Patch by Michael Paquier and Heikki Linnakangas, reviewed at different
stages by Robert Haas, Stephen Frost, David Steele, Aleksander Alekseev,
and many others.
Discussion: https://www.postgresql.org/message-id/CAB7nPqRbR3GmFYdedCAhzukfKrgBLTLtMvENOmPrVWREsZkF8g%40mail.gmail.com
Discussion: https://www.postgresql.org/message-id/CAB7nPqSMXU35g%3DW9X74HVeQp0uvgJxvYOuA4A-A3M%2B0wfEBv-w%40mail.gmail.com
Discussion: https://www.postgresql.org/message-id/55192AFE.6080106@iki.fi
2017-03-07 13:25:40 +01:00
2017-09-24 06:29:59 +02:00
<varlistentry>
<term><literal>md5</literal></term>
<listitem>
<para>
2017-10-09 03:44:17 +02:00
The method <literal>md5</literal> uses a custom less secure challenge-response
2017-09-24 06:29:59 +02:00
mechanism. It prevents password sniffing and avoids storing passwords
on the server in plain text but provides no protection if an attacker
manages to steal the password hash from the server. Also, the MD5 hash
2017-10-02 11:27:46 +02:00
algorithm is nowadays no longer considered secure against determined
2017-09-24 06:29:59 +02:00
attacks.
</para>
2004-12-27 00:06:56 +01:00
2017-09-24 06:29:59 +02:00
<para>
To ease transition from the <literal>md5</literal> method to the newer
SCRAM method, if <literal>md5</literal> is specified as a method
in <filename>pg_hba.conf</filename> but the user's password on the
server is encrypted for SCRAM (see below), then SCRAM-based
authentication will automatically be chosen instead.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><literal>password</literal></term>
<listitem>
<para>
2017-10-09 03:44:17 +02:00
The method <literal>password</literal> sends the password in clear-text and is
therefore vulnerable to password <quote>sniffing</quote> attacks. It should
2017-09-24 06:29:59 +02:00
always be avoided if possible. If the connection is protected by SSL
2017-10-09 03:44:17 +02:00
encryption then <literal>password</literal> can be used safely, though.
2017-09-24 06:29:59 +02:00
(Though SSL certificate authentication might be a better choice if one
is depending on using SSL).
</para>
</listitem>
</varlistentry>
</variablelist>
2001-12-27 22:37:34 +01:00
2000-06-18 23:24:54 +02:00
<para>
2002-04-04 06:25:54 +02:00
<productname>PostgreSQL</productname> database passwords are
2002-11-11 21:14:04 +01:00
separate from operating system user passwords. The password for
2017-10-09 03:44:17 +02:00
each database user is stored in the <literal>pg_authid</literal> system
2005-08-15 01:35:38 +02:00
catalog. Passwords can be managed with the SQL commands
2017-11-23 15:39:47 +01:00
<xref linkend="sql-createrole"/> and
<xref linkend="sql-alterrole"/>,
2017-10-31 19:04:49 +01:00
e.g., <userinput>CREATE ROLE foo WITH LOGIN PASSWORD 'secret'</userinput>,
2017-09-24 06:29:59 +02:00
or the <application>psql</application>
command <literal>\password</literal>.
2010-02-03 18:25:06 +01:00
If no password has been set up for a user, the stored password
2004-12-27 00:06:56 +01:00
is null and password authentication will always fail for that user.
2000-07-04 18:32:01 +02:00
</para>
2017-09-24 06:29:59 +02:00
<para>
The availability of the different password-based authentication methods
depends on how a user's password on the server is encrypted (or hashed,
more accurately). This is controlled by the configuration
2017-11-23 15:39:47 +01:00
parameter <xref linkend="guc-password-encryption"/> at the time the
2017-09-24 06:29:59 +02:00
password is set. If a password was encrypted using
the <literal>scram-sha-256</literal> setting, then it can be used for the
authentication methods <literal>scram-sha-256</literal>
and <literal>password</literal> (but password transmission will be in
plain text in the latter case). The authentication method
specification <literal>md5</literal> will automatically switch to using
the <literal>scram-sha-256</literal> method in this case, as explained
above, so it will also work. If a password was encrypted using
the <literal>md5</literal> setting, then it can be used only for
the <literal>md5</literal> and <literal>password</literal> authentication
method specifications (again, with the password transmitted in plain text
in the latter case). (Previous PostgreSQL releases supported storing the
password on the server in plain text. This is no longer possible.) To
check the currently stored password hashes, see the system
catalog <literal>pg_authid</literal>.
</para>
<para>
To upgrade an existing installation from <literal>md5</literal>
to <literal>scram-sha-256</literal>, after having ensured that all client
libraries in use are new enough to support SCRAM,
set <literal>password_encryption = 'scram-sha-256'</literal>
in <filename>postgresql.conf</filename>, make all users set new passwords,
and change the authentication method specifications
in <filename>pg_hba.conf</filename> to <literal>scram-sha-256</literal>.
</para>
2018-04-12 02:33:53 +02:00
</sect1>
2000-06-18 23:24:54 +02:00
2018-04-12 02:33:53 +02:00
<sect1 id="gssapi-auth">
2011-01-29 19:00:18 +01:00
<title>GSSAPI Authentication</title>
2007-07-18 14:00:47 +02:00
<indexterm zone="gssapi-auth">
<primary>GSSAPI</primary>
</indexterm>
<para>
<productname>GSSAPI</productname> is an industry-standard protocol
2020-12-01 13:36:30 +01:00
for secure authentication defined in
2024-04-10 13:53:25 +02:00
<ulink url="https://datatracker.ietf.org/doc/html/rfc2743">RFC 2743</ulink>.
GSSAPI encryption support
On both the frontend and backend, prepare for GSSAPI encryption
support by moving common code for error handling into a separate file.
Fix a TODO for handling multiple status messages in the process.
Eliminate the OIDs, which have not been needed for some time.
Add frontend and backend encryption support functions. Keep the
context initiation for authentication-only separate on both the
frontend and backend in order to avoid concerns about changing the
requested flags to include encryption support.
In postmaster, pull GSSAPI authorization checking into a shared
function. Also share the initiator name between the encryption and
non-encryption codepaths.
For HBA, add "hostgssenc" and "hostnogssenc" entries that behave
similarly to their SSL counterparts. "hostgssenc" requires either
"gss", "trust", or "reject" for its authentication.
Similarly, add a "gssencmode" parameter to libpq. Supported values are
"disable", "require", and "prefer". Notably, negotiation will only be
attempted if credentials can be acquired. Move credential acquisition
into its own function to support this behavior.
Add a simple pg_stat_gssapi view similar to pg_stat_ssl, for monitoring
if GSSAPI authentication was used, what principal was used, and if
encryption is being used on the connection.
Finally, add documentation for everything new, and update existing
documentation on connection security.
Thanks to Michael Paquier for the Windows fixes.
Author: Robbie Harwood, with changes to the read/write functions by me.
Reviewed in various forms and at different times by: Michael Paquier,
Andres Freund, David Steele.
Discussion: https://www.postgresql.org/message-id/flat/jlg1tgq1ktm.fsf@thriss.redhat.com
2019-04-03 21:02:33 +02:00
<productname>PostgreSQL</productname>
2020-12-28 23:44:17 +01:00
supports <productname>GSSAPI</productname> for authentication,
communications encryption, or both.
GSSAPI encryption support
On both the frontend and backend, prepare for GSSAPI encryption
support by moving common code for error handling into a separate file.
Fix a TODO for handling multiple status messages in the process.
Eliminate the OIDs, which have not been needed for some time.
Add frontend and backend encryption support functions. Keep the
context initiation for authentication-only separate on both the
frontend and backend in order to avoid concerns about changing the
requested flags to include encryption support.
In postmaster, pull GSSAPI authorization checking into a shared
function. Also share the initiator name between the encryption and
non-encryption codepaths.
For HBA, add "hostgssenc" and "hostnogssenc" entries that behave
similarly to their SSL counterparts. "hostgssenc" requires either
"gss", "trust", or "reject" for its authentication.
Similarly, add a "gssencmode" parameter to libpq. Supported values are
"disable", "require", and "prefer". Notably, negotiation will only be
attempted if credentials can be acquired. Move credential acquisition
into its own function to support this behavior.
Add a simple pg_stat_gssapi view similar to pg_stat_ssl, for monitoring
if GSSAPI authentication was used, what principal was used, and if
encryption is being used on the connection.
Finally, add documentation for everything new, and update existing
documentation on connection security.
Thanks to Michael Paquier for the Windows fixes.
Author: Robbie Harwood, with changes to the read/write functions by me.
Reviewed in various forms and at different times by: Michael Paquier,
Andres Freund, David Steele.
Discussion: https://www.postgresql.org/message-id/flat/jlg1tgq1ktm.fsf@thriss.redhat.com
2019-04-03 21:02:33 +02:00
<productname>GSSAPI</productname> provides automatic authentication
(single sign-on) for systems that support it. The authentication itself is
secure. If <productname>GSSAPI</productname> encryption
2020-12-28 23:44:17 +01:00
or <acronym>SSL</acronym> encryption is
GSSAPI encryption support
On both the frontend and backend, prepare for GSSAPI encryption
support by moving common code for error handling into a separate file.
Fix a TODO for handling multiple status messages in the process.
Eliminate the OIDs, which have not been needed for some time.
Add frontend and backend encryption support functions. Keep the
context initiation for authentication-only separate on both the
frontend and backend in order to avoid concerns about changing the
requested flags to include encryption support.
In postmaster, pull GSSAPI authorization checking into a shared
function. Also share the initiator name between the encryption and
non-encryption codepaths.
For HBA, add "hostgssenc" and "hostnogssenc" entries that behave
similarly to their SSL counterparts. "hostgssenc" requires either
"gss", "trust", or "reject" for its authentication.
Similarly, add a "gssencmode" parameter to libpq. Supported values are
"disable", "require", and "prefer". Notably, negotiation will only be
attempted if credentials can be acquired. Move credential acquisition
into its own function to support this behavior.
Add a simple pg_stat_gssapi view similar to pg_stat_ssl, for monitoring
if GSSAPI authentication was used, what principal was used, and if
encryption is being used on the connection.
Finally, add documentation for everything new, and update existing
documentation on connection security.
Thanks to Michael Paquier for the Windows fixes.
Author: Robbie Harwood, with changes to the read/write functions by me.
Reviewed in various forms and at different times by: Michael Paquier,
Andres Freund, David Steele.
Discussion: https://www.postgresql.org/message-id/flat/jlg1tgq1ktm.fsf@thriss.redhat.com
2019-04-03 21:02:33 +02:00
used, the data sent along the database connection will be encrypted;
otherwise, it will not.
2007-07-18 14:00:47 +02:00
</para>
2014-01-15 17:24:01 +01:00
<para>
2017-10-09 03:44:17 +02:00
GSSAPI support has to be enabled when <productname>PostgreSQL</productname> is built;
2017-11-23 15:39:47 +01:00
see <xref linkend="installation"/> for more information.
2014-01-15 17:24:01 +01:00
</para>
2007-07-18 14:00:47 +02:00
<para>
When <productname>GSSAPI</productname> uses
2020-12-28 23:44:17 +01:00
<productname>Kerberos</productname>, it uses a standard service
principal (authentication identity) name in the format
2017-10-09 03:44:17 +02:00
<literal><replaceable>servicename</replaceable>/<replaceable>hostname</replaceable>@<replaceable>realm</replaceable></literal>.
2020-12-28 23:44:17 +01:00
The principal name used by a particular installation is not encoded in
the <productname>PostgreSQL</productname> server in any way; rather it
is specified in the <firstterm>keytab</firstterm> file that the server
reads to determine its identity. If multiple principals are listed in
the keytab file, the server will accept any one of them.
The server's realm name is the preferred realm specified in the Kerberos
configuration file(s) accessible to the server.
2014-01-15 17:24:01 +01:00
</para>
2020-12-28 23:44:17 +01:00
2014-01-15 17:24:01 +01:00
<para>
2020-12-28 23:44:17 +01:00
When connecting, the client must know the principal name of the server
it intends to connect to. The <replaceable>servicename</replaceable>
part of the principal is ordinarily <literal>postgres</literal>,
but another value can be selected via <application>libpq</application>'s
<xref linkend="libpq-connect-krbsrvname"/> connection parameter.
The <replaceable>hostname</replaceable> part is the fully qualified
host name that <application>libpq</application> is told to connect to.
The realm name is the preferred realm specified in the Kerberos
configuration file(s) accessible to the client.
2010-05-27 01:49:19 +02:00
</para>
<para>
2020-12-28 23:44:17 +01:00
The client will also have a principal name for its own identity
(and it must have a valid ticket for this principal). To
use <productname>GSSAPI</productname> for authentication, the client
principal must be associated with
a <productname>PostgreSQL</productname> database user name.
The <filename>pg_ident.conf</filename> configuration file can be used
to map principals to user names; for example,
2017-10-09 03:44:17 +02:00
<literal>pgusername@realm</literal> could be mapped to just <literal>pgusername</literal>.
Alternatively, you can use the full <literal>username@realm</literal> principal as
the role name in <productname>PostgreSQL</productname> without any mapping.
2015-05-09 01:39:42 +02:00
</para>
<para>
2020-12-28 23:44:17 +01:00
<productname>PostgreSQL</productname> also supports mapping
client principals to user names by just stripping the realm from
2015-05-09 01:39:42 +02:00
the principal. This method is supported for backwards compatibility and is
strongly discouraged as it is then impossible to distinguish different users
2015-09-11 03:22:21 +02:00
with the same user name but coming from different realms. To enable this,
2017-10-09 03:44:17 +02:00
set <literal>include_realm</literal> to 0. For simple single-realm
2016-05-06 23:42:44 +02:00
installations, doing that combined with setting the
2017-10-09 03:44:17 +02:00
<literal>krb_realm</literal> parameter (which checks that the principal's realm
2016-05-06 23:42:44 +02:00
matches exactly what is in the <literal>krb_realm</literal> parameter)
is still secure; but this is a
less capable approach compared to specifying an explicit mapping in
2017-10-09 03:44:17 +02:00
<filename>pg_ident.conf</filename>.
2014-01-15 17:24:01 +01:00
</para>
<para>
2020-12-28 23:44:17 +01:00
The location of the server's keytab file is specified by the <xref
Fix up usage of krb_server_keyfile GUC parameter.
secure_open_gssapi() installed the krb_server_keyfile setting as
KRB5_KTNAME unconditionally, so long as it's not empty. However,
pg_GSS_recvauth() only installed it if KRB5_KTNAME wasn't set already,
leading to a troubling inconsistency: in theory, clients could see
different sets of server principal names depending on whether they
use GSSAPI encryption. Always using krb_server_keyfile seems like
the right thing, so make both places do that. Also fix up
secure_open_gssapi()'s lack of a check for setenv() failure ---
it's unlikely, surely, but security-critical actions are no place
to be sloppy.
Also improve the associated documentation.
This patch does nothing about secure_open_gssapi()'s use of setenv(),
and indeed causes pg_GSS_recvauth() to use it too. That's nominally
against project portability rules, but since this code is only built
with --with-gssapi, I do not feel a need to do something about this
in the back branches. A fix will be forthcoming for HEAD though.
Back-patch to v12 where GSSAPI encryption was introduced. The
dubious behavior in pg_GSS_recvauth() goes back further, but it
didn't have anything to be inconsistent with, so let it be.
Discussion: https://postgr.es/m/2187460.1609263156@sss.pgh.pa.us
2020-12-30 17:38:42 +01:00
linkend="guc-krb-server-keyfile"/> configuration parameter.
2014-03-16 15:18:52 +01:00
For security reasons, it is recommended to use a separate keytab
just for the <productname>PostgreSQL</productname> server rather
2020-12-28 23:44:17 +01:00
than allowing the server to read the system keytab file.
Make sure that your server keytab file is readable (and preferably
only readable, not writable) by the <productname>PostgreSQL</productname>
server account. (See also <xref linkend="postgres-user"/>.)
2014-01-15 17:24:01 +01:00
</para>
2020-12-28 23:44:17 +01:00
2014-01-15 17:24:01 +01:00
<para>
2020-12-28 23:44:17 +01:00
The keytab file is generated using the Kerberos software; see the
Kerberos documentation for details. The following example shows
doing this using the <application>kadmin</application> tool of
2023-04-13 14:55:13 +02:00
MIT Kerberos:
2014-01-15 17:24:01 +01:00
<screen>
2020-12-28 23:44:17 +01:00
<prompt>kadmin% </prompt><userinput>addprinc -randkey postgres/server.my.domain.org</userinput>
2017-10-09 03:44:17 +02:00
<prompt>kadmin% </prompt><userinput>ktadd -k krb5.keytab postgres/server.my.domain.org</userinput>
2014-01-15 17:24:01 +01:00
</screen>
</para>
<para>
2020-12-28 23:44:17 +01:00
The following authentication options are supported for
the <productname>GSSAPI</productname> authentication method:
2008-10-23 15:31:10 +02:00
<variablelist>
<varlistentry>
2010-02-20 20:21:14 +01:00
<term><literal>include_realm</literal></term>
2008-10-23 15:31:10 +02:00
<listitem>
<para>
2015-05-09 01:39:42 +02:00
If set to 0, the realm name from the authenticated user principal is
stripped off before being passed through the user name mapping
2017-11-23 15:39:47 +01:00
(<xref linkend="auth-username-maps"/>). This is discouraged and is
2016-05-06 23:42:44 +02:00
primarily available for backwards compatibility, as it is not secure
in multi-realm environments unless <literal>krb_realm</literal> is
also used. It is recommended to
leave <literal>include_realm</literal> set to the default (1) and to
2017-10-09 03:44:17 +02:00
provide an explicit mapping in <filename>pg_ident.conf</filename> to convert
principal names to <productname>PostgreSQL</productname> user names.
2008-10-23 15:31:10 +02:00
</para>
</listitem>
</varlistentry>
2009-01-07 13:38:11 +01:00
2009-01-07 14:09:21 +01:00
<varlistentry>
2010-02-20 20:21:14 +01:00
<term><literal>map</literal></term>
2009-01-07 14:09:21 +01:00
<listitem>
<para>
2020-12-28 23:44:17 +01:00
Allows mapping from client principals to database user names. See
2017-11-23 15:39:47 +01:00
<xref linkend="auth-username-maps"/> for details. For a GSSAPI/Kerberos
2015-05-09 01:39:42 +02:00
principal, such as <literal>username@EXAMPLE.COM</literal> (or, less
commonly, <literal>username/hostbased@EXAMPLE.COM</literal>), the
user name used for mapping is
<literal>username@EXAMPLE.COM</literal> (or
2015-05-16 19:28:26 +02:00
<literal>username/hostbased@EXAMPLE.COM</literal>, respectively),
2015-05-09 01:39:42 +02:00
unless <literal>include_realm</literal> has been set to 0, in which case
<literal>username</literal> (or <literal>username/hostbased</literal>)
2015-09-11 03:22:21 +02:00
is what is seen as the system user name when mapping.
2009-01-07 14:09:21 +01:00
</para>
</listitem>
</varlistentry>
2009-01-07 13:38:11 +01:00
<varlistentry>
2009-05-16 23:17:21 +02:00
<term><literal>krb_realm</literal></term>
2009-01-07 13:38:11 +01:00
<listitem>
<para>
2009-01-09 11:13:19 +01:00
Sets the realm to match user principal names against. If this parameter
2009-05-16 23:17:21 +02:00
is set, only users of that realm will be accepted. If it is not set,
2010-08-17 06:37:21 +02:00
users of any realm can connect, subject to whatever user name mapping
2009-05-16 23:17:21 +02:00
is done.
2009-01-07 13:38:11 +01:00
</para>
</listitem>
</varlistentry>
2008-10-23 15:31:10 +02:00
</variablelist>
</para>
2020-12-28 23:44:17 +01:00
<para>
In addition to these settings, which can be different for
different <filename>pg_hba.conf</filename> entries, there is the
server-wide <xref linkend="guc-krb-caseins-users"/> configuration
parameter. If that is set to true, client principals are matched to
user map entries case-insensitively. <literal>krb_realm</literal>, if
set, is also matched case-insensitively.
</para>
2018-04-12 02:33:53 +02:00
</sect1>
2007-07-18 14:00:47 +02:00
2018-04-12 02:33:53 +02:00
<sect1 id="sspi-auth">
2011-01-29 19:00:18 +01:00
<title>SSPI Authentication</title>
2007-07-23 12:16:54 +02:00
<indexterm zone="sspi-auth">
<primary>SSPI</primary>
</indexterm>
<para>
<productname>SSPI</productname> is a <productname>Windows</productname>
2009-05-16 23:17:21 +02:00
technology for secure authentication with single sign-on.
2007-07-23 12:16:54 +02:00
<productname>PostgreSQL</productname> will use SSPI in
<literal>negotiate</literal> mode, which will use
<productname>Kerberos</productname> when possible and automatically
fall back to <productname>NTLM</productname> in other cases.
2023-10-10 22:51:08 +02:00
<productname>SSPI</productname> and <productname>GSSAPI</productname>
interoperate as clients and servers, e.g., an
<productname>SSPI</productname> client can authenticate to an
<productname>GSSAPI</productname> server. It is recommended to use
<productname>SSPI</productname> on Windows clients and servers and
<productname>GSSAPI</productname> on non-Windows platforms.
2007-07-23 12:16:54 +02:00
</para>
<para>
2009-05-16 23:17:21 +02:00
When using <productname>Kerberos</productname> authentication,
<productname>SSPI</productname> works the same way
2017-11-23 15:39:47 +01:00
<productname>GSSAPI</productname> does; see <xref linkend="gssapi-auth"/>
2007-07-23 12:16:54 +02:00
for details.
</para>
2008-10-23 15:31:10 +02:00
<para>
The following configuration options are supported for <productname>SSPI</productname>:
<variablelist>
2010-02-20 22:04:28 +01:00
2008-10-23 15:31:10 +02:00
<varlistentry>
2010-02-20 22:04:28 +01:00
<term><literal>include_realm</literal></term>
2008-10-23 15:31:10 +02:00
<listitem>
<para>
2015-05-09 01:39:42 +02:00
If set to 0, the realm name from the authenticated user principal is
stripped off before being passed through the user name mapping
2017-11-23 15:39:47 +01:00
(<xref linkend="auth-username-maps"/>). This is discouraged and is
2016-05-06 23:42:44 +02:00
primarily available for backwards compatibility, as it is not secure
in multi-realm environments unless <literal>krb_realm</literal> is
also used. It is recommended to
leave <literal>include_realm</literal> set to the default (1) and to
2017-10-09 03:44:17 +02:00
provide an explicit mapping in <filename>pg_ident.conf</filename> to convert
principal names to <productname>PostgreSQL</productname> user names.
2008-10-23 15:31:10 +02:00
</para>
</listitem>
</varlistentry>
2009-01-07 13:38:11 +01:00
2016-04-08 20:23:52 +02:00
<varlistentry>
<term><literal>compat_realm</literal></term>
<listitem>
<para>
If set to 1, the domain's SAM-compatible name (also known as the
NetBIOS name) is used for the <literal>include_realm</literal>
option. This is the default. If set to 0, the true realm name from
the Kerberos user principal name is used.
</para>
<para>
2016-05-06 23:42:44 +02:00
Do not disable this option unless your server runs under a domain
2016-04-08 20:23:52 +02:00
account (this includes virtual service accounts on a domain member
system) and all clients authenticating through SSPI are also using
domain accounts, or authentication will fail.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><literal>upn_username</literal></term>
<listitem>
<para>
If this option is enabled along with <literal>compat_realm</literal>,
the user name from the Kerberos UPN is used for authentication. If
it is disabled (the default), the SAM-compatible user name is used.
By default, these two names are identical for new user accounts.
</para>
<para>
2017-10-09 03:44:17 +02:00
Note that <application>libpq</application> uses the SAM-compatible name if no
2016-04-08 20:23:52 +02:00
explicit user name is specified. If you use
2017-10-09 03:44:17 +02:00
<application>libpq</application> or a driver based on it, you should
2016-04-08 20:23:52 +02:00
leave this option disabled or explicitly specify user name in the
connection string.
</para>
</listitem>
</varlistentry>
2009-01-07 14:09:21 +01:00
<varlistentry>
2010-02-20 22:04:28 +01:00
<term><literal>map</literal></term>
2009-01-07 14:09:21 +01:00
<listitem>
<para>
2010-08-17 06:37:21 +02:00
Allows for mapping between system and database user names. See
2021-06-11 03:38:04 +02:00
<xref linkend="auth-username-maps"/> for details. For an SSPI/Kerberos
2015-05-09 01:39:42 +02:00
principal, such as <literal>username@EXAMPLE.COM</literal> (or, less
commonly, <literal>username/hostbased@EXAMPLE.COM</literal>), the
user name used for mapping is
<literal>username@EXAMPLE.COM</literal> (or
2015-05-16 19:28:26 +02:00
<literal>username/hostbased@EXAMPLE.COM</literal>, respectively),
2015-05-09 01:39:42 +02:00
unless <literal>include_realm</literal> has been set to 0, in which case
<literal>username</literal> (or <literal>username/hostbased</literal>)
2015-09-11 03:22:21 +02:00
is what is seen as the system user name when mapping.
2009-01-07 14:09:21 +01:00
</para>
</listitem>
</varlistentry>
2009-01-07 13:38:11 +01:00
<varlistentry>
2009-05-16 23:17:21 +02:00
<term><literal>krb_realm</literal></term>
2009-01-07 13:38:11 +01:00
<listitem>
<para>
2009-01-09 11:13:19 +01:00
Sets the realm to match user principal names against. If this parameter
2009-05-16 23:17:21 +02:00
is set, only users of that realm will be accepted. If it is not set,
2010-08-17 06:37:21 +02:00
users of any realm can connect, subject to whatever user name mapping
2009-05-16 23:17:21 +02:00
is done.
2009-01-07 13:38:11 +01:00
</para>
</listitem>
</varlistentry>
2008-10-23 15:31:10 +02:00
</variablelist>
</para>
2018-04-12 02:33:53 +02:00
</sect1>
2007-07-23 12:16:54 +02:00
2018-04-12 02:33:53 +02:00
<sect1 id="auth-ident">
2011-03-19 18:44:35 +01:00
<title>Ident Authentication</title>
2000-06-18 23:24:54 +02:00
2001-05-13 00:51:36 +02:00
<indexterm>
<primary>ident</primary>
</indexterm>
2002-09-14 20:35:46 +02:00
<para>
2004-12-27 00:06:56 +01:00
The ident authentication method works by obtaining the client's
2011-03-19 18:44:35 +01:00
operating system user name from an ident server and using it as
the allowed database user name (with an optional user name mapping).
This is only supported on TCP/IP connections.
2002-09-14 20:35:46 +02:00
</para>
2011-03-19 18:44:35 +01:00
<note>
<para>
When ident is specified for a local (non-TCP/IP) connection,
2017-11-23 15:39:47 +01:00
peer authentication (see <xref linkend="auth-peer"/>) will be
2011-03-19 18:44:35 +01:00
used instead.
</para>
</note>
2008-10-23 15:31:10 +02:00
<para>
2022-04-13 07:42:13 +02:00
The following configuration options are supported for <literal>ident</literal>:
2008-10-23 15:31:10 +02:00
<variablelist>
<varlistentry>
2009-05-16 23:17:21 +02:00
<term><literal>map</literal></term>
2008-10-23 15:31:10 +02:00
<listitem>
<para>
2010-08-17 06:37:21 +02:00
Allows for mapping between system and database user names. See
2017-11-23 15:39:47 +01:00
<xref linkend="auth-username-maps"/> for details.
2008-10-23 15:31:10 +02:00
</para>
</listitem>
</varlistentry>
</variablelist>
</para>
2000-06-18 23:24:54 +02:00
<para>
The <quote>Identification Protocol</quote> is described in
2024-04-10 13:53:25 +02:00
<ulink url="https://datatracker.ietf.org/doc/html/rfc1413">RFC 1413</ulink>.
2020-12-01 13:36:30 +01:00
Virtually every Unix-like
2001-03-15 21:01:32 +01:00
operating system ships with an ident server that listens on TCP
2000-07-04 18:32:01 +02:00
port 113 by default. The basic functionality of an ident server
2000-06-18 23:24:54 +02:00
is to answer questions like <quote>What user initiated the
connection that goes out of your port <replaceable>X</replaceable>
and connects to my port <replaceable>Y</replaceable>?</quote>.
2017-10-09 03:44:17 +02:00
Since <productname>PostgreSQL</productname> knows both <replaceable>X</replaceable> and
<replaceable>Y</replaceable> when a physical connection is established, it
2000-07-04 18:32:01 +02:00
can interrogate the ident server on the host of the connecting
2010-02-03 18:25:06 +01:00
client and can theoretically determine the operating system user
for any given connection.
2000-06-18 23:24:54 +02:00
</para>
<para>
The drawback of this procedure is that it depends on the integrity
2010-02-03 18:25:06 +01:00
of the client: if the client machine is untrusted or compromised,
2000-06-18 23:24:54 +02:00
an attacker could run just about any program on port 113 and
2015-09-22 04:57:29 +02:00
return any user name they choose. This authentication method is
2000-06-18 23:24:54 +02:00
therefore only appropriate for closed networks where each client
machine is under tight control and where the database and system
2001-10-05 00:27:18 +02:00
administrators operate in close contact. In other words, you must
trust the machine running the ident server.
Heed the warning:
2000-06-18 23:24:54 +02:00
<blockquote>
<attribution>RFC 1413</attribution>
<para>
The Identification Protocol is not intended as an authorization
2001-07-11 23:27:07 +02:00
or access control protocol.
2000-06-18 23:24:54 +02:00
</para>
</blockquote>
</para>
2005-01-28 23:38:37 +01:00
<para>
Some ident servers have a nonstandard option that causes the returned
user name to be encrypted, using a key that only the originating
2017-10-09 03:44:17 +02:00
machine's administrator knows. This option <emphasis>must not</emphasis> be
used when using the ident server with <productname>PostgreSQL</productname>,
since <productname>PostgreSQL</productname> does not have any way to decrypt the
2005-01-28 23:38:37 +01:00
returned string to determine the actual user name.
</para>
2018-04-12 02:33:53 +02:00
</sect1>
2002-09-14 20:35:46 +02:00
2018-04-12 02:33:53 +02:00
<sect1 id="auth-peer">
2011-03-19 18:44:35 +01:00
<title>Peer Authentication</title>
<indexterm>
<primary>peer</primary>
</indexterm>
2000-06-18 23:24:54 +02:00
2001-08-02 01:25:39 +02:00
<para>
2011-03-19 18:44:35 +01:00
The peer authentication method works by obtaining the client's
operating system user name from the kernel and using it as the
allowed database user name (with optional user name mapping). This
Replace use of credential control messages with getsockopt(LOCAL_PEERCRED).
It turns out the reason we hadn't found out about the portability issues
with our credential-control-message code is that almost no modern platforms
use that code at all; the ones that used to need it now offer getpeereid(),
which we choose first. The last holdout was NetBSD, and they added
getpeereid() as of 5.0. So far as I can tell, the only live platform on
which that code was being exercised was Debian/kFreeBSD, ie, FreeBSD kernel
with Linux userland --- since glibc doesn't provide getpeereid(), we fell
back to the control message code. However, the FreeBSD kernel provides a
LOCAL_PEERCRED socket parameter that's functionally equivalent to Linux's
SO_PEERCRED. That is both much simpler to use than control messages, and
superior because it doesn't require receiving a message from the other end
at just the right time.
Therefore, add code to use LOCAL_PEERCRED when necessary, and rip out all
the credential-control-message code in the backend. (libpq still has such
code so that it can still talk to pre-9.1 servers ... but eventually we can
get rid of it there too.) Clean up related autoconf probes, too.
This means that libpq's requirepeer parameter now works on exactly the same
platforms where the backend supports peer authentication, so adjust the
documentation accordingly.
2011-05-31 22:10:46 +02:00
method is only supported on local connections.
2011-03-19 18:44:35 +01:00
</para>
<para>
2022-04-13 07:42:13 +02:00
The following configuration options are supported for <literal>peer</literal>:
2011-03-19 18:44:35 +01:00
<variablelist>
<varlistentry>
<term><literal>map</literal></term>
<listitem>
<para>
Allows for mapping between system and database user names. See
2017-11-23 15:39:47 +01:00
<xref linkend="auth-username-maps"/> for details.
2011-03-19 18:44:35 +01:00
</para>
</listitem>
</varlistentry>
</variablelist>
</para>
<para>
Replace use of credential control messages with getsockopt(LOCAL_PEERCRED).
It turns out the reason we hadn't found out about the portability issues
with our credential-control-message code is that almost no modern platforms
use that code at all; the ones that used to need it now offer getpeereid(),
which we choose first. The last holdout was NetBSD, and they added
getpeereid() as of 5.0. So far as I can tell, the only live platform on
which that code was being exercised was Debian/kFreeBSD, ie, FreeBSD kernel
with Linux userland --- since glibc doesn't provide getpeereid(), we fell
back to the control message code. However, the FreeBSD kernel provides a
LOCAL_PEERCRED socket parameter that's functionally equivalent to Linux's
SO_PEERCRED. That is both much simpler to use than control messages, and
superior because it doesn't require receiving a message from the other end
at just the right time.
Therefore, add code to use LOCAL_PEERCRED when necessary, and rip out all
the credential-control-message code in the backend. (libpq still has such
code so that it can still talk to pre-9.1 servers ... but eventually we can
get rid of it there too.) Clean up related autoconf probes, too.
This means that libpq's requirepeer parameter now works on exactly the same
platforms where the backend supports peer authentication, so adjust the
documentation accordingly.
2011-05-31 22:10:46 +02:00
Peer authentication is only available on operating systems providing
2017-10-09 03:44:17 +02:00
the <function>getpeereid()</function> function, the <symbol>SO_PEERCRED</symbol>
Replace use of credential control messages with getsockopt(LOCAL_PEERCRED).
It turns out the reason we hadn't found out about the portability issues
with our credential-control-message code is that almost no modern platforms
use that code at all; the ones that used to need it now offer getpeereid(),
which we choose first. The last holdout was NetBSD, and they added
getpeereid() as of 5.0. So far as I can tell, the only live platform on
which that code was being exercised was Debian/kFreeBSD, ie, FreeBSD kernel
with Linux userland --- since glibc doesn't provide getpeereid(), we fell
back to the control message code. However, the FreeBSD kernel provides a
LOCAL_PEERCRED socket parameter that's functionally equivalent to Linux's
SO_PEERCRED. That is both much simpler to use than control messages, and
superior because it doesn't require receiving a message from the other end
at just the right time.
Therefore, add code to use LOCAL_PEERCRED when necessary, and rip out all
the credential-control-message code in the backend. (libpq still has such
code so that it can still talk to pre-9.1 servers ... but eventually we can
get rid of it there too.) Clean up related autoconf probes, too.
This means that libpq's requirepeer parameter now works on exactly the same
platforms where the backend supports peer authentication, so adjust the
documentation accordingly.
2011-05-31 22:10:46 +02:00
socket parameter, or similar mechanisms. Currently that includes
2017-10-09 03:44:17 +02:00
<systemitem class="osname">Linux</systemitem>,
most flavors of <systemitem class="osname">BSD</systemitem> including
<systemitem class="osname">macOS</systemitem>,
Replace use of credential control messages with getsockopt(LOCAL_PEERCRED).
It turns out the reason we hadn't found out about the portability issues
with our credential-control-message code is that almost no modern platforms
use that code at all; the ones that used to need it now offer getpeereid(),
which we choose first. The last holdout was NetBSD, and they added
getpeereid() as of 5.0. So far as I can tell, the only live platform on
which that code was being exercised was Debian/kFreeBSD, ie, FreeBSD kernel
with Linux userland --- since glibc doesn't provide getpeereid(), we fell
back to the control message code. However, the FreeBSD kernel provides a
LOCAL_PEERCRED socket parameter that's functionally equivalent to Linux's
SO_PEERCRED. That is both much simpler to use than control messages, and
superior because it doesn't require receiving a message from the other end
at just the right time.
Therefore, add code to use LOCAL_PEERCRED when necessary, and rip out all
the credential-control-message code in the backend. (libpq still has such
code so that it can still talk to pre-9.1 servers ... but eventually we can
get rid of it there too.) Clean up related autoconf probes, too.
This means that libpq's requirepeer parameter now works on exactly the same
platforms where the backend supports peer authentication, so adjust the
documentation accordingly.
2011-05-31 22:10:46 +02:00
and <systemitem class="osname">Solaris</systemitem>.
2001-08-02 01:25:39 +02:00
</para>
2018-04-12 02:33:53 +02:00
</sect1>
2002-09-14 20:35:46 +02:00
2018-04-12 02:33:53 +02:00
<sect1 id="auth-ldap">
2011-01-29 19:00:18 +01:00
<title>LDAP Authentication</title>
2006-06-16 17:16:16 +02:00
<indexterm zone="auth-ldap">
<primary>LDAP</primary>
</indexterm>
<para>
This authentication method operates similarly to
<literal>password</literal> except that it uses LDAP
2008-10-23 15:31:10 +02:00
as the password verification method. LDAP is used only to validate
2006-06-16 17:16:16 +02:00
the user name/password pairs. Therefore the user must already
exist in the database before LDAP can be used for
2008-10-23 15:31:10 +02:00
authentication.
2006-06-16 17:16:16 +02:00
</para>
2008-10-23 15:31:10 +02:00
2006-06-16 17:16:16 +02:00
<para>
2009-12-12 22:35:21 +01:00
LDAP authentication can operate in two modes. In the first mode,
2012-10-06 03:20:06 +02:00
which we will call the simple bind mode,
2009-12-12 22:35:21 +01:00
the server will bind to the distinguished name constructed as
2017-10-09 03:44:17 +02:00
<replaceable>prefix</replaceable> <replaceable>username</replaceable> <replaceable>suffix</replaceable>.
Typically, the <replaceable>prefix</replaceable> parameter is used to specify
<literal>cn=</literal>, or <replaceable>DOMAIN</replaceable><literal>\</literal> in an Active
Directory environment. <replaceable>suffix</replaceable> is used to specify the
2009-05-16 23:17:21 +02:00
remaining part of the DN in a non-Active Directory environment.
2006-06-16 17:16:16 +02:00
</para>
2008-10-23 15:31:10 +02:00
2009-12-12 22:35:21 +01:00
<para>
2012-10-06 03:20:06 +02:00
In the second mode, which we will call the search+bind mode,
the server first binds to the LDAP directory with
2017-10-09 03:44:17 +02:00
a fixed user name and password, specified with <replaceable>ldapbinddn</replaceable>
and <replaceable>ldapbindpasswd</replaceable>, and performs a search for the user trying
2009-12-12 22:35:21 +01:00
to log in to the database. If no user and password is configured, an
anonymous bind will be attempted to the directory. The search will be
2017-10-09 03:44:17 +02:00
performed over the subtree at <replaceable>ldapbasedn</replaceable>, and will try to
2009-12-12 22:35:21 +01:00
do an exact match of the attribute specified in
2017-10-09 03:44:17 +02:00
<replaceable>ldapsearchattribute</replaceable>.
2012-10-06 03:20:06 +02:00
Once the user has been found in
2023-07-09 08:22:34 +02:00
this search, the server re-binds to the directory as
2009-12-12 22:35:21 +01:00
this user, using the password specified by the client, to verify that the
2012-10-06 03:20:06 +02:00
login is correct. This mode is the same as that used by LDAP authentication
2015-09-11 03:22:21 +02:00
schemes in other software, such as Apache <literal>mod_authnz_ldap</literal> and <literal>pam_ldap</literal>.
2012-10-06 03:20:06 +02:00
This method allows for significantly more flexibility
2009-12-12 22:35:21 +01:00
in where the user objects are located in the directory, but will cause
2023-07-09 08:22:34 +02:00
two additional requests to the LDAP server to be made.
2009-12-12 22:35:21 +01:00
</para>
2008-10-23 15:31:10 +02:00
<para>
2012-10-06 03:20:06 +02:00
The following configuration options are used in both modes:
2008-10-23 15:31:10 +02:00
<variablelist>
<varlistentry>
2009-05-16 23:17:21 +02:00
<term><literal>ldapserver</literal></term>
2008-10-23 15:31:10 +02:00
<listitem>
<para>
2011-11-01 15:44:26 +01:00
Names or IP addresses of LDAP servers to connect to. Multiple
servers may be specified, separated by spaces.
2008-10-23 15:31:10 +02:00
</para>
</listitem>
</varlistentry>
2009-12-12 22:35:21 +01:00
<varlistentry>
<term><literal>ldapport</literal></term>
<listitem>
<para>
Port number on LDAP server to connect to. If no port is specified,
2010-05-27 01:49:19 +02:00
the LDAP library's default port setting will be used.
2009-12-12 22:35:21 +01:00
</para>
</listitem>
</varlistentry>
2018-01-03 16:00:08 +01:00
<varlistentry>
<term><literal>ldapscheme</literal></term>
<listitem>
<para>
Set to <literal>ldaps</literal> to use LDAPS. This is a non-standard
way of using LDAP over SSL, supported by some LDAP server
implementations. See also the <literal>ldaptls</literal> option for
an alternative.
</para>
</listitem>
</varlistentry>
2009-12-12 22:35:21 +01:00
<varlistentry>
<term><literal>ldaptls</literal></term>
<listitem>
<para>
2018-01-03 16:00:08 +01:00
Set to 1 to make the connection between PostgreSQL and the LDAP server
use TLS encryption. This uses the <literal>StartTLS</literal>
2024-04-10 13:53:25 +02:00
operation per <ulink url="https://datatracker.ietf.org/doc/html/rfc4513">RFC 4513</ulink>.
2020-12-01 13:36:30 +01:00
See also the <literal>ldapscheme</literal> option for an alternative.
2009-12-12 22:35:21 +01:00
</para>
</listitem>
</varlistentry>
2012-10-06 03:20:06 +02:00
</variablelist>
2018-01-03 16:00:08 +01:00
</para>
<para>
Note that using <literal>ldapscheme</literal> or
<literal>ldaptls</literal> only encrypts the traffic between the
PostgreSQL server and the LDAP server. The connection between the
PostgreSQL server and the PostgreSQL client will still be unencrypted
unless SSL is used there as well.
</para>
2012-10-06 03:20:06 +02:00
2018-01-03 16:00:08 +01:00
<para>
2012-10-06 03:20:06 +02:00
The following options are used in simple bind mode only:
<variablelist>
2008-10-23 15:31:10 +02:00
<varlistentry>
2009-05-16 23:17:21 +02:00
<term><literal>ldapprefix</literal></term>
2008-10-23 15:31:10 +02:00
<listitem>
<para>
2010-08-17 06:37:21 +02:00
String to prepend to the user name when forming the DN to bind as,
2009-12-12 22:35:21 +01:00
when doing simple bind authentication.
2008-10-23 15:31:10 +02:00
</para>
</listitem>
</varlistentry>
<varlistentry>
2009-05-16 23:17:21 +02:00
<term><literal>ldapsuffix</literal></term>
2008-10-23 15:31:10 +02:00
<listitem>
<para>
2010-08-17 06:37:21 +02:00
String to append to the user name when forming the DN to bind as,
2009-12-12 22:35:21 +01:00
when doing simple bind authentication.
2008-10-23 15:31:10 +02:00
</para>
</listitem>
</varlistentry>
2012-10-06 03:20:06 +02:00
</variablelist>
2018-01-03 16:00:08 +01:00
</para>
2012-10-06 03:20:06 +02:00
2018-01-03 16:00:08 +01:00
<para>
2012-10-06 03:20:06 +02:00
The following options are used in search+bind mode only:
<variablelist>
2008-10-23 15:31:10 +02:00
<varlistentry>
2009-12-12 22:35:21 +01:00
<term><literal>ldapbasedn</literal></term>
2008-10-23 15:31:10 +02:00
<listitem>
<para>
2010-05-27 01:49:19 +02:00
Root DN to begin the search for the user in, when doing search+bind
2009-12-12 22:35:21 +01:00
authentication.
2008-10-23 15:31:10 +02:00
</para>
</listitem>
</varlistentry>
<varlistentry>
2009-12-12 22:35:21 +01:00
<term><literal>ldapbinddn</literal></term>
2008-10-23 15:31:10 +02:00
<listitem>
<para>
2009-12-12 22:35:21 +01:00
DN of user to bind to the directory with to perform the search when
doing search+bind authentication.
2008-10-23 15:31:10 +02:00
</para>
</listitem>
</varlistentry>
2009-12-12 22:35:21 +01:00
<varlistentry>
<term><literal>ldapbindpasswd</literal></term>
<listitem>
<para>
Password for user to bind to the directory with to perform the search
when doing search+bind authentication.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><literal>ldapsearchattribute</literal></term>
<listitem>
<para>
2010-08-17 06:37:21 +02:00
Attribute to match against the user name in the search when doing
2012-10-06 03:20:06 +02:00
search+bind authentication. If no attribute is specified, the
2017-10-09 03:44:17 +02:00
<literal>uid</literal> attribute will be used.
2009-12-12 22:35:21 +01:00
</para>
</listitem>
</varlistentry>
2017-09-12 15:46:14 +02:00
<varlistentry>
<term><literal>ldapsearchfilter</literal></term>
<listitem>
<para>
The search filter to use when doing search+bind authentication.
Occurrences of <literal>$username</literal> will be replaced with the
user name. This allows for more flexible search filters than
<literal>ldapsearchattribute</literal>.
</para>
</listitem>
</varlistentry>
2012-12-04 05:29:56 +01:00
<varlistentry>
<term><literal>ldapurl</literal></term>
<listitem>
<para>
2024-04-10 13:53:25 +02:00
An <ulink url="https://datatracker.ietf.org/doc/html/rfc4516">RFC 4516</ulink>
2020-12-01 13:36:30 +01:00
LDAP URL. This is an alternative way to write some of the
2012-12-04 05:29:56 +01:00
other LDAP options in a more compact and standard form. The format is
<synopsis>
2018-01-03 16:00:08 +01:00
ldap[s]://<replaceable>host</replaceable>[:<replaceable>port</replaceable>]/<replaceable>basedn</replaceable>[?[<replaceable>attribute</replaceable>][?[<replaceable>scope</replaceable>][?[<replaceable>filter</replaceable>]]]]
2012-12-04 05:29:56 +01:00
</synopsis>
<replaceable>scope</replaceable> must be one
of <literal>base</literal>, <literal>one</literal>, <literal>sub</literal>,
2017-09-12 16:02:34 +02:00
typically the last. (The default is <literal>base</literal>, which
is normally not useful in this application.) <replaceable>attribute</replaceable> can
2017-09-12 15:46:14 +02:00
nominate a single attribute, in which case it is used as a value for
<literal>ldapsearchattribute</literal>. If
<replaceable>attribute</replaceable> is empty then
<replaceable>filter</replaceable> can be used as a value for
<literal>ldapsearchfilter</literal>.
2012-12-04 05:29:56 +01:00
</para>
2012-12-31 06:24:16 +01:00
<para>
2018-01-03 16:00:08 +01:00
The URL scheme <literal>ldaps</literal> chooses the LDAPS method for
making LDAP connections over SSL, equivalent to using
<literal>ldapscheme=ldaps</literal>. To use encrypted LDAP
connections using the <literal>StartTLS</literal> operation, use the
normal URL scheme <literal>ldap</literal> and specify the
<literal>ldaptls</literal> option in addition to
<literal>ldapurl</literal>.
2012-12-31 06:24:16 +01:00
</para>
2012-12-04 05:29:56 +01:00
<para>
2018-01-03 16:00:08 +01:00
For non-anonymous binds, <literal>ldapbinddn</literal>
and <literal>ldapbindpasswd</literal> must be specified as separate
options.
2012-12-04 05:29:56 +01:00
</para>
<para>
2019-03-21 03:19:03 +01:00
LDAP URLs are currently only supported with
<productname>OpenLDAP</productname>, not on Windows.
2012-12-04 05:29:56 +01:00
</para>
</listitem>
</varlistentry>
2008-10-23 15:31:10 +02:00
</variablelist>
</para>
2012-10-06 03:20:06 +02:00
<para>
It is an error to mix configuration options for simple bind with options
for search+bind.
</para>
2017-09-12 15:46:14 +02:00
<para>
When using search+bind mode, the search can be performed using a single
attribute specified with <literal>ldapsearchattribute</literal>, or using
a custom search filter specified with
<literal>ldapsearchfilter</literal>.
Specifying <literal>ldapsearchattribute=foo</literal> is equivalent to
specifying <literal>ldapsearchfilter="(foo=$username)"</literal>. If neither
option is specified the default is
<literal>ldapsearchattribute=uid</literal>.
</para>
2019-03-21 03:19:03 +01:00
<para>
If <productname>PostgreSQL</productname> was compiled with
<productname>OpenLDAP</productname> as the LDAP client library, the
<literal>ldapserver</literal> setting may be omitted. In that case, a
2020-12-01 13:36:30 +01:00
list of host names and ports is looked up via
2024-04-10 13:53:25 +02:00
<ulink url="https://datatracker.ietf.org/doc/html/rfc2782">RFC 2782</ulink> DNS SRV records.
2019-03-21 03:19:03 +01:00
The name <literal>_ldap._tcp.DOMAIN</literal> is looked up, where
<literal>DOMAIN</literal> is extracted from <literal>ldapbasedn</literal>.
</para>
2012-10-06 03:20:06 +02:00
<para>
Here is an example for a simple-bind LDAP configuration:
<programlisting>
host ... ldap ldapserver=ldap.example.net ldapprefix="cn=" ldapsuffix=", dc=example, dc=net"
</programlisting>
When a connection to the database server as database
user <literal>someuser</literal> is requested, PostgreSQL will attempt to
bind to the LDAP server using the DN <literal>cn=someuser, dc=example,
dc=net</literal> and the password provided by the client. If that connection
succeeds, the database access is granted.
</para>
<para>
2012-11-02 03:58:36 +01:00
Here is an example for a search+bind configuration:
2012-10-06 03:20:06 +02:00
<programlisting>
host ... ldap ldapserver=ldap.example.net ldapbasedn="dc=example, dc=net" ldapsearchattribute=uid
</programlisting>
When a connection to the database server as database
user <literal>someuser</literal> is requested, PostgreSQL will attempt to
bind anonymously (since <literal>ldapbinddn</literal> was not specified) to
the LDAP server, perform a search for <literal>(uid=someuser)</literal>
under the specified base DN. If an entry is found, it will then attempt to
bind using that found information and the password supplied by the client.
2023-07-09 08:22:34 +02:00
If that second bind succeeds, the database access is granted.
2012-10-06 03:20:06 +02:00
</para>
2012-12-04 05:29:56 +01:00
<para>
Here is the same search+bind configuration written as a URL:
<programlisting>
2015-08-09 14:49:47 +02:00
host ... ldap ldapurl="ldap://ldap.example.net/dc=example,dc=net?uid?sub"
2012-12-04 05:29:56 +01:00
</programlisting>
Some other software that supports authentication against LDAP uses the
same URL format, so it will be easier to share the configuration.
</para>
2017-09-12 15:46:14 +02:00
<para>
Here is an example for a search+bind configuration that uses
<literal>ldapsearchfilter</literal> instead of
<literal>ldapsearchattribute</literal> to allow authentication by
user ID or email address:
<programlisting>
host ... ldap ldapserver=ldap.example.net ldapbasedn="dc=example, dc=net" ldapsearchfilter="(|(uid=$username)(mail=$username))"
</programlisting>
</para>
2019-03-21 03:19:03 +01:00
<para>
Here is an example for a search+bind configuration that uses DNS SRV
2019-07-05 08:33:51 +02:00
discovery to find the host name(s) and port(s) for the LDAP service for the
2019-03-21 03:19:03 +01:00
domain name <literal>example.net</literal>:
<programlisting>
host ... ldap ldapbasedn="dc=example,dc=net"
</programlisting>
</para>
2012-10-06 03:20:06 +02:00
<tip>
2008-10-23 15:31:10 +02:00
<para>
Since LDAP often uses commas and spaces to separate the different
2009-05-16 23:17:21 +02:00
parts of a DN, it is often necessary to use double-quoted parameter
2012-10-06 03:20:06 +02:00
values when configuring LDAP options, as shown in the examples.
2008-10-23 15:31:10 +02:00
</para>
2012-10-06 03:20:06 +02:00
</tip>
2008-10-23 15:31:10 +02:00
2018-04-12 02:33:53 +02:00
</sect1>
2006-06-16 17:16:16 +02:00
2018-04-12 02:33:53 +02:00
<sect1 id="auth-radius">
2011-01-29 19:00:18 +01:00
<title>RADIUS Authentication</title>
2010-01-27 13:12:00 +01:00
<indexterm zone="auth-radius">
<primary>RADIUS</primary>
</indexterm>
<para>
This authentication method operates similarly to
<literal>password</literal> except that it uses RADIUS
as the password verification method. RADIUS is used only to validate
the user name/password pairs. Therefore the user must already
exist in the database before RADIUS can be used for
authentication.
</para>
<para>
When using RADIUS authentication, an Access Request message will be sent
to the configured RADIUS server. This request will be of type
<literal>Authenticate Only</literal>, and include parameters for
2017-10-09 03:44:17 +02:00
<literal>user name</literal>, <literal>password</literal> (encrypted) and
<literal>NAS Identifier</literal>. The request will be encrypted using
2010-01-27 13:12:00 +01:00
a secret shared with the server. The RADIUS server will respond to
2019-11-13 19:41:04 +01:00
this request with either <literal>Access Accept</literal> or
2017-10-09 03:44:17 +02:00
<literal>Access Reject</literal>. There is no support for RADIUS accounting.
2010-01-27 13:12:00 +01:00
</para>
2017-03-22 17:55:16 +01:00
<para>
Multiple RADIUS servers can be specified, in which case they will
be tried sequentially. If a negative response is received from
a server, the authentication will fail. If no response is received,
the next server in the list will be tried. To specify multiple
2019-11-13 19:41:04 +01:00
servers, separate the server names with commas and surround the list
with double quotes. If multiple servers are specified, the other
RADIUS options can also be given as comma-separated lists, to provide
individual values for each server. They can also be specified as
a single value, in which case that value will apply to all servers.
2017-03-22 17:55:16 +01:00
</para>
2010-01-27 13:12:00 +01:00
<para>
The following configuration options are supported for RADIUS:
<variablelist>
<varlistentry>
2017-03-22 17:55:16 +01:00
<term><literal>radiusservers</literal></term>
2010-01-27 13:12:00 +01:00
<listitem>
<para>
2019-11-13 19:41:04 +01:00
The DNS names or IP addresses of the RADIUS servers to connect to.
2010-02-02 20:09:37 +01:00
This parameter is required.
2010-01-27 13:12:00 +01:00
</para>
</listitem>
</varlistentry>
<varlistentry>
2017-03-22 17:55:16 +01:00
<term><literal>radiussecrets</literal></term>
2010-01-27 13:12:00 +01:00
<listitem>
<para>
2017-03-22 17:55:16 +01:00
The shared secrets used when talking securely to the RADIUS
2019-11-13 19:41:04 +01:00
servers. This must have exactly the same value on the PostgreSQL
2010-05-27 01:49:19 +02:00
and RADIUS servers. It is recommended that this be a string of
2010-01-27 13:12:00 +01:00
at least 16 characters. This parameter is required.
<note>
<para>
The encryption vector used will only be cryptographically
2017-10-09 03:44:17 +02:00
strong if <productname>PostgreSQL</productname> is built with support for
<productname>OpenSSL</productname>. In other cases, the transmission to the
2010-01-27 13:12:00 +01:00
RADIUS server should only be considered obfuscated, not secured, and
external security measures should be applied if necessary.
</para>
</note>
</para>
</listitem>
</varlistentry>
<varlistentry>
2017-03-22 17:55:16 +01:00
<term><literal>radiusports</literal></term>
2010-01-27 13:12:00 +01:00
<listitem>
<para>
2019-11-13 19:41:04 +01:00
The port numbers to connect to on the RADIUS servers. If no port
is specified, the default RADIUS port (<literal>1812</literal>)
will be used.
2010-01-27 13:12:00 +01:00
</para>
</listitem>
</varlistentry>
<varlistentry>
2017-03-22 17:55:16 +01:00
<term><literal>radiusidentifiers</literal></term>
2010-01-27 13:12:00 +01:00
<listitem>
<para>
2019-11-13 19:41:04 +01:00
The strings to be used as <literal>NAS Identifier</literal> in the
RADIUS requests. This parameter can be used, for example, to
identify which database cluster the user is attempting to connect
to, which can be useful for policy matching on
2010-01-27 13:12:00 +01:00
the RADIUS server. If no identifier is specified, the default
2017-10-09 03:44:17 +02:00
<literal>postgresql</literal> will be used.
2010-01-27 13:12:00 +01:00
</para>
</listitem>
</varlistentry>
</variablelist>
</para>
2019-11-13 19:41:04 +01:00
<para>
If it is necessary to have a comma or whitespace in a RADIUS parameter
value, that can be done by putting double quotes around the value, but
it is tedious because two layers of double-quoting are now required.
An example of putting whitespace into RADIUS secret strings is:
<programlisting>
host ... radius radiusservers="server1,server2" radiussecrets="""secret one"",""secret two"""
</programlisting>
</para>
2018-04-12 02:33:53 +02:00
</sect1>
2010-01-27 13:12:00 +01:00
2018-04-12 02:33:53 +02:00
<sect1 id="auth-cert">
2011-01-29 19:00:18 +01:00
<title>Certificate Authentication</title>
2008-11-20 12:48:26 +01:00
<indexterm zone="auth-cert">
<primary>Certificate</primary>
</indexterm>
<para>
This authentication method uses SSL client certificates to perform
2023-10-10 21:54:29 +02:00
authentication. It is therefore only available for SSL connections;
see <xref linkend="ssl-openssl-config"/> for SSL configuration instructions.
2008-11-20 12:48:26 +01:00
When using this authentication method, the server will require that
2016-07-16 20:12:44 +02:00
the client provide a valid, trusted certificate. No password prompt
will be sent to the client. The <literal>cn</literal> (Common Name)
attribute of the certificate
2010-08-17 06:37:21 +02:00
will be compared to the requested database user name, and if they match
the login will be allowed. User name mapping can be used to allow
<literal>cn</literal> to be different from the database user name.
2009-05-16 23:17:21 +02:00
</para>
<para>
The following configuration options are supported for SSL certificate
authentication:
<variablelist>
<varlistentry>
<term><literal>map</literal></term>
<listitem>
<para>
2010-08-17 06:37:21 +02:00
Allows for mapping between system and database user names. See
2017-11-23 15:39:47 +01:00
<xref linkend="auth-username-maps"/> for details.
2009-05-16 23:17:21 +02:00
</para>
</listitem>
</varlistentry>
</variablelist>
2008-11-20 12:48:26 +01:00
</para>
2016-07-16 20:12:44 +02:00
<para>
2020-10-05 21:48:40 +02:00
It is redundant to use the <literal>clientcert</literal> option with
<literal>cert</literal> authentication because <literal>cert</literal>
authentication is effectively <literal>trust</literal> authentication
with <literal>clientcert=verify-full</literal>.
2016-07-16 20:12:44 +02:00
</para>
2018-04-12 02:33:53 +02:00
</sect1>
2008-11-20 12:48:26 +01:00
2018-04-12 02:33:53 +02:00
<sect1 id="auth-pam">
2011-01-29 19:00:18 +01:00
<title>PAM Authentication</title>
2002-09-14 20:35:46 +02:00
2003-08-31 19:32:24 +02:00
<indexterm zone="auth-pam">
<primary>PAM</primary>
</indexterm>
2002-09-14 20:35:46 +02:00
<para>
2003-03-13 02:30:29 +01:00
This authentication method operates similarly to
<literal>password</literal> except that it uses PAM (Pluggable
2002-09-14 20:35:46 +02:00
Authentication Modules) as the authentication mechanism. The
2008-10-23 15:31:10 +02:00
default PAM service name is <literal>postgresql</literal>.
2016-04-08 16:45:16 +02:00
PAM is used only to validate user name/password pairs and optionally the
connected remote host name or IP address. Therefore the user must already
exist in the database before PAM can be used for authentication. For more
information about PAM, please read the
2018-07-16 10:44:06 +02:00
<ulink url="https://www.kernel.org/pub/linux/libs/pam/">
2017-10-09 03:44:17 +02:00
<productname>Linux-PAM</productname> Page</ulink>.
2002-09-14 20:35:46 +02:00
</para>
2007-09-14 05:53:54 +02:00
2008-10-23 15:31:10 +02:00
<para>
The following configuration options are supported for PAM:
<variablelist>
<varlistentry>
2009-05-16 23:17:21 +02:00
<term><literal>pamservice</literal></term>
2008-10-23 15:31:10 +02:00
<listitem>
<para>
PAM service name.
</para>
</listitem>
</varlistentry>
2016-04-08 16:45:16 +02:00
<varlistentry>
<term><literal>pam_use_hostname</literal></term>
<listitem>
<para>
Determines whether the remote IP address or the host name is provided
to PAM modules through the <symbol>PAM_RHOST</symbol> item. By
default, the IP address is used. Set this option to 1 to use the
resolved host name instead. Host name resolution can lead to login
delays. (Most PAM configurations don't use this information, so it is
only necessary to consider this setting if a PAM configuration was
specifically created to make use of it.)
</para>
</listitem>
</varlistentry>
2008-10-23 15:31:10 +02:00
</variablelist>
</para>
2007-09-14 05:53:54 +02:00
<note>
<para>
2017-10-09 03:44:17 +02:00
If PAM is set up to read <filename>/etc/shadow</filename>, authentication
2007-12-29 05:15:38 +01:00
will fail because the PostgreSQL server is started by a non-root
2009-05-16 23:17:21 +02:00
user. However, this is not an issue when PAM is configured to use
LDAP or other authentication methods.
2007-09-14 05:53:54 +02:00
</para>
</note>
2018-04-12 02:33:53 +02:00
</sect1>
2016-04-08 19:51:54 +02:00
2018-04-12 02:33:53 +02:00
<sect1 id="auth-bsd">
2016-04-08 19:51:54 +02:00
<title>BSD Authentication</title>
<indexterm zone="auth-bsd">
<primary>BSD Authentication</primary>
</indexterm>
<para>
This authentication method operates similarly to
<literal>password</literal> except that it uses BSD Authentication
to verify the password. BSD Authentication is used only
to validate user name/password pairs. Therefore the user's role must
already exist in the database before BSD Authentication can be used
for authentication. The BSD Authentication framework is currently
only available on OpenBSD.
</para>
<para>
2017-10-09 03:44:17 +02:00
BSD Authentication in <productname>PostgreSQL</productname> uses
2016-04-08 19:51:54 +02:00
the <literal>auth-postgresql</literal> login type and authenticates with
the <literal>postgresql</literal> login class if that's defined
in <filename>login.conf</filename>. By default that login class does not
2017-10-09 03:44:17 +02:00
exist, and <productname>PostgreSQL</productname> will use the default login class.
2016-04-08 19:51:54 +02:00
</para>
<note>
<para>
To use BSD Authentication, the PostgreSQL user account (that is, the
operating system user running the server) must first be added to
the <literal>auth</literal> group. The <literal>auth</literal> group
exists by default on OpenBSD systems.
</para>
</note>
2018-04-12 02:33:53 +02:00
</sect1>
2000-06-18 23:24:54 +02:00
<sect1 id="client-authentication-problems">
2011-01-29 19:00:18 +01:00
<title>Authentication Problems</title>
2000-06-18 23:24:54 +02:00
<para>
2009-05-16 23:17:21 +02:00
Authentication failures and related problems generally
manifest themselves through error messages like the following:
2000-06-18 23:24:54 +02:00
</para>
<para>
2005-01-23 01:30:59 +01:00
<programlisting>
2003-09-13 00:17:24 +02:00
FATAL: no pg_hba.conf entry for host "123.123.123.123", user "andym", database "testdb"
2005-01-23 01:30:59 +01:00
</programlisting>
2002-04-04 06:25:54 +02:00
This is what you are most likely to get if you succeed in contacting
the server, but it does not want to talk to you. As the message
suggests, the server refused the connection request because it found
2005-08-15 01:35:38 +02:00
no matching entry in its <filename>pg_hba.conf</filename>
2000-06-18 23:24:54 +02:00
configuration file.
</para>
<para>
2005-01-23 01:30:59 +01:00
<programlisting>
2010-05-27 01:49:19 +02:00
FATAL: password authentication failed for user "andym"
2005-01-23 01:30:59 +01:00
</programlisting>
2002-04-04 06:25:54 +02:00
Messages like this indicate that you contacted the server, and it is
willing to talk to you, but not until you pass the authorization
method specified in the <filename>pg_hba.conf</filename> file. Check
the password you are providing, or check your Kerberos or ident
software if the complaint mentions one of those authentication
types.
2000-06-18 23:24:54 +02:00
</para>
<para>
2005-01-23 01:30:59 +01:00
<programlisting>
2003-09-13 00:17:24 +02:00
FATAL: user "andym" does not exist
2005-01-23 01:30:59 +01:00
</programlisting>
2009-05-16 23:17:21 +02:00
The indicated database user name was not found.
2000-06-18 23:24:54 +02:00
</para>
<para>
2005-01-23 01:30:59 +01:00
<programlisting>
2003-09-13 00:17:24 +02:00
FATAL: database "testdb" does not exist
2005-01-23 01:30:59 +01:00
</programlisting>
2001-11-28 21:49:10 +01:00
The database you are trying to connect to does not exist. Note that
if you do not specify a database name, it defaults to the database
2022-11-24 09:04:50 +01:00
user name.
2000-06-18 23:24:54 +02:00
</para>
2001-08-02 01:25:39 +02:00
2003-09-13 00:17:24 +02:00
<tip>
2001-08-02 01:25:39 +02:00
<para>
Update documentation on may/can/might:
Standard English uses "may", "can", and "might" in different ways:
may - permission, "You may borrow my rake."
can - ability, "I can lift that log."
might - possibility, "It might rain today."
Unfortunately, in conversational English, their use is often mixed, as
in, "You may use this variable to do X", when in fact, "can" is a better
choice. Similarly, "It may crash" is better stated, "It might crash".
Also update two error messages mentioned in the documenation to match.
2007-01-31 21:56:20 +01:00
The server log might contain more information about an
2002-04-04 06:25:54 +02:00
authentication failure than is reported to the client. If you are
2010-02-03 18:25:06 +01:00
confused about the reason for a failure, check the server log.
2001-08-02 01:25:39 +02:00
</para>
2003-09-13 00:17:24 +02:00
</tip>
2000-06-18 23:24:54 +02:00
</sect1>
</chapter>