1 <!-- doc/src/sgml/client-auth.sgml -->
3 <chapter id="client-authentication">
4 <title>Client Authentication</title>
6 <indexterm zone="client-authentication">
7 <primary>client authentication</primary>
11 When a client application connects to the database server, it
12 specifies which <productname>PostgreSQL</productname> database user name it
13 wants to connect as, much the same way one logs into a Unix computer
14 as a particular user. Within the SQL environment the active database
15 user name determines access privileges to database objects — see
16 <xref linkend="user-manag"> for more information. Therefore, it is
17 essential to restrict which database users can connect.
22 As explained in <xref linkend="user-manag">,
23 <productname>PostgreSQL</productname> actually does privilege
24 management in terms of <quote>roles</>. In this chapter, we
25 consistently use <firstterm>database user</> to mean <quote>role with the
26 <literal>LOGIN</> privilege</quote>.
31 <firstterm>Authentication</firstterm> is the process by which the
32 database server establishes the identity of the client, and by
33 extension determines whether the client application (or the user
34 who runs the client application) is permitted to connect with the
35 database user name that was requested.
39 <productname>PostgreSQL</productname> offers a number of different
40 client authentication methods. The method used to authenticate a
41 particular client connection can be selected on the basis of
42 (client) host address, database, and user.
46 <productname>PostgreSQL</productname> database user names are logically
47 separate from user names of the operating system in which the server
48 runs. If all the users of a particular server also have accounts on
49 the server's machine, it makes sense to assign database user names
50 that match their operating system user names. However, a server that
51 accepts remote connections might have many database users who have no local
53 account, and in such cases there need be no connection between
54 database user names and OS user names.
57 <sect1 id="auth-pg-hba-conf">
58 <title>The <filename>pg_hba.conf</filename> File</title>
60 <indexterm zone="auth-pg-hba-conf">
61 <primary>pg_hba.conf</primary>
65 Client authentication is controlled by a configuration file,
66 which traditionally is named
67 <filename>pg_hba.conf</filename> and is stored in the database
68 cluster's data directory.
69 (<acronym>HBA</> stands for host-based authentication.) A default
70 <filename>pg_hba.conf</filename> file is installed when the data
71 directory is initialized by <command>initdb</command>. It is
72 possible to place the authentication configuration file elsewhere,
73 however; see the <xref linkend="guc-hba-file"> configuration parameter.
77 The general format of the <filename>pg_hba.conf</filename> file is
78 a set of records, one per line. Blank lines are ignored, as is any
79 text after the <literal>#</literal> comment character.
80 Records cannot be continued across lines.
82 up of a number of fields which are separated by spaces and/or tabs.
83 Fields can contain white space if the field value is double-quoted.
84 Quoting one of the keywords in a database, user, or address field (e.g.,
85 <literal>all</> or <literal>replication</>) makes the word lose its special
86 meaning, and just match a database, user, or host with that name.
90 Each record specifies a connection type, a client IP address range
91 (if relevant for the connection type), a database name, a user name,
92 and the authentication method to be used for connections matching
93 these parameters. The first record with a matching connection type,
94 client address, requested database, and user name is used to perform
95 authentication. There is no <quote>fall-through</> or
96 <quote>backup</>: if one record is chosen and the authentication
97 fails, subsequent records are not considered. If no record matches,
102 A record can have one of the seven formats
104 local <replaceable>database</replaceable> <replaceable>user</replaceable> <replaceable>auth-method</replaceable> <optional><replaceable>auth-options</replaceable></optional>
105 host <replaceable>database</replaceable> <replaceable>user</replaceable> <replaceable>address</replaceable> <replaceable>auth-method</replaceable> <optional><replaceable>auth-options</replaceable></optional>
106 hostssl <replaceable>database</replaceable> <replaceable>user</replaceable> <replaceable>address</replaceable> <replaceable>auth-method</replaceable> <optional><replaceable>auth-options</replaceable></optional>
107 hostnossl <replaceable>database</replaceable> <replaceable>user</replaceable> <replaceable>address</replaceable> <replaceable>auth-method</replaceable> <optional><replaceable>auth-options</replaceable></optional>
108 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>
109 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>
110 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>
112 The meaning of the fields is as follows:
116 <term><literal>local</literal></term>
119 This record matches connection attempts using Unix-domain
120 sockets. Without a record of this type, Unix-domain socket
121 connections are disallowed.
127 <term><literal>host</literal></term>
130 This record matches connection attempts made using TCP/IP.
131 <literal>host</literal> records match either
132 <acronym>SSL</acronym> or non-<acronym>SSL</acronym> connection
137 Remote TCP/IP connections will not be possible unless
138 the server is started with an appropriate value for the
139 <xref linkend="guc-listen-addresses"> configuration parameter,
140 since the default behavior is to listen for TCP/IP connections
141 only on the local loopback address <literal>localhost</>.
148 <term><literal>hostssl</literal></term>
151 This record matches connection attempts made using TCP/IP,
152 but only when the connection is made with <acronym>SSL</acronym>
157 To make use of this option the server must be built with
158 <acronym>SSL</acronym> support. Furthermore,
159 <acronym>SSL</acronym> must be enabled
160 by setting the <xref linkend="guc-ssl"> configuration parameter (see
161 <xref linkend="ssl-tcp"> for more information).
162 Otherwise, the <literal>hostssl</literal> record is ignored except for
163 logging a warning that it cannot match any connections.
169 <term><literal>hostnossl</literal></term>
172 This record type has the opposite behavior of <literal>hostssl</>;
173 it only matches connection attempts made over
174 TCP/IP that do not use <acronym>SSL</acronym>.
180 <term><replaceable>database</replaceable></term>
183 Specifies which database name(s) this record matches. The value
184 <literal>all</literal> specifies that it matches all databases.
185 The value <literal>sameuser</> specifies that the record
186 matches if the requested database has the same name as the
187 requested user. The value <literal>samerole</> specifies that
188 the requested user must be a member of the role with the same
189 name as the requested database. (<literal>samegroup</> is an
190 obsolete but still accepted spelling of <literal>samerole</>.)
191 Superusers are not considered to be members of a role for the
192 purposes of <literal>samerole</> unless they are explicitly
193 members of the role, directly or indirectly, and not just by
194 virtue of being a superuser.
195 The value <literal>replication</> specifies that the record
196 matches if a physical replication connection is requested (note that
197 replication connections do not specify any particular database).
198 Otherwise, this is the name of
199 a specific <productname>PostgreSQL</productname> database.
200 Multiple database names can be supplied by separating them with
201 commas. A separate file containing database names can be specified by
202 preceding the file name with <literal>@</>.
208 <term><replaceable>user</replaceable></term>
211 Specifies which database user name(s) this record
212 matches. The value <literal>all</literal> specifies that it
213 matches all users. Otherwise, this is either the name of a specific
214 database user, or a group name preceded by <literal>+</>.
215 (Recall that there is no real distinction between users and groups
216 in <productname>PostgreSQL</>; a <literal>+</> mark really means
217 <quote>match any of the roles that are directly or indirectly members
218 of this role</>, while a name without a <literal>+</> mark matches
219 only that specific role.) For this purpose, a superuser is only
220 considered to be a member of a role if they are explicitly a member
221 of the role, directly or indirectly, and not just by virtue of
223 Multiple user names can be supplied by separating them with commas.
224 A separate file containing user names can be specified by preceding the
225 file name with <literal>@</>.
231 <term><replaceable>address</replaceable></term>
234 Specifies the client machine address(es) that this record
235 matches. This field can contain either a host name, an IP
236 address range, or one of the special key words mentioned below.
240 An IP address range is specified using standard numeric notation
241 for the range's starting address, then a slash (<literal>/</literal>)
242 and a <acronym>CIDR</> mask length. The mask
243 length indicates the number of high-order bits of the client
244 IP address that must match. Bits to the right of this should
245 be zero in the given IP address.
246 There must not be any white space between the IP address, the
247 <literal>/</literal>, and the CIDR mask length.
251 Typical examples of an IPv4 address range specified this way are
252 <literal>172.20.143.89/32</literal> for a single host, or
253 <literal>172.20.143.0/24</literal> for a small network, or
254 <literal>10.6.0.0/16</literal> for a larger one.
255 An IPv6 address range might look like <literal>::1/128</literal>
256 for a single host (in this case the IPv6 loopback address) or
257 <literal>fe80::7a31:c1ff:0000:0000/96</literal> for a small
259 <literal>0.0.0.0/0</literal> represents all
260 IPv4 addresses, and <literal>::0/0</literal> represents
262 To specify a single host, use a mask length of 32 for IPv4 or
263 128 for IPv6. In a network address, do not omit trailing zeroes.
267 An entry given in IPv4 format will match only IPv4 connections,
268 and an entry given in IPv6 format will match only IPv6 connections,
269 even if the represented address is in the IPv4-in-IPv6 range.
270 Note that entries in IPv6 format will be rejected if the system's
271 C library does not have support for IPv6 addresses.
275 You can also write <literal>all</literal> to match any IP address,
276 <literal>samehost</literal> to match any of the server's own IP
277 addresses, or <literal>samenet</literal> to match any address in any
278 subnet that the server is directly connected to.
282 If a host name is specified (anything that is not an IP address
283 range or a special key word is treated as a host name),
284 that name is compared with the result of a reverse name
285 resolution of the client's IP address (e.g., reverse DNS
286 lookup, if DNS is used). Host name comparisons are case
287 insensitive. If there is a match, then a forward name
288 resolution (e.g., forward DNS lookup) is performed on the host
289 name to check whether any of the addresses it resolves to are
290 equal to the client's IP address. If both directions match,
291 then the entry is considered to match. (The host name that is
292 used in <filename>pg_hba.conf</filename> should be the one that
293 address-to-name resolution of the client's IP address returns,
294 otherwise the line won't be matched. Some host name databases
295 allow associating an IP address with multiple host names, but
296 the operating system will only return one host name when asked
297 to resolve an IP address.)
301 A host name specification that starts with a dot
302 (<literal>.</literal>) matches a suffix of the actual host
303 name. So <literal>.example.com</literal> would match
304 <literal>foo.example.com</literal> (but not just
305 <literal>example.com</literal>).
309 When host names are specified
310 in <filename>pg_hba.conf</filename>, you should make sure that
311 name resolution is reasonably fast. It can be of advantage to
312 set up a local name resolution cache such
313 as <command>nscd</command>. Also, you may wish to enable the
314 configuration parameter <varname>log_hostname</varname> to see
315 the client's host name instead of the IP address in the log.
319 This field only applies to <literal>host</literal>,
320 <literal>hostssl</literal>, and <literal>hostnossl</> records.
325 Users sometimes wonder why host names are handled
326 in this seemingly complicated way, with two name resolutions
327 including a reverse lookup of the client's IP address. This
328 complicates use of the feature in case the client's reverse DNS
329 entry is not set up or yields some undesirable host name.
330 It is done primarily for efficiency: this way, a connection attempt
331 requires at most two resolver lookups, one reverse and one forward.
332 If there is a resolver problem with some address, it becomes only
333 that client's problem. A hypothetical alternative
334 implementation that only did forward lookups would have to
335 resolve every host name mentioned in
336 <filename>pg_hba.conf</filename> during every connection attempt.
337 That could be quite slow if many names are listed.
338 And if there is a resolver problem with one of the host names,
339 it becomes everyone's problem.
343 Also, a reverse lookup is necessary to implement the suffix
344 matching feature, because the actual client host name needs to
345 be known in order to match it against the pattern.
349 Note that this behavior is consistent with other popular
350 implementations of host name-based access control, such as the
351 Apache HTTP Server and TCP Wrappers.
358 <term><replaceable>IP-address</replaceable></term>
359 <term><replaceable>IP-mask</replaceable></term>
362 These two fields can be used as an alternative to the
363 <replaceable>IP-address</><literal>/</><replaceable>mask-length</>
365 specifying the mask length, the actual mask is specified in a
366 separate column. For example, <literal>255.0.0.0</> represents an IPv4
367 CIDR mask length of 8, and <literal>255.255.255.255</> represents a
368 CIDR mask length of 32.
372 These fields only apply to <literal>host</literal>,
373 <literal>hostssl</literal>, and <literal>hostnossl</> records.
379 <term><replaceable>auth-method</replaceable></term>
382 Specifies the authentication method to use when a connection matches
383 this record. The possible choices are summarized here; details
384 are in <xref linkend="auth-methods">.
388 <term><literal>trust</></term>
391 Allow the connection unconditionally. This method
392 allows anyone that can connect to the
393 <productname>PostgreSQL</productname> database server to login as
394 any <productname>PostgreSQL</productname> user they wish,
395 without the need for a password or any other authentication. See <xref
396 linkend="auth-trust"> for details.
402 <term><literal>reject</></term>
405 Reject the connection unconditionally. This is useful for
406 <quote>filtering out</> certain hosts from a group, for example a
407 <literal>reject</> line could block a specific host from connecting,
408 while a later line allows the remaining hosts in a specific
415 <term><literal>scram-sha-256</></term>
418 Perform SCRAM-SHA-256 authentication to verify the user's
419 password. See <xref linkend="auth-password"> for details.
425 <term><literal>md5</></term>
428 Perform SCRAM-SHA-256 or MD5 authentication to verify the
429 user's password. See <xref linkend="auth-password">
436 <term><literal>password</></term>
439 Require the client to supply an unencrypted password for
441 Since the password is sent in clear text over the
442 network, this should not be used on untrusted networks.
443 See <xref linkend="auth-password"> for details.
449 <term><literal>gss</></term>
452 Use GSSAPI to authenticate the user. This is only
453 available for TCP/IP connections. See <xref
454 linkend="gssapi-auth"> for details.
460 <term><literal>sspi</></term>
463 Use SSPI to authenticate the user. This is only
464 available on Windows. See <xref
465 linkend="sspi-auth"> for details.
471 <term><literal>ident</></term>
474 Obtain the operating system user name of the client
475 by contacting the ident server on the client
476 and check if it matches the requested database user name.
477 Ident authentication can only be used on TCP/IP
478 connections. When specified for local connections, peer
479 authentication will be used instead.
480 See <xref linkend="auth-ident"> for details.
486 <term><literal>peer</></term>
489 Obtain the client's operating system user name from the operating
490 system and check if it matches the requested database user name.
491 This is only available for local connections.
492 See <xref linkend="auth-peer"> for details.
498 <term><literal>ldap</></term>
501 Authenticate using an <acronym>LDAP</> server. See <xref
502 linkend="auth-ldap"> for details.
508 <term><literal>radius</></term>
511 Authenticate using a RADIUS server. See <xref
512 linkend="auth-radius"> for details.
518 <term><literal>cert</></term>
521 Authenticate using SSL client certificates. See
522 <xref linkend="auth-cert"> for details.
528 <term><literal>pam</></term>
531 Authenticate using the Pluggable Authentication Modules
532 (PAM) service provided by the operating system. See <xref
533 linkend="auth-pam"> for details.
539 <term><literal>bsd</></term>
542 Authenticate using the BSD Authentication service provided by the
543 operating system. See <xref linkend="auth-bsd"> for details.
554 <term><replaceable>auth-options</replaceable></term>
557 After the <replaceable>auth-method</> field, there can be field(s) of
558 the form <replaceable>name</><literal>=</><replaceable>value</> that
559 specify options for the authentication method. Details about which
560 options are available for which authentication methods appear below.
564 In addition to the method-specific options listed below, there is one
565 method-independent authentication option <literal>clientcert</>, which
566 can be specified in any <literal>hostssl</> record. When set
567 to <literal>1</>, this option requires the client to present a valid
568 (trusted) SSL certificate, in addition to the other requirements of the
569 authentication method.
577 Files included by <literal>@</> constructs are read as lists of names,
578 which can be separated by either whitespace or commas. Comments are
579 introduced by <literal>#</literal>, just as in
580 <filename>pg_hba.conf</filename>, and nested <literal>@</> constructs are
581 allowed. Unless the file name following <literal>@</> is an absolute
582 path, it is taken to be relative to the directory containing the
587 Since the <filename>pg_hba.conf</filename> records are examined
588 sequentially for each connection attempt, the order of the records is
589 significant. Typically, earlier records will have tight connection
590 match parameters and weaker authentication methods, while later
591 records will have looser match parameters and stronger authentication
592 methods. For example, one might wish to use <literal>trust</>
593 authentication for local TCP/IP connections but require a password for
594 remote TCP/IP connections. In this case a record specifying
595 <literal>trust</> authentication for connections from 127.0.0.1 would
596 appear before a record specifying password authentication for a wider
597 range of allowed client IP addresses.
601 The <filename>pg_hba.conf</filename> file is read on start-up and when
602 the main server process receives a
603 <systemitem>SIGHUP</systemitem><indexterm><primary>SIGHUP</primary></indexterm>
604 signal. If you edit the file on an
605 active system, you will need to signal the postmaster
606 (using <literal>pg_ctl reload</> or <literal>kill -HUP</>) to make it
612 The preceding statement is not true on Microsoft Windows: there, any
613 changes in the <filename>pg_hba.conf</filename> file are immediately
614 applied by subsequent new connections.
620 <link linkend="view-pg-hba-file-rules"><structname>pg_hba_file_rules</structname></link>
621 can be helpful for pre-testing changes to the <filename>pg_hba.conf</>
622 file, or for diagnosing problems if loading of the file did not have the
623 desired effects. Rows in the view with
624 non-null <structfield>error</structfield> fields indicate problems in the
625 corresponding lines of the file.
630 To connect to a particular database, a user must not only pass the
631 <filename>pg_hba.conf</filename> checks, but must have the
632 <literal>CONNECT</> privilege for the database. If you wish to
633 restrict which users can connect to which databases, it's usually
634 easier to control this by granting/revoking <literal>CONNECT</> privilege
635 than to put the rules in <filename>pg_hba.conf</filename> entries.
640 Some examples of <filename>pg_hba.conf</filename> entries are shown in
641 <xref linkend="example-pg-hba.conf">. See the next section for details on the
642 different authentication methods.
645 <example id="example-pg-hba.conf">
646 <title>Example <filename>pg_hba.conf</filename> Entries</title>
648 # Allow any user on the local system to connect to any database with
649 # any database user name using Unix-domain sockets (the default for local
652 # TYPE DATABASE USER ADDRESS METHOD
655 # The same using local loopback TCP/IP connections.
657 # TYPE DATABASE USER ADDRESS METHOD
658 host all all 127.0.0.1/32 trust
660 # The same as the previous line, but using a separate netmask column
662 # TYPE DATABASE USER IP-ADDRESS IP-MASK METHOD
663 host all all 127.0.0.1 255.255.255.255 trust
665 # The same over IPv6.
667 # TYPE DATABASE USER ADDRESS METHOD
668 host all all ::1/128 trust
670 # The same using a host name (would typically cover both IPv4 and IPv6).
672 # TYPE DATABASE USER ADDRESS METHOD
673 host all all localhost trust
675 # Allow any user from any host with IP address 192.168.93.x to connect
676 # to database "postgres" as the same user name that ident reports for
677 # the connection (typically the operating system user name).
679 # TYPE DATABASE USER ADDRESS METHOD
680 host postgres all 192.168.93.0/24 ident
682 # Allow any user from host 192.168.12.10 to connect to database
683 # "postgres" if the user's password is correctly supplied.
685 # TYPE DATABASE USER ADDRESS METHOD
686 host postgres all 192.168.12.10/32 scram-sha-256
688 # Allow any user from hosts in the example.com domain to connect to
689 # any database if the user's password is correctly supplied.
691 # Require SCRAM authentication for most users, but make an exception
692 # for user 'mike', who uses an older client that doesn't support SCRAM
695 # TYPE DATABASE USER ADDRESS METHOD
696 host all mike .example.com md5
697 host all all .example.com scram-sha-256
699 # In the absence of preceding "host" lines, these two lines will
700 # reject all connections from 192.168.54.1 (since that entry will be
701 # matched first), but allow GSSAPI connections from anywhere else
702 # on the Internet. The zero mask causes no bits of the host IP
703 # address to be considered, so it matches any host.
705 # TYPE DATABASE USER ADDRESS METHOD
706 host all all 192.168.54.1/32 reject
707 host all all 0.0.0.0/0 gss
709 # Allow users from 192.168.x.x hosts to connect to any database, if
710 # they pass the ident check. If, for example, ident says the user is
711 # "bryanh" and he requests to connect as PostgreSQL user "guest1", the
712 # connection is allowed if there is an entry in pg_ident.conf for map
713 # "omicron" that says "bryanh" is allowed to connect as "guest1".
715 # TYPE DATABASE USER ADDRESS METHOD
716 host all all 192.168.0.0/16 ident map=omicron
718 # If these are the only three lines for local connections, they will
719 # allow local users to connect only to their own databases (databases
720 # with the same name as their database user name) except for administrators
721 # and members of role "support", who can connect to all databases. The file
722 # $PGDATA/admins contains a list of names of administrators. Passwords
723 # are required in all cases.
725 # TYPE DATABASE USER ADDRESS METHOD
726 local sameuser all md5
727 local all @admins md5
728 local all +support md5
730 # The last two lines above can be combined into a single line:
731 local all @admins,+support md5
733 # The database column can also use lists and file names:
734 local db1,db2,@demodbs all md5
739 <sect1 id="auth-username-maps">
740 <title>User Name Maps</title>
742 <indexterm zone="auth-username-maps">
743 <primary>User name maps</primary>
747 When using an external authentication system such as Ident or GSSAPI,
748 the name of the operating system user that initiated the connection
749 might not be the same as the database user (role) that is to be used.
750 In this case, a user name map can be applied to map the operating system
751 user name to a database user. To use user name mapping, specify
752 <literal>map</literal>=<replaceable>map-name</replaceable>
753 in the options field in <filename>pg_hba.conf</filename>. This option is
754 supported for all authentication methods that receive external user names.
755 Since different mappings might be needed for different connections,
756 the name of the map to be used is specified in the
757 <replaceable>map-name</replaceable> parameter in <filename>pg_hba.conf</filename>
758 to indicate which map to use for each individual connection.
762 User name maps are defined in the ident map file, which by default is named
763 <filename>pg_ident.conf</><indexterm><primary>pg_ident.conf</primary></indexterm>
765 cluster's data directory. (It is possible to place the map file
766 elsewhere, however; see the <xref linkend="guc-ident-file">
767 configuration parameter.)
768 The ident map file contains lines of the general form:
770 <replaceable>map-name</> <replaceable>system-username</> <replaceable>database-username</>
772 Comments and whitespace are handled in the same way as in
773 <filename>pg_hba.conf</>. The
774 <replaceable>map-name</> is an arbitrary name that will be used to
775 refer to this mapping in <filename>pg_hba.conf</filename>. The other
776 two fields specify an operating system user name and a matching
777 database user name. The same <replaceable>map-name</> can be
778 used repeatedly to specify multiple user-mappings within a single map.
781 There is no restriction regarding how many database users a given
782 operating system user can correspond to, nor vice versa. Thus, entries
783 in a map should be thought of as meaning <quote>this operating system
784 user is allowed to connect as this database user</quote>, rather than
785 implying that they are equivalent. The connection will be allowed if
786 there is any map entry that pairs the user name obtained from the
787 external authentication system with the database user name that the
788 user has requested to connect as.
791 If the <replaceable>system-username</> field starts with a slash (<literal>/</>),
792 the remainder of the field is treated as a regular expression.
793 (See <xref linkend="posix-syntax-details"> for details of
794 <productname>PostgreSQL</>'s regular expression syntax.) The regular
795 expression can include a single capture, or parenthesized subexpression,
796 which can then be referenced in the <replaceable>database-username</>
797 field as <literal>\1</> (backslash-one). This allows the mapping of
798 multiple user names in a single line, which is particularly useful for
799 simple syntax substitutions. For example, these entries
801 mymap /^(.*)@mydomain\.com$ \1
802 mymap /^(.*)@otherdomain\.com$ guest
804 will remove the domain part for users with system user names that end with
805 <literal>@mydomain.com</>, and allow any user whose system name ends with
806 <literal>@otherdomain.com</> to log in as <literal>guest</>.
811 Keep in mind that by default, a regular expression can match just part of
812 a string. It's usually wise to use <literal>^</> and <literal>$</>, as
813 shown in the above example, to force the match to be to the entire
819 The <filename>pg_ident.conf</filename> file is read on start-up and
820 when the main server process receives a
821 <systemitem>SIGHUP</systemitem><indexterm><primary>SIGHUP</primary></indexterm>
822 signal. If you edit the file on an
823 active system, you will need to signal the postmaster
824 (using <literal>pg_ctl reload</> or <literal>kill -HUP</>) to make it
829 A <filename>pg_ident.conf</filename> file that could be used in
830 conjunction with the <filename>pg_hba.conf</> file in <xref
831 linkend="example-pg-hba.conf"> is shown in <xref
832 linkend="example-pg-ident.conf">. In this example, anyone
833 logged in to a machine on the 192.168 network that does not have the
834 operating system user name <literal>bryanh</>, <literal>ann</>, or
835 <literal>robert</> would not be granted access. Unix user
836 <literal>robert</> would only be allowed access when he tries to
837 connect as <productname>PostgreSQL</> user <literal>bob</>, not
838 as <literal>robert</> or anyone else. <literal>ann</> would
839 only be allowed to connect as <literal>ann</>. User
840 <literal>bryanh</> would be allowed to connect as either
841 <literal>bryanh</> or as <literal>guest1</>.
844 <example id="example-pg-ident.conf">
845 <title>An Example <filename>pg_ident.conf</> File</title>
847 # MAPNAME SYSTEM-USERNAME PG-USERNAME
849 omicron bryanh bryanh
851 # bob has user name robert on these machines
853 # bryanh can also connect as guest1
854 omicron bryanh guest1
859 <sect1 id="auth-methods">
860 <title>Authentication Methods</title>
862 The following subsections describe the authentication methods in more detail.
865 <sect2 id="auth-trust">
866 <title>Trust Authentication</title>
869 When <literal>trust</> authentication is specified,
870 <productname>PostgreSQL</productname> assumes that anyone who can
871 connect to the server is authorized to access the database with
872 whatever database user name they specify (even superuser names).
873 Of course, restrictions made in the <literal>database</> and
874 <literal>user</> columns still apply.
875 This method should only be used when there is adequate
876 operating-system-level protection on connections to the server.
880 <literal>trust</> authentication is appropriate and very
881 convenient for local connections on a single-user workstation. It
882 is usually <emphasis>not</> appropriate by itself on a multiuser
883 machine. However, you might be able to use <literal>trust</> even
884 on a multiuser machine, if you restrict access to the server's
885 Unix-domain socket file using file-system permissions. To do this, set the
886 <varname>unix_socket_permissions</varname> (and possibly
887 <varname>unix_socket_group</varname>) configuration parameters as
888 described in <xref linkend="runtime-config-connection">. Or you
889 could set the <varname>unix_socket_directories</varname>
890 configuration parameter to place the socket file in a suitably
891 restricted directory.
895 Setting file-system permissions only helps for Unix-socket connections.
896 Local TCP/IP connections are not restricted by file-system permissions.
897 Therefore, if you want to use file-system permissions for local security,
898 remove the <literal>host ... 127.0.0.1 ...</> line from
899 <filename>pg_hba.conf</>, or change it to a
900 non-<literal>trust</> authentication method.
904 <literal>trust</> authentication is only suitable for TCP/IP connections
905 if you trust every user on every machine that is allowed to connect
906 to the server by the <filename>pg_hba.conf</> lines that specify
907 <literal>trust</>. It is seldom reasonable to use <literal>trust</>
908 for any TCP/IP connections other than those from <systemitem>localhost</> (127.0.0.1).
913 <sect2 id="auth-password">
914 <title>Password Authentication</title>
920 <primary>password</primary>
921 <secondary>authentication</secondary>
925 The password-based authentication methods are <literal>scram-sha-256</>,
926 <literal>md5</>, and <literal>password</>. These methods operate
927 similarly except for the way that the password is sent across the
932 Plain <literal>password</> sends the password in clear-text, and is
933 therefore vulnerable to password <quote>sniffing</> attacks. It should
934 always be avoided if possible. If the connection is protected by SSL
935 encryption then <literal>password</> can be used safely, though.
936 (Though SSL certificate authentication might be a better choice if one
937 is depending on using SSL).
942 <literal>scram-sha-256</> performs SCRAM-SHA-256 authentication, as
944 <ulink url="https://tools.ietf.org/html/rfc5802">RFC5802</ulink>. It
945 is a challenge-response scheme, that prevents password sniffing on
946 untrusted connections. It is more secure than the <literal>md5</>
947 method, but might not be supported by older clients.
951 <literal>md5</> allows falling back to a less secure challenge-response
952 mechanism for those users with an MD5 hashed password.
953 The fallback mechanism also prevents password sniffing, but provides no
954 protection if an attacker manages to steal the password hash from the
955 server, and it cannot be used with the <xref
956 linkend="guc-db-user-namespace"> feature. For all other users,
957 <literal>md5</> works the same as <literal>scram-sha-256</>.
961 <productname>PostgreSQL</productname> database passwords are
962 separate from operating system user passwords. The password for
963 each database user is stored in the <literal>pg_authid</> system
964 catalog. Passwords can be managed with the SQL commands
965 <xref linkend="sql-createuser"> and
966 <xref linkend="sql-alterrole">,
967 e.g., <userinput>CREATE USER foo WITH PASSWORD 'secret'</userinput>.
968 If no password has been set up for a user, the stored password
969 is null and password authentication will always fail for that user.
974 <sect2 id="gssapi-auth">
975 <title>GSSAPI Authentication</title>
977 <indexterm zone="gssapi-auth">
978 <primary>GSSAPI</primary>
982 <productname>GSSAPI</productname> is an industry-standard protocol
983 for secure authentication defined in RFC 2743.
984 <productname>PostgreSQL</productname> supports
985 <productname>GSSAPI</productname> with <productname>Kerberos</productname>
986 authentication according to RFC 1964. <productname>GSSAPI</productname>
987 provides automatic authentication (single sign-on) for systems
988 that support it. The authentication itself is secure, but the
989 data sent over the database connection will be sent unencrypted unless
990 <acronym>SSL</acronym> is used.
994 GSSAPI support has to be enabled when <productname>PostgreSQL</> is built;
995 see <xref linkend="installation"> for more information.
999 When <productname>GSSAPI</productname> uses
1000 <productname>Kerberos</productname>, it uses a standard principal
1002 <literal><replaceable>servicename</>/<replaceable>hostname</>@<replaceable>realm</></literal>.
1003 The PostgreSQL server will accept any principal that is included in the keytab used by
1004 the server, but care needs to be taken to specify the correct principal details when
1005 making the connection from the client using the <literal>krbsrvname</> connection parameter. (See
1006 also <xref linkend="libpq-paramkeywords">.) The installation default can be
1007 changed from the default <literal>postgres</literal> at build time using
1008 <literal>./configure --with-krb-srvnam=</><replaceable>whatever</>.
1009 In most environments,
1010 this parameter never needs to be changed.
1011 Some Kerberos implementations might require a different service name,
1012 such as Microsoft Active Directory which requires the service name
1013 to be in upper case (<literal>POSTGRES</literal>).
1016 <replaceable>hostname</> is the fully qualified host name of the
1017 server machine. The service principal's realm is the preferred realm
1018 of the server machine.
1022 Client principals can be mapped to different <productname>PostgreSQL</>
1023 database user names with <filename>pg_ident.conf</>. For example,
1024 <literal>pgusername@realm</> could be mapped to just <literal>pgusername</>.
1025 Alternatively, you can use the full <literal>username@realm</> principal as
1026 the role name in <productname>PostgreSQL</> without any mapping.
1030 <productname>PostgreSQL</> also supports a parameter to strip the realm from
1031 the principal. This method is supported for backwards compatibility and is
1032 strongly discouraged as it is then impossible to distinguish different users
1033 with the same user name but coming from different realms. To enable this,
1034 set <literal>include_realm</> to 0. For simple single-realm
1035 installations, doing that combined with setting the
1036 <literal>krb_realm</> parameter (which checks that the principal's realm
1037 matches exactly what is in the <literal>krb_realm</literal> parameter)
1038 is still secure; but this is a
1039 less capable approach compared to specifying an explicit mapping in
1040 <filename>pg_ident.conf</>.
1044 Make sure that your server keytab file is readable (and preferably
1045 only readable, not writable) by the <productname>PostgreSQL</productname>
1046 server account. (See also <xref linkend="postgres-user">.) The location
1047 of the key file is specified by the <xref
1048 linkend="guc-krb-server-keyfile"> configuration
1049 parameter. The default is
1050 <filename>/usr/local/pgsql/etc/krb5.keytab</> (or whatever
1051 directory was specified as <varname>sysconfdir</> at build time).
1052 For security reasons, it is recommended to use a separate keytab
1053 just for the <productname>PostgreSQL</productname> server rather
1054 than opening up permissions on the system keytab file.
1057 The keytab file is generated by the Kerberos software; see the
1058 Kerberos documentation for details. The following example is
1059 for MIT-compatible Kerberos 5 implementations:
1061 <prompt>kadmin% </><userinput>ank -randkey postgres/server.my.domain.org</>
1062 <prompt>kadmin% </><userinput>ktadd -k krb5.keytab postgres/server.my.domain.org</>
1067 When connecting to the database make sure you have a ticket for a
1068 principal matching the requested database user name. For example, for
1069 database user name <literal>fred</>, principal
1070 <literal>fred@EXAMPLE.COM</> would be able to connect. To also allow
1071 principal <literal>fred/users.example.com@EXAMPLE.COM</>, use a user name
1072 map, as described in <xref linkend="auth-username-maps">.
1076 The following configuration options are supported for <productname>GSSAPI</productname>:
1079 <term><literal>include_realm</literal></term>
1082 If set to 0, the realm name from the authenticated user principal is
1083 stripped off before being passed through the user name mapping
1084 (<xref linkend="auth-username-maps">). This is discouraged and is
1085 primarily available for backwards compatibility, as it is not secure
1086 in multi-realm environments unless <literal>krb_realm</literal> is
1087 also used. It is recommended to
1088 leave <literal>include_realm</literal> set to the default (1) and to
1089 provide an explicit mapping in <filename>pg_ident.conf</> to convert
1090 principal names to <productname>PostgreSQL</> user names.
1096 <term><literal>map</literal></term>
1099 Allows for mapping between system and database user names. See
1100 <xref linkend="auth-username-maps"> for details. For a GSSAPI/Kerberos
1101 principal, such as <literal>username@EXAMPLE.COM</literal> (or, less
1102 commonly, <literal>username/hostbased@EXAMPLE.COM</literal>), the
1103 user name used for mapping is
1104 <literal>username@EXAMPLE.COM</literal> (or
1105 <literal>username/hostbased@EXAMPLE.COM</literal>, respectively),
1106 unless <literal>include_realm</literal> has been set to 0, in which case
1107 <literal>username</literal> (or <literal>username/hostbased</literal>)
1108 is what is seen as the system user name when mapping.
1114 <term><literal>krb_realm</literal></term>
1117 Sets the realm to match user principal names against. If this parameter
1118 is set, only users of that realm will be accepted. If it is not set,
1119 users of any realm can connect, subject to whatever user name mapping
1128 <sect2 id="sspi-auth">
1129 <title>SSPI Authentication</title>
1131 <indexterm zone="sspi-auth">
1132 <primary>SSPI</primary>
1136 <productname>SSPI</productname> is a <productname>Windows</productname>
1137 technology for secure authentication with single sign-on.
1138 <productname>PostgreSQL</productname> will use SSPI in
1139 <literal>negotiate</literal> mode, which will use
1140 <productname>Kerberos</productname> when possible and automatically
1141 fall back to <productname>NTLM</productname> in other cases.
1142 <productname>SSPI</productname> authentication only works when both
1143 server and client are running <productname>Windows</productname>,
1144 or, on non-Windows platforms, when <productname>GSSAPI</productname>
1149 When using <productname>Kerberos</productname> authentication,
1150 <productname>SSPI</productname> works the same way
1151 <productname>GSSAPI</productname> does; see <xref linkend="gssapi-auth">
1156 The following configuration options are supported for <productname>SSPI</productname>:
1160 <term><literal>include_realm</literal></term>
1163 If set to 0, the realm name from the authenticated user principal is
1164 stripped off before being passed through the user name mapping
1165 (<xref linkend="auth-username-maps">). This is discouraged and is
1166 primarily available for backwards compatibility, as it is not secure
1167 in multi-realm environments unless <literal>krb_realm</literal> is
1168 also used. It is recommended to
1169 leave <literal>include_realm</literal> set to the default (1) and to
1170 provide an explicit mapping in <filename>pg_ident.conf</> to convert
1171 principal names to <productname>PostgreSQL</> user names.
1177 <term><literal>compat_realm</literal></term>
1180 If set to 1, the domain's SAM-compatible name (also known as the
1181 NetBIOS name) is used for the <literal>include_realm</literal>
1182 option. This is the default. If set to 0, the true realm name from
1183 the Kerberos user principal name is used.
1186 Do not disable this option unless your server runs under a domain
1187 account (this includes virtual service accounts on a domain member
1188 system) and all clients authenticating through SSPI are also using
1189 domain accounts, or authentication will fail.
1195 <term><literal>upn_username</literal></term>
1198 If this option is enabled along with <literal>compat_realm</literal>,
1199 the user name from the Kerberos UPN is used for authentication. If
1200 it is disabled (the default), the SAM-compatible user name is used.
1201 By default, these two names are identical for new user accounts.
1204 Note that <application>libpq</> uses the SAM-compatible name if no
1205 explicit user name is specified. If you use
1206 <application>libpq</> or a driver based on it, you should
1207 leave this option disabled or explicitly specify user name in the
1214 <term><literal>map</literal></term>
1217 Allows for mapping between system and database user names. See
1218 <xref linkend="auth-username-maps"> for details. For a SSPI/Kerberos
1219 principal, such as <literal>username@EXAMPLE.COM</literal> (or, less
1220 commonly, <literal>username/hostbased@EXAMPLE.COM</literal>), the
1221 user name used for mapping is
1222 <literal>username@EXAMPLE.COM</literal> (or
1223 <literal>username/hostbased@EXAMPLE.COM</literal>, respectively),
1224 unless <literal>include_realm</literal> has been set to 0, in which case
1225 <literal>username</literal> (or <literal>username/hostbased</literal>)
1226 is what is seen as the system user name when mapping.
1232 <term><literal>krb_realm</literal></term>
1235 Sets the realm to match user principal names against. If this parameter
1236 is set, only users of that realm will be accepted. If it is not set,
1237 users of any realm can connect, subject to whatever user name mapping
1246 <sect2 id="auth-ident">
1247 <title>Ident Authentication</title>
1250 <primary>ident</primary>
1254 The ident authentication method works by obtaining the client's
1255 operating system user name from an ident server and using it as
1256 the allowed database user name (with an optional user name mapping).
1257 This is only supported on TCP/IP connections.
1262 When ident is specified for a local (non-TCP/IP) connection,
1263 peer authentication (see <xref linkend="auth-peer">) will be
1269 The following configuration options are supported for <productname>ident</productname>:
1272 <term><literal>map</literal></term>
1275 Allows for mapping between system and database user names. See
1276 <xref linkend="auth-username-maps"> for details.
1284 The <quote>Identification Protocol</quote> is described in
1285 RFC 1413. Virtually every Unix-like
1286 operating system ships with an ident server that listens on TCP
1287 port 113 by default. The basic functionality of an ident server
1288 is to answer questions like <quote>What user initiated the
1289 connection that goes out of your port <replaceable>X</replaceable>
1290 and connects to my port <replaceable>Y</replaceable>?</quote>.
1291 Since <productname>PostgreSQL</> knows both <replaceable>X</> and
1292 <replaceable>Y</> when a physical connection is established, it
1293 can interrogate the ident server on the host of the connecting
1294 client and can theoretically determine the operating system user
1295 for any given connection.
1299 The drawback of this procedure is that it depends on the integrity
1300 of the client: if the client machine is untrusted or compromised,
1301 an attacker could run just about any program on port 113 and
1302 return any user name they choose. This authentication method is
1303 therefore only appropriate for closed networks where each client
1304 machine is under tight control and where the database and system
1305 administrators operate in close contact. In other words, you must
1306 trust the machine running the ident server.
1309 <attribution>RFC 1413</attribution>
1311 The Identification Protocol is not intended as an authorization
1312 or access control protocol.
1318 Some ident servers have a nonstandard option that causes the returned
1319 user name to be encrypted, using a key that only the originating
1320 machine's administrator knows. This option <emphasis>must not</> be
1321 used when using the ident server with <productname>PostgreSQL</>,
1322 since <productname>PostgreSQL</> does not have any way to decrypt the
1323 returned string to determine the actual user name.
1327 <sect2 id="auth-peer">
1328 <title>Peer Authentication</title>
1331 <primary>peer</primary>
1335 The peer authentication method works by obtaining the client's
1336 operating system user name from the kernel and using it as the
1337 allowed database user name (with optional user name mapping). This
1338 method is only supported on local connections.
1342 The following configuration options are supported for <productname>peer</productname>:
1345 <term><literal>map</literal></term>
1348 Allows for mapping between system and database user names. See
1349 <xref linkend="auth-username-maps"> for details.
1357 Peer authentication is only available on operating systems providing
1358 the <function>getpeereid()</> function, the <symbol>SO_PEERCRED</symbol>
1359 socket parameter, or similar mechanisms. Currently that includes
1360 <systemitem class="osname">Linux</>,
1361 most flavors of <systemitem class="osname">BSD</> including
1362 <systemitem class="osname">macOS</>,
1363 and <systemitem class="osname">Solaris</systemitem>.
1368 <sect2 id="auth-ldap">
1369 <title>LDAP Authentication</title>
1371 <indexterm zone="auth-ldap">
1372 <primary>LDAP</primary>
1376 This authentication method operates similarly to
1377 <literal>password</literal> except that it uses LDAP
1378 as the password verification method. LDAP is used only to validate
1379 the user name/password pairs. Therefore the user must already
1380 exist in the database before LDAP can be used for
1385 LDAP authentication can operate in two modes. In the first mode,
1386 which we will call the simple bind mode,
1387 the server will bind to the distinguished name constructed as
1388 <replaceable>prefix</> <replaceable>username</> <replaceable>suffix</>.
1389 Typically, the <replaceable>prefix</> parameter is used to specify
1390 <literal>cn=</>, or <replaceable>DOMAIN</><literal>\</> in an Active
1391 Directory environment. <replaceable>suffix</> is used to specify the
1392 remaining part of the DN in a non-Active Directory environment.
1396 In the second mode, which we will call the search+bind mode,
1397 the server first binds to the LDAP directory with
1398 a fixed user name and password, specified with <replaceable>ldapbinddn</>
1399 and <replaceable>ldapbindpasswd</>, and performs a search for the user trying
1400 to log in to the database. If no user and password is configured, an
1401 anonymous bind will be attempted to the directory. The search will be
1402 performed over the subtree at <replaceable>ldapbasedn</>, and will try to
1403 do an exact match of the attribute specified in
1404 <replaceable>ldapsearchattribute</>.
1405 Once the user has been found in
1406 this search, the server disconnects and re-binds to the directory as
1407 this user, using the password specified by the client, to verify that the
1408 login is correct. This mode is the same as that used by LDAP authentication
1409 schemes in other software, such as Apache <literal>mod_authnz_ldap</literal> and <literal>pam_ldap</literal>.
1410 This method allows for significantly more flexibility
1411 in where the user objects are located in the directory, but will cause
1412 two separate connections to the LDAP server to be made.
1416 The following configuration options are used in both modes:
1419 <term><literal>ldapserver</literal></term>
1422 Names or IP addresses of LDAP servers to connect to. Multiple
1423 servers may be specified, separated by spaces.
1428 <term><literal>ldapport</literal></term>
1431 Port number on LDAP server to connect to. If no port is specified,
1432 the LDAP library's default port setting will be used.
1437 <term><literal>ldaptls</literal></term>
1440 Set to 1 to make the connection between PostgreSQL and the
1441 LDAP server use TLS encryption. Note that this only encrypts
1442 the traffic to the LDAP server — the connection to the client
1443 will still be unencrypted unless SSL is used.
1449 The following options are used in simple bind mode only:
1452 <term><literal>ldapprefix</literal></term>
1455 String to prepend to the user name when forming the DN to bind as,
1456 when doing simple bind authentication.
1461 <term><literal>ldapsuffix</literal></term>
1464 String to append to the user name when forming the DN to bind as,
1465 when doing simple bind authentication.
1471 The following options are used in search+bind mode only:
1474 <term><literal>ldapbasedn</literal></term>
1477 Root DN to begin the search for the user in, when doing search+bind
1483 <term><literal>ldapbinddn</literal></term>
1486 DN of user to bind to the directory with to perform the search when
1487 doing search+bind authentication.
1492 <term><literal>ldapbindpasswd</literal></term>
1495 Password for user to bind to the directory with to perform the search
1496 when doing search+bind authentication.
1501 <term><literal>ldapsearchattribute</literal></term>
1504 Attribute to match against the user name in the search when doing
1505 search+bind authentication. If no attribute is specified, the
1506 <literal>uid</> attribute will be used.
1511 <term><literal>ldapurl</literal></term>
1514 An RFC 4516 LDAP URL. This is an alternative way to write some of the
1515 other LDAP options in a more compact and standard form. The format is
1517 ldap://<replaceable>host</replaceable>[:<replaceable>port</replaceable>]/<replaceable>basedn</replaceable>[?[<replaceable>attribute</replaceable>][?[<replaceable>scope</replaceable>]]]
1519 <replaceable>scope</replaceable> must be one
1520 of <literal>base</literal>, <literal>one</literal>, <literal>sub</literal>,
1521 typically the latter. Only one attribute is used, and some other
1522 components of standard LDAP URLs such as filters and extensions are
1527 For non-anonymous binds, <literal>ldapbinddn</literal>
1528 and <literal>ldapbindpasswd</literal> must be specified as separate
1533 To use encrypted LDAP connections, the <literal>ldaptls</literal>
1534 option has to be used in addition to <literal>ldapurl</literal>.
1535 The <literal>ldaps</literal> URL scheme (direct SSL connection) is not
1540 LDAP URLs are currently only supported with OpenLDAP, not on Windows.
1548 It is an error to mix configuration options for simple bind with options
1553 Here is an example for a simple-bind LDAP configuration:
1555 host ... ldap ldapserver=ldap.example.net ldapprefix="cn=" ldapsuffix=", dc=example, dc=net"
1557 When a connection to the database server as database
1558 user <literal>someuser</literal> is requested, PostgreSQL will attempt to
1559 bind to the LDAP server using the DN <literal>cn=someuser, dc=example,
1560 dc=net</literal> and the password provided by the client. If that connection
1561 succeeds, the database access is granted.
1565 Here is an example for a search+bind configuration:
1567 host ... ldap ldapserver=ldap.example.net ldapbasedn="dc=example, dc=net" ldapsearchattribute=uid
1569 When a connection to the database server as database
1570 user <literal>someuser</literal> is requested, PostgreSQL will attempt to
1571 bind anonymously (since <literal>ldapbinddn</literal> was not specified) to
1572 the LDAP server, perform a search for <literal>(uid=someuser)</literal>
1573 under the specified base DN. If an entry is found, it will then attempt to
1574 bind using that found information and the password supplied by the client.
1575 If that second connection succeeds, the database access is granted.
1579 Here is the same search+bind configuration written as a URL:
1581 host ... ldap ldapurl="ldap://ldap.example.net/dc=example,dc=net?uid?sub"
1583 Some other software that supports authentication against LDAP uses the
1584 same URL format, so it will be easier to share the configuration.
1589 Since LDAP often uses commas and spaces to separate the different
1590 parts of a DN, it is often necessary to use double-quoted parameter
1591 values when configuring LDAP options, as shown in the examples.
1597 <sect2 id="auth-radius">
1598 <title>RADIUS Authentication</title>
1600 <indexterm zone="auth-radius">
1601 <primary>RADIUS</primary>
1605 This authentication method operates similarly to
1606 <literal>password</literal> except that it uses RADIUS
1607 as the password verification method. RADIUS is used only to validate
1608 the user name/password pairs. Therefore the user must already
1609 exist in the database before RADIUS can be used for
1614 When using RADIUS authentication, an Access Request message will be sent
1615 to the configured RADIUS server. This request will be of type
1616 <literal>Authenticate Only</literal>, and include parameters for
1617 <literal>user name</>, <literal>password</> (encrypted) and
1618 <literal>NAS Identifier</>. The request will be encrypted using
1619 a secret shared with the server. The RADIUS server will respond to
1620 this server with either <literal>Access Accept</> or
1621 <literal>Access Reject</>. There is no support for RADIUS accounting.
1625 Multiple RADIUS servers can be specified, in which case they will
1626 be tried sequentially. If a negative response is received from
1627 a server, the authentication will fail. If no response is received,
1628 the next server in the list will be tried. To specify multiple
1629 servers, put the names within quotes and separate the server names
1630 with a comma. If multiple servers are specified, all other RADIUS
1631 options can also be given as a comma separate list, to apply
1632 individual values to each server. They can also be specified as
1633 a single value, in which case this value will apply to all servers.
1637 The following configuration options are supported for RADIUS:
1640 <term><literal>radiusservers</literal></term>
1643 The name or IP addresses of the RADIUS servers to connect to.
1644 This parameter is required.
1650 <term><literal>radiussecrets</literal></term>
1653 The shared secrets used when talking securely to the RADIUS
1654 server. This must have exactly the same value on the PostgreSQL
1655 and RADIUS servers. It is recommended that this be a string of
1656 at least 16 characters. This parameter is required.
1659 The encryption vector used will only be cryptographically
1660 strong if <productname>PostgreSQL</> is built with support for
1661 <productname>OpenSSL</>. In other cases, the transmission to the
1662 RADIUS server should only be considered obfuscated, not secured, and
1663 external security measures should be applied if necessary.
1671 <term><literal>radiusports</literal></term>
1674 The port number on the RADIUS servers to connect to. If no port
1675 is specified, the default port <literal>1812</> will be used.
1681 <term><literal>radiusidentifiers</literal></term>
1684 The string used as <literal>NAS Identifier</> in the RADIUS
1685 requests. This parameter can be used as a second parameter
1686 identifying for example which database user the user is attempting
1687 to authenticate as, which can be used for policy matching on
1688 the RADIUS server. If no identifier is specified, the default
1689 <literal>postgresql</> will be used.
1698 <sect2 id="auth-cert">
1699 <title>Certificate Authentication</title>
1701 <indexterm zone="auth-cert">
1702 <primary>Certificate</primary>
1706 This authentication method uses SSL client certificates to perform
1707 authentication. It is therefore only available for SSL connections.
1708 When using this authentication method, the server will require that
1709 the client provide a valid, trusted certificate. No password prompt
1710 will be sent to the client. The <literal>cn</literal> (Common Name)
1711 attribute of the certificate
1712 will be compared to the requested database user name, and if they match
1713 the login will be allowed. User name mapping can be used to allow
1714 <literal>cn</literal> to be different from the database user name.
1718 The following configuration options are supported for SSL certificate
1722 <term><literal>map</literal></term>
1725 Allows for mapping between system and database user names. See
1726 <xref linkend="auth-username-maps"> for details.
1734 In a <filename>pg_hba.conf</> record specifying certificate
1735 authentication, the authentication option <literal>clientcert</> is
1736 assumed to be <literal>1</>, and it cannot be turned off since a client
1737 certificate is necessary for this method. What the <literal>cert</>
1738 method adds to the basic <literal>clientcert</> certificate validity test
1739 is a check that the <literal>cn</literal> attribute matches the database
1744 <sect2 id="auth-pam">
1745 <title>PAM Authentication</title>
1747 <indexterm zone="auth-pam">
1748 <primary>PAM</primary>
1752 This authentication method operates similarly to
1753 <literal>password</literal> except that it uses PAM (Pluggable
1754 Authentication Modules) as the authentication mechanism. The
1755 default PAM service name is <literal>postgresql</literal>.
1756 PAM is used only to validate user name/password pairs and optionally the
1757 connected remote host name or IP address. Therefore the user must already
1758 exist in the database before PAM can be used for authentication. For more
1759 information about PAM, please read the
1760 <ulink url="http://www.kernel.org/pub/linux/libs/pam/">
1761 <productname>Linux-PAM</> Page</ulink>.
1765 The following configuration options are supported for PAM:
1768 <term><literal>pamservice</literal></term>
1776 <term><literal>pam_use_hostname</literal></term>
1779 Determines whether the remote IP address or the host name is provided
1780 to PAM modules through the <symbol>PAM_RHOST</symbol> item. By
1781 default, the IP address is used. Set this option to 1 to use the
1782 resolved host name instead. Host name resolution can lead to login
1783 delays. (Most PAM configurations don't use this information, so it is
1784 only necessary to consider this setting if a PAM configuration was
1785 specifically created to make use of it.)
1794 If PAM is set up to read <filename>/etc/shadow</>, authentication
1795 will fail because the PostgreSQL server is started by a non-root
1796 user. However, this is not an issue when PAM is configured to use
1797 LDAP or other authentication methods.
1802 <sect2 id="auth-bsd">
1803 <title>BSD Authentication</title>
1805 <indexterm zone="auth-bsd">
1806 <primary>BSD Authentication</primary>
1810 This authentication method operates similarly to
1811 <literal>password</literal> except that it uses BSD Authentication
1812 to verify the password. BSD Authentication is used only
1813 to validate user name/password pairs. Therefore the user's role must
1814 already exist in the database before BSD Authentication can be used
1815 for authentication. The BSD Authentication framework is currently
1816 only available on OpenBSD.
1820 BSD Authentication in <productname>PostgreSQL</> uses
1821 the <literal>auth-postgresql</literal> login type and authenticates with
1822 the <literal>postgresql</literal> login class if that's defined
1823 in <filename>login.conf</filename>. By default that login class does not
1824 exist, and <productname>PostgreSQL</> will use the default login class.
1829 To use BSD Authentication, the PostgreSQL user account (that is, the
1830 operating system user running the server) must first be added to
1831 the <literal>auth</literal> group. The <literal>auth</literal> group
1832 exists by default on OpenBSD systems.
1838 <sect1 id="client-authentication-problems">
1839 <title>Authentication Problems</title>
1842 Authentication failures and related problems generally
1843 manifest themselves through error messages like the following:
1848 FATAL: no pg_hba.conf entry for host "123.123.123.123", user "andym", database "testdb"
1850 This is what you are most likely to get if you succeed in contacting
1851 the server, but it does not want to talk to you. As the message
1852 suggests, the server refused the connection request because it found
1853 no matching entry in its <filename>pg_hba.conf</filename>
1859 FATAL: password authentication failed for user "andym"
1861 Messages like this indicate that you contacted the server, and it is
1862 willing to talk to you, but not until you pass the authorization
1863 method specified in the <filename>pg_hba.conf</filename> file. Check
1864 the password you are providing, or check your Kerberos or ident
1865 software if the complaint mentions one of those authentication
1871 FATAL: user "andym" does not exist
1873 The indicated database user name was not found.
1878 FATAL: database "testdb" does not exist
1880 The database you are trying to connect to does not exist. Note that
1881 if you do not specify a database name, it defaults to the database
1882 user name, which might or might not be the right thing.
1887 The server log might contain more information about an
1888 authentication failure than is reported to the client. If you are
1889 confused about the reason for a failure, check the server log.