| 1 |
<!-- doc/src/sgml/client-auth.sgml --> |
| 2 |
|
| 3 |
<chapter id="client-authentication"> |
| 4 |
<title>Client Authentication</title> |
| 5 |
|
| 6 |
<indexterm zone="client-authentication"> |
| 7 |
<primary>client authentication</primary> |
| 8 |
</indexterm> |
| 9 |
|
| 10 |
<para> |
| 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. |
| 18 |
</para> |
| 19 |
|
| 20 |
<note> |
| 21 |
<para> |
| 22 |
As explained in <xref linkend="user-manag"/>, |
| 23 |
<productname>PostgreSQL</productname> actually does privilege |
| 24 |
management in terms of <quote>roles</quote>. In this chapter, we |
| 25 |
consistently use <firstterm>database user</firstterm> to mean <quote>role with the |
| 26 |
<literal>LOGIN</literal> privilege</quote>. |
| 27 |
</para> |
| 28 |
</note> |
| 29 |
|
| 30 |
<para> |
| 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. |
| 36 |
</para> |
| 37 |
|
| 38 |
<para> |
| 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. |
| 43 |
</para> |
| 44 |
|
| 45 |
<para> |
| 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 |
| 52 |
operating system |
| 53 |
account, and in such cases there need be no connection between |
| 54 |
database user names and OS user names. |
| 55 |
</para> |
| 56 |
|
| 57 |
<sect1 id="auth-pg-hba-conf"> |
| 58 |
<title>The <filename>pg_hba.conf</filename> File</title> |
| 59 |
|
| 60 |
<indexterm zone="auth-pg-hba-conf"> |
| 61 |
<primary>pg_hba.conf</primary> |
| 62 |
</indexterm> |
| 63 |
|
| 64 |
<para> |
| 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</acronym> stands for host-based authentication.) A default |
| 70 |
<filename>pg_hba.conf</filename> file is installed when the data |
| 71 |
directory is initialized by <xref linkend="app-initdb"/>. It is |
| 72 |
possible to place the authentication configuration file elsewhere, |
| 73 |
however; see the <xref linkend="guc-hba-file"/> configuration parameter. |
| 74 |
</para> |
| 75 |
|
| 76 |
<para> |
| 77 |
The <filename>pg_hba.conf</filename> file is read on start-up and when |
| 78 |
the main server process receives a |
| 79 |
<systemitem>SIGHUP</systemitem><indexterm><primary>SIGHUP</primary></indexterm> |
| 80 |
signal. If you edit the file on an |
| 81 |
active system, you will need to signal the postmaster |
| 82 |
(using <literal>pg_ctl reload</literal>, calling the SQL function |
| 83 |
<function>pg_reload_conf()</function>, or using <literal>kill |
| 84 |
-HUP</literal>) to make it re-read the file. |
| 85 |
</para> |
| 86 |
|
| 87 |
<note> |
| 88 |
<para> |
| 89 |
The preceding statement is not true on Microsoft Windows: there, any |
| 90 |
changes in the <filename>pg_hba.conf</filename> file are immediately |
| 91 |
applied by subsequent new connections. |
| 92 |
</para> |
| 93 |
</note> |
| 94 |
|
| 95 |
<para> |
| 96 |
The system view |
| 97 |
<link linkend="view-pg-hba-file-rules"><structname>pg_hba_file_rules</structname></link> |
| 98 |
can be helpful for pre-testing changes to the <filename>pg_hba.conf</filename> |
| 99 |
file, or for diagnosing problems if loading of the file did not have the |
| 100 |
desired effects. Rows in the view with |
| 101 |
non-null <structfield>error</structfield> fields indicate problems in the |
| 102 |
corresponding lines of the file. |
| 103 |
</para> |
| 104 |
|
| 105 |
<para> |
| 106 |
The general format of the <filename>pg_hba.conf</filename> file is |
| 107 |
a set of records, one per line. Blank lines are ignored, as is any |
| 108 |
text after the <literal>#</literal> comment character. |
| 109 |
A record can be continued onto the next line by ending the line with |
| 110 |
a backslash. (Backslashes are not special except at the end of a line.) |
| 111 |
A record is made |
| 112 |
up of a number of fields which are separated by spaces and/or tabs. |
| 113 |
Fields can contain white space if the field value is double-quoted. |
| 114 |
Quoting one of the keywords in a database, user, or address field (e.g., |
| 115 |
<literal>all</literal> or <literal>replication</literal>) makes the word lose its special |
| 116 |
meaning, and just match a database, user, or host with that name. |
| 117 |
Backslash line continuation applies even within quoted text or comments. |
| 118 |
</para> |
| 119 |
|
| 120 |
<para> |
| 121 |
Each authentication record specifies a connection type, a client IP address |
| 122 |
range (if relevant for the connection type), a database name, a user name, |
| 123 |
and the authentication method to be used for connections matching |
| 124 |
these parameters. The first record with a matching connection type, |
| 125 |
client address, requested database, and user name is used to perform |
| 126 |
authentication. There is no <quote>fall-through</quote> or |
| 127 |
<quote>backup</quote>: if one record is chosen and the authentication |
| 128 |
fails, subsequent records are not considered. If no record matches, |
| 129 |
access is denied. |
| 130 |
</para> |
| 131 |
|
| 132 |
<para> |
| 133 |
Each record can be an include directive or an authentication record. |
| 134 |
Include directives specify files that can be included, that contain |
| 135 |
additional records. The records will be inserted in place of the |
| 136 |
include directives. Include directives only contain two fields: |
| 137 |
<literal>include</literal>, <literal>include_if_exists</literal> or |
| 138 |
<literal>include_dir</literal> directive and the file or directory to be |
| 139 |
included. The file or directory can be a relative or absolute path, and can |
| 140 |
be double-quoted. For the <literal>include_dir</literal> form, all files |
| 141 |
not starting with a <literal>.</literal> and ending with |
| 142 |
<literal>.conf</literal> will be included. Multiple files within an include |
| 143 |
directory are processed in file name order (according to C locale rules, |
| 144 |
i.e., numbers before letters, and uppercase letters before lowercase ones). |
| 145 |
</para> |
| 146 |
|
| 147 |
<para> |
| 148 |
A record can have several formats: |
| 149 |
<synopsis> |
| 150 |
local <replaceable>database</replaceable> <replaceable>user</replaceable> <replaceable>auth-method</replaceable> <optional><replaceable>auth-options</replaceable></optional> |
| 151 |
host <replaceable>database</replaceable> <replaceable>user</replaceable> <replaceable>address</replaceable> <replaceable>auth-method</replaceable> <optional><replaceable>auth-options</replaceable></optional> |
| 152 |
hostssl <replaceable>database</replaceable> <replaceable>user</replaceable> <replaceable>address</replaceable> <replaceable>auth-method</replaceable> <optional><replaceable>auth-options</replaceable></optional> |
| 153 |
hostnossl <replaceable>database</replaceable> <replaceable>user</replaceable> <replaceable>address</replaceable> <replaceable>auth-method</replaceable> <optional><replaceable>auth-options</replaceable></optional> |
| 154 |
hostgssenc <replaceable>database</replaceable> <replaceable>user</replaceable> <replaceable>address</replaceable> <replaceable>auth-method</replaceable> <optional><replaceable>auth-options</replaceable></optional> |
| 155 |
hostnogssenc <replaceable>database</replaceable> <replaceable>user</replaceable> <replaceable>address</replaceable> <replaceable>auth-method</replaceable> <optional><replaceable>auth-options</replaceable></optional> |
| 156 |
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> |
| 157 |
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> |
| 158 |
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> |
| 159 |
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> |
| 160 |
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> |
| 161 |
include <replaceable>file</replaceable> |
| 162 |
include_if_exists <replaceable>file</replaceable> |
| 163 |
include_dir <replaceable>directory</replaceable> |
| 164 |
</synopsis> |
| 165 |
The meaning of the fields is as follows: |
| 166 |
|
| 167 |
<variablelist> |
| 168 |
<varlistentry> |
| 169 |
<term><literal>local</literal></term> |
| 170 |
<listitem> |
| 171 |
<para> |
| 172 |
This record matches connection attempts using Unix-domain |
| 173 |
sockets. Without a record of this type, Unix-domain socket |
| 174 |
connections are disallowed. |
| 175 |
</para> |
| 176 |
</listitem> |
| 177 |
</varlistentry> |
| 178 |
|
| 179 |
<varlistentry> |
| 180 |
<term><literal>host</literal></term> |
| 181 |
<listitem> |
| 182 |
<para> |
| 183 |
This record matches connection attempts made using TCP/IP. |
| 184 |
<literal>host</literal> records match |
| 185 |
<acronym>SSL</acronym> or non-<acronym>SSL</acronym> connection |
| 186 |
attempts as well as <acronym>GSSAPI</acronym> encrypted or |
| 187 |
non-<acronym>GSSAPI</acronym> encrypted connection attempts. |
| 188 |
</para> |
| 189 |
<note> |
| 190 |
<para> |
| 191 |
Remote TCP/IP connections will not be possible unless |
| 192 |
the server is started with an appropriate value for the |
| 193 |
<xref linkend="guc-listen-addresses"/> configuration parameter, |
| 194 |
since the default behavior is to listen for TCP/IP connections |
| 195 |
only on the local loopback address <literal>localhost</literal>. |
| 196 |
</para> |
| 197 |
</note> |
| 198 |
</listitem> |
| 199 |
</varlistentry> |
| 200 |
|
| 201 |
<varlistentry> |
| 202 |
<term><literal>hostssl</literal></term> |
| 203 |
<listitem> |
| 204 |
<para> |
| 205 |
This record matches connection attempts made using TCP/IP, |
| 206 |
but only when the connection is made with <acronym>SSL</acronym> |
| 207 |
encryption. |
| 208 |
</para> |
| 209 |
|
| 210 |
<para> |
| 211 |
To make use of this option the server must be built with |
| 212 |
<acronym>SSL</acronym> support. Furthermore, |
| 213 |
<acronym>SSL</acronym> must be enabled |
| 214 |
by setting the <xref linkend="guc-ssl"/> configuration parameter (see |
| 215 |
<xref linkend="ssl-tcp"/> for more information). |
| 216 |
Otherwise, the <literal>hostssl</literal> record is ignored except for |
| 217 |
logging a warning that it cannot match any connections. |
| 218 |
</para> |
| 219 |
</listitem> |
| 220 |
</varlistentry> |
| 221 |
|
| 222 |
<varlistentry> |
| 223 |
<term><literal>hostnossl</literal></term> |
| 224 |
<listitem> |
| 225 |
<para> |
| 226 |
This record type has the opposite behavior of <literal>hostssl</literal>; |
| 227 |
it only matches connection attempts made over |
| 228 |
TCP/IP that do not use <acronym>SSL</acronym>. |
| 229 |
</para> |
| 230 |
</listitem> |
| 231 |
</varlistentry> |
| 232 |
|
| 233 |
<varlistentry> |
| 234 |
<term><literal>hostgssenc</literal></term> |
| 235 |
<listitem> |
| 236 |
<para> |
| 237 |
This record matches connection attempts made using TCP/IP, |
| 238 |
but only when the connection is made with <acronym>GSSAPI</acronym> |
| 239 |
encryption. |
| 240 |
</para> |
| 241 |
|
| 242 |
<para> |
| 243 |
To make use of this option the server must be built with |
| 244 |
<acronym>GSSAPI</acronym> support. Otherwise, |
| 245 |
the <literal>hostgssenc</literal> record is ignored except for logging |
| 246 |
a warning that it cannot match any connections. |
| 247 |
</para> |
| 248 |
</listitem> |
| 249 |
</varlistentry> |
| 250 |
|
| 251 |
<varlistentry> |
| 252 |
<term><literal>hostnogssenc</literal></term> |
| 253 |
<listitem> |
| 254 |
<para> |
| 255 |
This record type has the opposite behavior of <literal>hostgssenc</literal>; |
| 256 |
it only matches connection attempts made over |
| 257 |
TCP/IP that do not use <acronym>GSSAPI</acronym> encryption. |
| 258 |
</para> |
| 259 |
</listitem> |
| 260 |
</varlistentry> |
| 261 |
|
| 262 |
<varlistentry> |
| 263 |
<term><replaceable>database</replaceable></term> |
| 264 |
<listitem> |
| 265 |
<para> |
| 266 |
Specifies which database name(s) this record matches. The value |
| 267 |
<literal>all</literal> specifies that it matches all databases. |
| 268 |
The value <literal>sameuser</literal> specifies that the record |
| 269 |
matches if the requested database has the same name as the |
| 270 |
requested user. The value <literal>samerole</literal> specifies that |
| 271 |
the requested user must be a member of the role with the same |
| 272 |
name as the requested database. (<literal>samegroup</literal> is an |
| 273 |
obsolete but still accepted spelling of <literal>samerole</literal>.) |
| 274 |
Superusers are not considered to be members of a role for the |
| 275 |
purposes of <literal>samerole</literal> unless they are explicitly |
| 276 |
members of the role, directly or indirectly, and not just by |
| 277 |
virtue of being a superuser. |
| 278 |
The value <literal>replication</literal> specifies that the record |
| 279 |
matches if a physical replication connection is requested, however, it |
| 280 |
doesn't match with logical replication connections. Note that physical |
| 281 |
replication connections do not specify any particular database whereas |
| 282 |
logical replication connections do specify it. |
| 283 |
Otherwise, this is the name of a specific |
| 284 |
<productname>PostgreSQL</productname> database or a regular expression. |
| 285 |
Multiple database names and/or regular expressions can be supplied by |
| 286 |
separating them with commas. |
| 287 |
</para> |
| 288 |
<para> |
| 289 |
If the database name starts with a slash (<literal>/</literal>), the |
| 290 |
remainder of the name is treated as a regular expression. |
| 291 |
(See <xref linkend="posix-syntax-details"/> for details of |
| 292 |
<productname>PostgreSQL</productname>'s regular expression syntax.) |
| 293 |
</para> |
| 294 |
<para> |
| 295 |
A separate file containing database names and/or regular expressions |
| 296 |
can be specified by preceding the file name with <literal>@</literal>. |
| 297 |
</para> |
| 298 |
</listitem> |
| 299 |
</varlistentry> |
| 300 |
|
| 301 |
<varlistentry> |
| 302 |
<term><replaceable>user</replaceable></term> |
| 303 |
<listitem> |
| 304 |
<para> |
| 305 |
Specifies which database user name(s) this record |
| 306 |
matches. The value <literal>all</literal> specifies that it |
| 307 |
matches all users. Otherwise, this is either the name of a specific |
| 308 |
database user, a regular expression (when starting with a slash |
| 309 |
(<literal>/</literal>), or a group name preceded by <literal>+</literal>. |
| 310 |
(Recall that there is no real distinction between users and groups |
| 311 |
in <productname>PostgreSQL</productname>; a <literal>+</literal> mark really means |
| 312 |
<quote>match any of the roles that are directly or indirectly members |
| 313 |
of this role</quote>, while a name without a <literal>+</literal> mark matches |
| 314 |
only that specific role.) For this purpose, a superuser is only |
| 315 |
considered to be a member of a role if they are explicitly a member |
| 316 |
of the role, directly or indirectly, and not just by virtue of |
| 317 |
being a superuser. |
| 318 |
Multiple user names and/or regular expressions can be supplied by |
| 319 |
separating them with commas. |
| 320 |
</para> |
| 321 |
<para> |
| 322 |
If the user name starts with a slash (<literal>/</literal>), the |
| 323 |
remainder of the name is treated as a regular expression. |
| 324 |
(See <xref linkend="posix-syntax-details"/> for details of |
| 325 |
<productname>PostgreSQL</productname>'s regular expression syntax.) |
| 326 |
</para> |
| 327 |
<para> |
| 328 |
A separate file containing user names and/or regular expressions can |
| 329 |
be specified by preceding the file name with <literal>@</literal>. |
| 330 |
</para> |
| 331 |
</listitem> |
| 332 |
</varlistentry> |
| 333 |
|
| 334 |
<varlistentry> |
| 335 |
<term><replaceable>address</replaceable></term> |
| 336 |
<listitem> |
| 337 |
<para> |
| 338 |
Specifies the client machine address(es) that this record |
| 339 |
matches. This field can contain either a host name, an IP |
| 340 |
address range, or one of the special key words mentioned below. |
| 341 |
</para> |
| 342 |
|
| 343 |
<para> |
| 344 |
An IP address range is specified using standard numeric notation |
| 345 |
for the range's starting address, then a slash (<literal>/</literal>) |
| 346 |
and a <acronym>CIDR</acronym> mask length. The mask |
| 347 |
length indicates the number of high-order bits of the client |
| 348 |
IP address that must match. Bits to the right of this should |
| 349 |
be zero in the given IP address. |
| 350 |
There must not be any white space between the IP address, the |
| 351 |
<literal>/</literal>, and the CIDR mask length. |
| 352 |
</para> |
| 353 |
|
| 354 |
<para> |
| 355 |
Typical examples of an IPv4 address range specified this way are |
| 356 |
<literal>172.20.143.89/32</literal> for a single host, or |
| 357 |
<literal>172.20.143.0/24</literal> for a small network, or |
| 358 |
<literal>10.6.0.0/16</literal> for a larger one. |
| 359 |
An IPv6 address range might look like <literal>::1/128</literal> |
| 360 |
for a single host (in this case the IPv6 loopback address) or |
| 361 |
<literal>fe80::7a31:c1ff:0000:0000/96</literal> for a small |
| 362 |
network. |
| 363 |
<literal>0.0.0.0/0</literal> represents all |
| 364 |
IPv4 addresses, and <literal>::0/0</literal> represents |
| 365 |
all IPv6 addresses. |
| 366 |
To specify a single host, use a mask length of 32 for IPv4 or |
| 367 |
128 for IPv6. In a network address, do not omit trailing zeroes. |
| 368 |
</para> |
| 369 |
|
| 370 |
<para> |
| 371 |
An entry given in IPv4 format will match only IPv4 connections, |
| 372 |
and an entry given in IPv6 format will match only IPv6 connections, |
| 373 |
even if the represented address is in the IPv4-in-IPv6 range. |
| 374 |
</para> |
| 375 |
|
| 376 |
<para> |
| 377 |
You can also write <literal>all</literal> to match any IP address, |
| 378 |
<literal>samehost</literal> to match any of the server's own IP |
| 379 |
addresses, or <literal>samenet</literal> to match any address in any |
| 380 |
subnet that the server is directly connected to. |
| 381 |
</para> |
| 382 |
|
| 383 |
<para> |
| 384 |
If a host name is specified (anything that is not an IP address |
| 385 |
range or a special key word is treated as a host name), |
| 386 |
that name is compared with the result of a reverse name |
| 387 |
resolution of the client's IP address (e.g., reverse DNS |
| 388 |
lookup, if DNS is used). Host name comparisons are case |
| 389 |
insensitive. If there is a match, then a forward name |
| 390 |
resolution (e.g., forward DNS lookup) is performed on the host |
| 391 |
name to check whether any of the addresses it resolves to are |
| 392 |
equal to the client's IP address. If both directions match, |
| 393 |
then the entry is considered to match. (The host name that is |
| 394 |
used in <filename>pg_hba.conf</filename> should be the one that |
| 395 |
address-to-name resolution of the client's IP address returns, |
| 396 |
otherwise the line won't be matched. Some host name databases |
| 397 |
allow associating an IP address with multiple host names, but |
| 398 |
the operating system will only return one host name when asked |
| 399 |
to resolve an IP address.) |
| 400 |
</para> |
| 401 |
|
| 402 |
<para> |
| 403 |
A host name specification that starts with a dot |
| 404 |
(<literal>.</literal>) matches a suffix of the actual host |
| 405 |
name. So <literal>.example.com</literal> would match |
| 406 |
<literal>foo.example.com</literal> (but not just |
| 407 |
<literal>example.com</literal>). |
| 408 |
</para> |
| 409 |
|
| 410 |
<para> |
| 411 |
When host names are specified |
| 412 |
in <filename>pg_hba.conf</filename>, you should make sure that |
| 413 |
name resolution is reasonably fast. It can be of advantage to |
| 414 |
set up a local name resolution cache such |
| 415 |
as <command>nscd</command>. Also, you may wish to enable the |
| 416 |
configuration parameter <varname>log_hostname</varname> to see |
| 417 |
the client's host name instead of the IP address in the log. |
| 418 |
</para> |
| 419 |
|
| 420 |
<para> |
| 421 |
These fields do not apply to <literal>local</literal> records. |
| 422 |
</para> |
| 423 |
|
| 424 |
<note> |
| 425 |
<para> |
| 426 |
Users sometimes wonder why host names are handled |
| 427 |
in this seemingly complicated way, with two name resolutions |
| 428 |
including a reverse lookup of the client's IP address. This |
| 429 |
complicates use of the feature in case the client's reverse DNS |
| 430 |
entry is not set up or yields some undesirable host name. |
| 431 |
It is done primarily for efficiency: this way, a connection attempt |
| 432 |
requires at most two resolver lookups, one reverse and one forward. |
| 433 |
If there is a resolver problem with some address, it becomes only |
| 434 |
that client's problem. A hypothetical alternative |
| 435 |
implementation that only did forward lookups would have to |
| 436 |
resolve every host name mentioned in |
| 437 |
<filename>pg_hba.conf</filename> during every connection attempt. |
| 438 |
That could be quite slow if many names are listed. |
| 439 |
And if there is a resolver problem with one of the host names, |
| 440 |
it becomes everyone's problem. |
| 441 |
</para> |
| 442 |
|
| 443 |
<para> |
| 444 |
Also, a reverse lookup is necessary to implement the suffix |
| 445 |
matching feature, because the actual client host name needs to |
| 446 |
be known in order to match it against the pattern. |
| 447 |
</para> |
| 448 |
|
| 449 |
<para> |
| 450 |
Note that this behavior is consistent with other popular |
| 451 |
implementations of host name-based access control, such as the |
| 452 |
Apache HTTP Server and TCP Wrappers. |
| 453 |
</para> |
| 454 |
</note> |
| 455 |
</listitem> |
| 456 |
</varlistentry> |
| 457 |
|
| 458 |
<varlistentry> |
| 459 |
<term><replaceable>IP-address</replaceable></term> |
| 460 |
<term><replaceable>IP-mask</replaceable></term> |
| 461 |
<listitem> |
| 462 |
<para> |
| 463 |
These two fields can be used as an alternative to the |
| 464 |
<replaceable>IP-address</replaceable><literal>/</literal><replaceable>mask-length</replaceable> |
| 465 |
notation. Instead of |
| 466 |
specifying the mask length, the actual mask is specified in a |
| 467 |
separate column. For example, <literal>255.0.0.0</literal> represents an IPv4 |
| 468 |
CIDR mask length of 8, and <literal>255.255.255.255</literal> represents a |
| 469 |
CIDR mask length of 32. |
| 470 |
</para> |
| 471 |
|
| 472 |
<para> |
| 473 |
These fields do not apply to <literal>local</literal> records. |
| 474 |
</para> |
| 475 |
</listitem> |
| 476 |
</varlistentry> |
| 477 |
|
| 478 |
<varlistentry> |
| 479 |
<term><replaceable>auth-method</replaceable></term> |
| 480 |
<listitem> |
| 481 |
<para> |
| 482 |
Specifies the authentication method to use when a connection matches |
| 483 |
this record. The possible choices are summarized here; details |
| 484 |
are in <xref linkend="auth-methods"/>. All the options |
| 485 |
are lower case and treated case sensitively, so even acronyms like |
| 486 |
<literal>ldap</literal> must be specified as lower case. |
| 487 |
|
| 488 |
<variablelist> |
| 489 |
<varlistentry> |
| 490 |
<term><literal>trust</literal></term> |
| 491 |
<listitem> |
| 492 |
<para> |
| 493 |
Allow the connection unconditionally. This method |
| 494 |
allows anyone that can connect to the |
| 495 |
<productname>PostgreSQL</productname> database server to login as |
| 496 |
any <productname>PostgreSQL</productname> user they wish, |
| 497 |
without the need for a password or any other authentication. See <xref |
| 498 |
linkend="auth-trust"/> for details. |
| 499 |
</para> |
| 500 |
</listitem> |
| 501 |
</varlistentry> |
| 502 |
|
| 503 |
<varlistentry> |
| 504 |
<term><literal>reject</literal></term> |
| 505 |
<listitem> |
| 506 |
<para> |
| 507 |
Reject the connection unconditionally. This is useful for |
| 508 |
<quote>filtering out</quote> certain hosts from a group, for example a |
| 509 |
<literal>reject</literal> line could block a specific host from connecting, |
| 510 |
while a later line allows the remaining hosts in a specific |
| 511 |
network to connect. |
| 512 |
</para> |
| 513 |
</listitem> |
| 514 |
</varlistentry> |
| 515 |
|
| 516 |
<varlistentry> |
| 517 |
<term><literal>scram-sha-256</literal></term> |
| 518 |
<listitem> |
| 519 |
<para> |
| 520 |
Perform SCRAM-SHA-256 authentication to verify the user's |
| 521 |
password. See <xref linkend="auth-password"/> for details. |
| 522 |
</para> |
| 523 |
</listitem> |
| 524 |
</varlistentry> |
| 525 |
|
| 526 |
<varlistentry> |
| 527 |
<term><literal>md5</literal></term> |
| 528 |
<listitem> |
| 529 |
<para> |
| 530 |
Perform SCRAM-SHA-256 or MD5 authentication to verify the |
| 531 |
user's password. See <xref linkend="auth-password"/> |
| 532 |
for details. |
| 533 |
</para> |
| 534 |
<warning> |
| 535 |
<para> |
| 536 |
Support for MD5-encrypted passwords is deprecated and will be |
| 537 |
removed in a future release of |
| 538 |
<productname>PostgreSQL</productname>. Refer to |
| 539 |
<xref linkend="auth-password"/> for details about migrating to |
| 540 |
another password type. |
| 541 |
</para> |
| 542 |
</warning> |
| 543 |
</listitem> |
| 544 |
</varlistentry> |
| 545 |
|
| 546 |
<varlistentry> |
| 547 |
<term><literal>password</literal></term> |
| 548 |
<listitem> |
| 549 |
<para> |
| 550 |
Require the client to supply an unencrypted password for |
| 551 |
authentication. |
| 552 |
Since the password is sent in clear text over the |
| 553 |
network, this should not be used on untrusted networks. |
| 554 |
See <xref linkend="auth-password"/> for details. |
| 555 |
</para> |
| 556 |
</listitem> |
| 557 |
</varlistentry> |
| 558 |
|
| 559 |
<varlistentry> |
| 560 |
<term><literal>gss</literal></term> |
| 561 |
<listitem> |
| 562 |
<para> |
| 563 |
Use GSSAPI to authenticate the user. This is only |
| 564 |
available for TCP/IP connections. See <xref |
| 565 |
linkend="gssapi-auth"/> for details. It can be used in conjunction |
| 566 |
with GSSAPI encryption. |
| 567 |
</para> |
| 568 |
</listitem> |
| 569 |
</varlistentry> |
| 570 |
|
| 571 |
<varlistentry> |
| 572 |
<term><literal>sspi</literal></term> |
| 573 |
<listitem> |
| 574 |
<para> |
| 575 |
Use SSPI to authenticate the user. This is only |
| 576 |
available on Windows. See <xref |
| 577 |
linkend="sspi-auth"/> for details. |
| 578 |
</para> |
| 579 |
</listitem> |
| 580 |
</varlistentry> |
| 581 |
|
| 582 |
<varlistentry> |
| 583 |
<term><literal>ident</literal></term> |
| 584 |
<listitem> |
| 585 |
<para> |
| 586 |
Obtain the operating system user name of the client |
| 587 |
by contacting the ident server on the client |
| 588 |
and check if it matches the requested database user name. |
| 589 |
Ident authentication can only be used on TCP/IP |
| 590 |
connections. When specified for local connections, peer |
| 591 |
authentication will be used instead. |
| 592 |
See <xref linkend="auth-ident"/> for details. |
| 593 |
</para> |
| 594 |
</listitem> |
| 595 |
</varlistentry> |
| 596 |
|
| 597 |
<varlistentry> |
| 598 |
<term><literal>peer</literal></term> |
| 599 |
<listitem> |
| 600 |
<para> |
| 601 |
Obtain the client's operating system user name from the operating |
| 602 |
system and check if it matches the requested database user name. |
| 603 |
This is only available for local connections. |
| 604 |
See <xref linkend="auth-peer"/> for details. |
| 605 |
</para> |
| 606 |
</listitem> |
| 607 |
</varlistentry> |
| 608 |
|
| 609 |
<varlistentry> |
| 610 |
<term><literal>ldap</literal></term> |
| 611 |
<listitem> |
| 612 |
<para> |
| 613 |
Authenticate using an <acronym>LDAP</acronym> server. See <xref |
| 614 |
linkend="auth-ldap"/> for details. |
| 615 |
</para> |
| 616 |
</listitem> |
| 617 |
</varlistentry> |
| 618 |
|
| 619 |
<varlistentry> |
| 620 |
<term><literal>radius</literal></term> |
| 621 |
<listitem> |
| 622 |
<para> |
| 623 |
Authenticate using a RADIUS server. See <xref |
| 624 |
linkend="auth-radius"/> for details. |
| 625 |
</para> |
| 626 |
</listitem> |
| 627 |
</varlistentry> |
| 628 |
|
| 629 |
<varlistentry> |
| 630 |
<term><literal>cert</literal></term> |
| 631 |
<listitem> |
| 632 |
<para> |
| 633 |
Authenticate using SSL client certificates. See |
| 634 |
<xref linkend="auth-cert"/> for details. |
| 635 |
</para> |
| 636 |
</listitem> |
| 637 |
</varlistentry> |
| 638 |
|
| 639 |
<varlistentry> |
| 640 |
<term><literal>pam</literal></term> |
| 641 |
<listitem> |
| 642 |
<para> |
| 643 |
Authenticate using the Pluggable Authentication Modules |
| 644 |
(PAM) service provided by the operating system. See <xref |
| 645 |
linkend="auth-pam"/> for details. |
| 646 |
</para> |
| 647 |
</listitem> |
| 648 |
</varlistentry> |
| 649 |
|
| 650 |
<varlistentry> |
| 651 |
<term><literal>bsd</literal></term> |
| 652 |
<listitem> |
| 653 |
<para> |
| 654 |
Authenticate using the BSD Authentication service provided by the |
| 655 |
operating system. See <xref linkend="auth-bsd"/> for details. |
| 656 |
</para> |
| 657 |
</listitem> |
| 658 |
</varlistentry> |
| 659 |
|
| 660 |
<varlistentry> |
| 661 |
<term><literal>oauth</literal></term> |
| 662 |
<listitem> |
| 663 |
<para> |
| 664 |
Authorize and optionally authenticate using a third-party OAuth 2.0 |
| 665 |
identity provider. See <xref linkend="auth-oauth"/> for details. |
| 666 |
</para> |
| 667 |
</listitem> |
| 668 |
</varlistentry> |
| 669 |
</variablelist> |
| 670 |
|
| 671 |
</para> |
| 672 |
</listitem> |
| 673 |
</varlistentry> |
| 674 |
|
| 675 |
<varlistentry> |
| 676 |
<term><replaceable>auth-options</replaceable></term> |
| 677 |
<listitem> |
| 678 |
<para> |
| 679 |
After the <replaceable>auth-method</replaceable> field, there can be field(s) of |
| 680 |
the form <replaceable>name</replaceable><literal>=</literal><replaceable>value</replaceable> that |
| 681 |
specify options for the authentication method. Details about which |
| 682 |
options are available for which authentication methods appear below. |
| 683 |
</para> |
| 684 |
|
| 685 |
<para> |
| 686 |
In addition to the method-specific options listed below, there is a |
| 687 |
method-independent authentication option <literal>clientcert</literal>, which |
| 688 |
can be specified in any <literal>hostssl</literal> record. |
| 689 |
This option can be set to <literal>verify-ca</literal> or |
| 690 |
<literal>verify-full</literal>. Both options require the client |
| 691 |
to present a valid (trusted) SSL certificate, while |
| 692 |
<literal>verify-full</literal> additionally enforces that the |
| 693 |
<literal>cn</literal> (Common Name) in the certificate matches |
| 694 |
the username or an applicable mapping. |
| 695 |
This behavior is similar to the <literal>cert</literal> authentication |
| 696 |
method (see <xref linkend="auth-cert"/>) but enables pairing |
| 697 |
the verification of client certificates with any authentication |
| 698 |
method that supports <literal>hostssl</literal> entries. |
| 699 |
</para> |
| 700 |
<para> |
| 701 |
On any record using client certificate authentication (i.e. one |
| 702 |
using the <literal>cert</literal> authentication method or one |
| 703 |
using the <literal>clientcert</literal> option), you can specify |
| 704 |
which part of the client certificate credentials to match using |
| 705 |
the <literal>clientname</literal> option. This option can have one |
| 706 |
of two values. If you specify <literal>clientname=CN</literal>, which |
| 707 |
is the default, the username is matched against the certificate's |
| 708 |
<literal>Common Name (CN)</literal>. If instead you specify |
| 709 |
<literal>clientname=DN</literal> the username is matched against the |
| 710 |
entire <literal>Distinguished Name (DN)</literal> of the certificate. |
| 711 |
This option is probably best used in conjunction with a username map. |
| 712 |
The comparison is done with the <literal>DN</literal> in |
| 713 |
<ulink url="https://datatracker.ietf.org/doc/html/rfc2253">RFC 2253</ulink> |
| 714 |
format. To see the <literal>DN</literal> of a client certificate |
| 715 |
in this format, do |
| 716 |
<programlisting> |
| 717 |
openssl x509 -in myclient.crt -noout -subject -nameopt RFC2253 | sed "s/^subject=//" |
| 718 |
</programlisting> |
| 719 |
Care needs to be taken when using this option, especially when using |
| 720 |
regular expression matching against the <literal>DN</literal>. |
| 721 |
</para> |
| 722 |
</listitem> |
| 723 |
</varlistentry> |
| 724 |
|
| 725 |
<varlistentry> |
| 726 |
<term><literal>include</literal></term> |
| 727 |
<listitem> |
| 728 |
<para> |
| 729 |
This line will be replaced by the contents of the given file. |
| 730 |
</para> |
| 731 |
</listitem> |
| 732 |
</varlistentry> |
| 733 |
|
| 734 |
<varlistentry> |
| 735 |
<term><literal>include_if_exists</literal></term> |
| 736 |
<listitem> |
| 737 |
<para> |
| 738 |
This line will be replaced by the content of the given file if the |
| 739 |
file exists. Otherwise, a message is logged to indicate that the file |
| 740 |
has been skipped. |
| 741 |
</para> |
| 742 |
</listitem> |
| 743 |
</varlistentry> |
| 744 |
|
| 745 |
<varlistentry> |
| 746 |
<term><literal>include_dir</literal></term> |
| 747 |
<listitem> |
| 748 |
<para> |
| 749 |
This line will be replaced by the contents of all the files found in |
| 750 |
the directory, if they don't start with a <literal>.</literal> and end |
| 751 |
with <literal>.conf</literal>, processed in file name order (according |
| 752 |
to C locale rules, i.e., numbers before letters, and uppercase letters |
| 753 |
before lowercase ones). |
| 754 |
</para> |
| 755 |
</listitem> |
| 756 |
</varlistentry> |
| 757 |
</variablelist> |
| 758 |
</para> |
| 759 |
|
| 760 |
<para> |
| 761 |
Files included by <literal>@</literal> constructs are read as lists of names, |
| 762 |
which can be separated by either whitespace or commas. Comments are |
| 763 |
introduced by <literal>#</literal>, just as in |
| 764 |
<filename>pg_hba.conf</filename>, and nested <literal>@</literal> constructs are |
| 765 |
allowed. Unless the file name following <literal>@</literal> is an absolute |
| 766 |
path, it is taken to be relative to the directory containing the |
| 767 |
referencing file. |
| 768 |
</para> |
| 769 |
|
| 770 |
<para> |
| 771 |
Since the <filename>pg_hba.conf</filename> records are examined |
| 772 |
sequentially for each connection attempt, the order of the records is |
| 773 |
significant. Typically, earlier records will have tight connection |
| 774 |
match parameters and weaker authentication methods, while later |
| 775 |
records will have looser match parameters and stronger authentication |
| 776 |
methods. For example, one might wish to use <literal>trust</literal> |
| 777 |
authentication for local TCP/IP connections but require a password for |
| 778 |
remote TCP/IP connections. In this case a record specifying |
| 779 |
<literal>trust</literal> authentication for connections from 127.0.0.1 would |
| 780 |
appear before a record specifying password authentication for a wider |
| 781 |
range of allowed client IP addresses. |
| 782 |
</para> |
| 783 |
|
| 784 |
<tip> |
| 785 |
<para> |
| 786 |
To connect to a particular database, a user must not only pass the |
| 787 |
<filename>pg_hba.conf</filename> checks, but must have the |
| 788 |
<literal>CONNECT</literal> privilege for the database. If you wish to |
| 789 |
restrict which users can connect to which databases, it's usually |
| 790 |
easier to control this by granting/revoking <literal>CONNECT</literal> privilege |
| 791 |
than to put the rules in <filename>pg_hba.conf</filename> entries. |
| 792 |
</para> |
| 793 |
</tip> |
| 794 |
|
| 795 |
<para> |
| 796 |
Some examples of <filename>pg_hba.conf</filename> entries are shown in |
| 797 |
<xref linkend="example-pg-hba.conf"/>. See the next section for details on the |
| 798 |
different authentication methods. |
| 799 |
</para> |
| 800 |
|
| 801 |
<example id="example-pg-hba.conf"> |
| 802 |
<title>Example <filename>pg_hba.conf</filename> Entries</title> |
| 803 |
<programlisting> |
| 804 |
# Allow any user on the local system to connect to any database with |
| 805 |
# any database user name using Unix-domain sockets (the default for local |
| 806 |
# connections). |
| 807 |
# |
| 808 |
# TYPE DATABASE USER ADDRESS METHOD |
| 809 |
local all all trust |
| 810 |
|
| 811 |
# The same using local loopback TCP/IP connections. |
| 812 |
# |
| 813 |
# TYPE DATABASE USER ADDRESS METHOD |
| 814 |
host all all 127.0.0.1/32 trust |
| 815 |
|
| 816 |
# The same as the previous line, but using a separate netmask column |
| 817 |
# |
| 818 |
# TYPE DATABASE USER IP-ADDRESS IP-MASK METHOD |
| 819 |
host all all 127.0.0.1 255.255.255.255 trust |
| 820 |
|
| 821 |
# The same over IPv6. |
| 822 |
# |
| 823 |
# TYPE DATABASE USER ADDRESS METHOD |
| 824 |
host all all ::1/128 trust |
| 825 |
|
| 826 |
# The same using a host name (would typically cover both IPv4 and IPv6). |
| 827 |
# |
| 828 |
# TYPE DATABASE USER ADDRESS METHOD |
| 829 |
host all all localhost trust |
| 830 |
|
| 831 |
# The same using a regular expression for DATABASE, that allows connection |
| 832 |
# to any databases with a name beginning with "db" and finishing with a |
| 833 |
# number using two to four digits (like "db1234" or "db12"). |
| 834 |
# |
| 835 |
# TYPE DATABASE USER ADDRESS METHOD |
| 836 |
host "/^db\d{2,4}$" all localhost trust |
| 837 |
|
| 838 |
# Allow any user from any host with IP address 192.168.93.x to connect |
| 839 |
# to database "postgres" as the same user name that ident reports for |
| 840 |
# the connection (typically the operating system user name). |
| 841 |
# |
| 842 |
# TYPE DATABASE USER ADDRESS METHOD |
| 843 |
host postgres all 192.168.93.0/24 ident |
| 844 |
|
| 845 |
# Allow any user from host 192.168.12.10 to connect to database |
| 846 |
# "postgres" if the user's password is correctly supplied. |
| 847 |
# |
| 848 |
# TYPE DATABASE USER ADDRESS METHOD |
| 849 |
host postgres all 192.168.12.10/32 scram-sha-256 |
| 850 |
|
| 851 |
# Allow any user from hosts in the example.com domain to connect to |
| 852 |
# any database if the user's password is correctly supplied. |
| 853 |
# |
| 854 |
# Require SCRAM authentication for most users, but make an exception |
| 855 |
# for user 'mike', who uses an older client that doesn't support SCRAM |
| 856 |
# authentication. |
| 857 |
# |
| 858 |
# TYPE DATABASE USER ADDRESS METHOD |
| 859 |
host all mike .example.com md5 |
| 860 |
host all all .example.com scram-sha-256 |
| 861 |
|
| 862 |
# In the absence of preceding "host" lines, these three lines will |
| 863 |
# reject all connections from 192.168.54.1 (since that entry will be |
| 864 |
# matched first), but allow GSSAPI-encrypted connections from anywhere else |
| 865 |
# on the Internet. The zero mask causes no bits of the host IP address to |
| 866 |
# be considered, so it matches any host. Unencrypted GSSAPI connections |
| 867 |
# (which "fall through" to the third line since "hostgssenc" only matches |
| 868 |
# encrypted GSSAPI connections) are allowed, but only from 192.168.12.10. |
| 869 |
# |
| 870 |
# TYPE DATABASE USER ADDRESS METHOD |
| 871 |
host all all 192.168.54.1/32 reject |
| 872 |
hostgssenc all all 0.0.0.0/0 gss |
| 873 |
host all all 192.168.12.10/32 gss |
| 874 |
|
| 875 |
# Allow users from 192.168.x.x hosts to connect to any database, if |
| 876 |
# they pass the ident check. If, for example, ident says the user is |
| 877 |
# "bryanh" and he requests to connect as PostgreSQL user "guest1", the |
| 878 |
# connection is allowed if there is an entry in pg_ident.conf for map |
| 879 |
# "omicron" that says "bryanh" is allowed to connect as "guest1". |
| 880 |
# |
| 881 |
# TYPE DATABASE USER ADDRESS METHOD |
| 882 |
host all all 192.168.0.0/16 ident map=omicron |
| 883 |
|
| 884 |
# If these are the only four lines for local connections, they will |
| 885 |
# allow local users to connect only to their own databases (databases |
| 886 |
# with the same name as their database user name) except for users whose |
| 887 |
# name end with "helpdesk", administrators and members of role "support", |
| 888 |
# who can connect to all databases. The file $PGDATA/admins contains a |
| 889 |
# list of names of administrators. Passwords are required in all cases. |
| 890 |
# |
| 891 |
# TYPE DATABASE USER ADDRESS METHOD |
| 892 |
local sameuser all scram-sha-256 |
| 893 |
local all /^.*helpdesk$ scram-sha-256 |
| 894 |
local all @admins scram-sha-256 |
| 895 |
local all +support scram-sha-256 |
| 896 |
|
| 897 |
# The last two lines above can be combined into a single line: |
| 898 |
local all @admins,+support scram-sha-256 |
| 899 |
|
| 900 |
# The database column can also use lists and file names: |
| 901 |
local db1,db2,@demodbs all scram-sha-256 |
| 902 |
</programlisting> |
| 903 |
</example> |
| 904 |
</sect1> |
| 905 |
|
| 906 |
<sect1 id="auth-username-maps"> |
| 907 |
<title>User Name Maps</title> |
| 908 |
|
| 909 |
<indexterm zone="auth-username-maps"> |
| 910 |
<primary>User name maps</primary> |
| 911 |
</indexterm> |
| 912 |
|
| 913 |
<para> |
| 914 |
When using an external authentication system such as Ident or GSSAPI, |
| 915 |
the name of the operating system user that initiated the connection |
| 916 |
might not be the same as the database user (role) that is to be used. |
| 917 |
In this case, a user name map can be applied to map the operating system |
| 918 |
user name to a database user. To use user name mapping, specify |
| 919 |
<literal>map</literal>=<replaceable>map-name</replaceable> |
| 920 |
in the options field in <filename>pg_hba.conf</filename>. This option is |
| 921 |
supported for all authentication methods that receive external user names. |
| 922 |
Since different mappings might be needed for different connections, |
| 923 |
the name of the map to be used is specified in the |
| 924 |
<replaceable>map-name</replaceable> parameter in <filename>pg_hba.conf</filename> |
| 925 |
to indicate which map to use for each individual connection. |
| 926 |
</para> |
| 927 |
|
| 928 |
<para> |
| 929 |
User name maps are defined in the ident map file, which by default is named |
| 930 |
<filename>pg_ident.conf</filename><indexterm><primary>pg_ident.conf</primary></indexterm> |
| 931 |
and is stored in the |
| 932 |
cluster's data directory. (It is possible to place the map file |
| 933 |
elsewhere, however; see the <xref linkend="guc-ident-file"/> |
| 934 |
configuration parameter.) |
| 935 |
The ident map file contains lines of the general forms: |
| 936 |
<synopsis> |
| 937 |
<replaceable>map-name</replaceable> <replaceable>system-username</replaceable> <replaceable>database-username</replaceable> |
| 938 |
<replaceable>include</replaceable> <replaceable>file</replaceable> |
| 939 |
<replaceable>include_if_exists</replaceable> <replaceable>file</replaceable> |
| 940 |
<replaceable>include_dir</replaceable> <replaceable>directory</replaceable> |
| 941 |
</synopsis> |
| 942 |
Comments, whitespace and line continuations are handled in the same way as in |
| 943 |
<filename>pg_hba.conf</filename>. The |
| 944 |
<replaceable>map-name</replaceable> is an arbitrary name that will be used to |
| 945 |
refer to this mapping in <filename>pg_hba.conf</filename>. The other |
| 946 |
two fields specify an operating system user name and a matching |
| 947 |
database user name. The same <replaceable>map-name</replaceable> can be |
| 948 |
used repeatedly to specify multiple user-mappings within a single map. |
| 949 |
</para> |
| 950 |
<para> |
| 951 |
As for <filename>pg_hba.conf</filename>, the lines in this file can |
| 952 |
be include directives, following the same rules. |
| 953 |
</para> |
| 954 |
|
| 955 |
<para> |
| 956 |
The <filename>pg_ident.conf</filename> file is read on start-up and |
| 957 |
when the main server process receives a |
| 958 |
<systemitem>SIGHUP</systemitem><indexterm><primary>SIGHUP</primary></indexterm> |
| 959 |
signal. If you edit the file on an |
| 960 |
active system, you will need to signal the postmaster |
| 961 |
(using <literal>pg_ctl reload</literal>, calling the SQL function |
| 962 |
<function>pg_reload_conf()</function>, or using <literal>kill |
| 963 |
-HUP</literal>) to make it re-read the file. |
| 964 |
</para> |
| 965 |
|
| 966 |
<para> |
| 967 |
The system view |
| 968 |
<link linkend="view-pg-ident-file-mappings"><structname>pg_ident_file_mappings</structname></link> |
| 969 |
can be helpful for pre-testing changes to the |
| 970 |
<filename>pg_ident.conf</filename> file, or for diagnosing problems if |
| 971 |
loading of the file did not have the desired effects. Rows in the view with |
| 972 |
non-null <structfield>error</structfield> fields indicate problems in the |
| 973 |
corresponding lines of the file. |
| 974 |
</para> |
| 975 |
|
| 976 |
<para> |
| 977 |
There is no restriction regarding how many database users a given |
| 978 |
operating system user can correspond to, nor vice versa. Thus, entries |
| 979 |
in a map should be thought of as meaning <quote>this operating system |
| 980 |
user is allowed to connect as this database user</quote>, rather than |
| 981 |
implying that they are equivalent. The connection will be allowed if |
| 982 |
there is any map entry that pairs the user name obtained from the |
| 983 |
external authentication system with the database user name that the |
| 984 |
user has requested to connect as. The value <literal>all</literal> |
| 985 |
can be used as the <replaceable>database-username</replaceable> to specify |
| 986 |
that if the <replaceable>system-username</replaceable> matches, then this |
| 987 |
user is allowed to log in as any of the existing database users. Quoting |
| 988 |
<literal>all</literal> makes the keyword lose its special meaning. |
| 989 |
</para> |
| 990 |
<para> |
| 991 |
If the <replaceable>database-username</replaceable> begins with a |
| 992 |
<literal>+</literal> character, then the operating system user can login as |
| 993 |
any user belonging to that role, similarly to how user names beginning with |
| 994 |
<literal>+</literal> are treated in <literal>pg_hba.conf</literal>. |
| 995 |
Thus, a <literal>+</literal> mark means <quote>match any of the roles that |
| 996 |
are directly or indirectly members of this role</quote>, while a name |
| 997 |
without a <literal>+</literal> mark matches only that specific role. Quoting |
| 998 |
a username starting with a <literal>+</literal> makes the |
| 999 |
<literal>+</literal> lose its special meaning. |
| 1000 |
</para> |
| 1001 |
<para> |
| 1002 |
If the <replaceable>system-username</replaceable> field starts with a slash (<literal>/</literal>), |
| 1003 |
the remainder of the field is treated as a regular expression. |
| 1004 |
(See <xref linkend="posix-syntax-details"/> for details of |
| 1005 |
<productname>PostgreSQL</productname>'s regular expression syntax.) The regular |
| 1006 |
expression can include a single capture, or parenthesized subexpression. |
| 1007 |
The portion of the system user name that matched the capture can then |
| 1008 |
be referenced in the <replaceable>database-username</replaceable> |
| 1009 |
field as <literal>\1</literal> (backslash-one). This allows the mapping of |
| 1010 |
multiple user names in a single line, which is particularly useful for |
| 1011 |
simple syntax substitutions. For example, these entries |
| 1012 |
<programlisting> |
| 1013 |
mymap /^(.*)@mydomain\.com$ \1 |
| 1014 |
mymap /^(.*)@otherdomain\.com$ guest |
| 1015 |
</programlisting> |
| 1016 |
will remove the domain part for users with system user names that end with |
| 1017 |
<literal>@mydomain.com</literal>, and allow any user whose system name ends with |
| 1018 |
<literal>@otherdomain.com</literal> to log in as <literal>guest</literal>. |
| 1019 |
Quoting a <replaceable>database-username</replaceable> containing |
| 1020 |
<literal>\1</literal> <emphasis>does not</emphasis> make |
| 1021 |
<literal>\1</literal> lose its special meaning. |
| 1022 |
</para> |
| 1023 |
<para> |
| 1024 |
If the <replaceable>database-username</replaceable> field starts with |
| 1025 |
a slash (<literal>/</literal>), the remainder of the field is treated |
| 1026 |
as a regular expression. |
| 1027 |
When the <replaceable>database-username</replaceable> field is a regular |
| 1028 |
expression, it is not possible to use <literal>\1</literal> within it to |
| 1029 |
refer to a capture from the <replaceable>system-username</replaceable> |
| 1030 |
field. |
| 1031 |
</para> |
| 1032 |
|
| 1033 |
<tip> |
| 1034 |
<para> |
| 1035 |
Keep in mind that by default, a regular expression can match just part of |
| 1036 |
a string. It's usually wise to use <literal>^</literal> and <literal>$</literal>, as |
| 1037 |
shown in the above example, to force the match to be to the entire |
| 1038 |
system user name. |
| 1039 |
</para> |
| 1040 |
</tip> |
| 1041 |
|
| 1042 |
<para> |
| 1043 |
A <filename>pg_ident.conf</filename> file that could be used in |
| 1044 |
conjunction with the <filename>pg_hba.conf</filename> file in <xref |
| 1045 |
linkend="example-pg-hba.conf"/> is shown in <xref |
| 1046 |
linkend="example-pg-ident.conf"/>. In this example, anyone |
| 1047 |
logged in to a machine on the 192.168 network that does not have the |
| 1048 |
operating system user name <literal>bryanh</literal>, <literal>ann</literal>, or |
| 1049 |
<literal>robert</literal> would not be granted access. Unix user |
| 1050 |
<literal>robert</literal> would only be allowed access when he tries to |
| 1051 |
connect as <productname>PostgreSQL</productname> user <literal>bob</literal>, not |
| 1052 |
as <literal>robert</literal> or anyone else. <literal>ann</literal> would |
| 1053 |
only be allowed to connect as <literal>ann</literal>. User |
| 1054 |
<literal>bryanh</literal> would be allowed to connect as either |
| 1055 |
<literal>bryanh</literal> or as <literal>guest1</literal>. |
| 1056 |
</para> |
| 1057 |
|
| 1058 |
<example id="example-pg-ident.conf"> |
| 1059 |
<title>An Example <filename>pg_ident.conf</filename> File</title> |
| 1060 |
<programlisting> |
| 1061 |
# MAPNAME SYSTEM-USERNAME PG-USERNAME |
| 1062 |
|
| 1063 |
omicron bryanh bryanh |
| 1064 |
omicron ann ann |
| 1065 |
# bob has user name robert on these machines |
| 1066 |
omicron robert bob |
| 1067 |
# bryanh can also connect as guest1 |
| 1068 |
omicron bryanh guest1 |
| 1069 |
</programlisting> |
| 1070 |
</example> |
| 1071 |
</sect1> |
| 1072 |
|
| 1073 |
<sect1 id="auth-methods"> |
| 1074 |
<title>Authentication Methods</title> |
| 1075 |
|
| 1076 |
<para> |
| 1077 |
<productname>PostgreSQL</productname> provides various methods for |
| 1078 |
authenticating users: |
| 1079 |
|
| 1080 |
<itemizedlist> |
| 1081 |
<listitem> |
| 1082 |
<para> |
| 1083 |
<link linkend="auth-trust">Trust authentication</link>, which |
| 1084 |
simply trusts that users are who they say they are. |
| 1085 |
</para> |
| 1086 |
</listitem> |
| 1087 |
<listitem> |
| 1088 |
<para> |
| 1089 |
<link linkend="auth-password">Password authentication</link>, which |
| 1090 |
requires that users send a password. |
| 1091 |
</para> |
| 1092 |
</listitem> |
| 1093 |
<listitem> |
| 1094 |
<para> |
| 1095 |
<link linkend="gssapi-auth">GSSAPI authentication</link>, which |
| 1096 |
relies on a GSSAPI-compatible security library. Typically this is |
| 1097 |
used to access an authentication server such as a Kerberos or |
| 1098 |
Microsoft Active Directory server. |
| 1099 |
</para> |
| 1100 |
</listitem> |
| 1101 |
<listitem> |
| 1102 |
<para> |
| 1103 |
<link linkend="sspi-auth">SSPI authentication</link>, which |
| 1104 |
uses a Windows-specific protocol similar to GSSAPI. |
| 1105 |
</para> |
| 1106 |
</listitem> |
| 1107 |
<listitem> |
| 1108 |
<para> |
| 1109 |
<link linkend="auth-ident">Ident authentication</link>, which |
| 1110 |
relies on an <quote>Identification Protocol</quote> |
| 1111 |
(<ulink url="https://datatracker.ietf.org/doc/html/rfc1413">RFC 1413</ulink>) |
| 1112 |
service on the client's machine. (On local Unix-socket connections, |
| 1113 |
this is treated as peer authentication.) |
| 1114 |
</para> |
| 1115 |
</listitem> |
| 1116 |
<listitem> |
| 1117 |
<para> |
| 1118 |
<link linkend="auth-peer">Peer authentication</link>, which |
| 1119 |
relies on operating system facilities to identify the process at the |
| 1120 |
other end of a local connection. This is not supported for remote |
| 1121 |
connections. |
| 1122 |
</para> |
| 1123 |
</listitem> |
| 1124 |
<listitem> |
| 1125 |
<para> |
| 1126 |
<link linkend="auth-ldap">LDAP authentication</link>, which |
| 1127 |
relies on an LDAP authentication server. |
| 1128 |
</para> |
| 1129 |
</listitem> |
| 1130 |
<listitem> |
| 1131 |
<para> |
| 1132 |
<link linkend="auth-radius">RADIUS authentication</link>, which |
| 1133 |
relies on a RADIUS authentication server. |
| 1134 |
</para> |
| 1135 |
</listitem> |
| 1136 |
<listitem> |
| 1137 |
<para> |
| 1138 |
<link linkend="auth-cert">Certificate authentication</link>, which |
| 1139 |
requires an SSL connection and authenticates users by checking the |
| 1140 |
SSL certificate they send. |
| 1141 |
</para> |
| 1142 |
</listitem> |
| 1143 |
<listitem> |
| 1144 |
<para> |
| 1145 |
<link linkend="auth-pam">PAM authentication</link>, which |
| 1146 |
relies on a PAM (Pluggable Authentication Modules) library. |
| 1147 |
</para> |
| 1148 |
</listitem> |
| 1149 |
<listitem> |
| 1150 |
<para> |
| 1151 |
<link linkend="auth-bsd">BSD authentication</link>, which |
| 1152 |
relies on the BSD Authentication framework (currently available |
| 1153 |
only on OpenBSD). |
| 1154 |
</para> |
| 1155 |
</listitem> |
| 1156 |
<listitem> |
| 1157 |
<para> |
| 1158 |
<link linkend="auth-oauth">OAuth authorization/authentication</link>, |
| 1159 |
which relies on an external OAuth 2.0 identity provider. |
| 1160 |
</para> |
| 1161 |
</listitem> |
| 1162 |
</itemizedlist> |
| 1163 |
</para> |
| 1164 |
|
| 1165 |
<para> |
| 1166 |
Peer authentication is usually recommendable for local connections, |
| 1167 |
though trust authentication might be sufficient in some circumstances. |
| 1168 |
Password authentication is the easiest choice for remote connections. |
| 1169 |
All the other options require some kind of external security |
| 1170 |
infrastructure (usually an authentication server or a certificate |
| 1171 |
authority for issuing SSL certificates), or are platform-specific. |
| 1172 |
</para> |
| 1173 |
|
| 1174 |
<para> |
| 1175 |
The following sections describe each of these authentication methods |
| 1176 |
in more detail. |
| 1177 |
</para> |
| 1178 |
</sect1> |
| 1179 |
|
| 1180 |
<sect1 id="auth-trust"> |
| 1181 |
<title>Trust Authentication</title> |
| 1182 |
|
| 1183 |
<para> |
| 1184 |
When <literal>trust</literal> authentication is specified, |
| 1185 |
<productname>PostgreSQL</productname> assumes that anyone who can |
| 1186 |
connect to the server is authorized to access the database with |
| 1187 |
whatever database user name they specify (even superuser names). |
| 1188 |
Of course, restrictions made in the <literal>database</literal> and |
| 1189 |
<literal>user</literal> columns still apply. |
| 1190 |
This method should only be used when there is adequate |
| 1191 |
operating-system-level protection on connections to the server. |
| 1192 |
</para> |
| 1193 |
|
| 1194 |
<para> |
| 1195 |
<literal>trust</literal> authentication is appropriate and very |
| 1196 |
convenient for local connections on a single-user workstation. It |
| 1197 |
is usually <emphasis>not</emphasis> appropriate by itself on a multiuser |
| 1198 |
machine. However, you might be able to use <literal>trust</literal> even |
| 1199 |
on a multiuser machine, if you restrict access to the server's |
| 1200 |
Unix-domain socket file using file-system permissions. To do this, set the |
| 1201 |
<varname>unix_socket_permissions</varname> (and possibly |
| 1202 |
<varname>unix_socket_group</varname>) configuration parameters as |
| 1203 |
described in <xref linkend="runtime-config-connection"/>. Or you |
| 1204 |
could set the <varname>unix_socket_directories</varname> |
| 1205 |
configuration parameter to place the socket file in a suitably |
| 1206 |
restricted directory. |
| 1207 |
</para> |
| 1208 |
|
| 1209 |
<para> |
| 1210 |
Setting file-system permissions only helps for Unix-socket connections. |
| 1211 |
Local TCP/IP connections are not restricted by file-system permissions. |
| 1212 |
Therefore, if you want to use file-system permissions for local security, |
| 1213 |
remove the <literal>host ... 127.0.0.1 ...</literal> line from |
| 1214 |
<filename>pg_hba.conf</filename>, or change it to a |
| 1215 |
non-<literal>trust</literal> authentication method. |
| 1216 |
</para> |
| 1217 |
|
| 1218 |
<para> |
| 1219 |
<literal>trust</literal> authentication is only suitable for TCP/IP connections |
| 1220 |
if you trust every user on every machine that is allowed to connect |
| 1221 |
to the server by the <filename>pg_hba.conf</filename> lines that specify |
| 1222 |
<literal>trust</literal>. It is seldom reasonable to use <literal>trust</literal> |
| 1223 |
for any TCP/IP connections other than those from <systemitem>localhost</systemitem> (127.0.0.1). |
| 1224 |
</para> |
| 1225 |
|
| 1226 |
</sect1> |
| 1227 |
|
| 1228 |
<sect1 id="auth-password"> |
| 1229 |
<title>Password Authentication</title> |
| 1230 |
|
| 1231 |
<indexterm> |
| 1232 |
<primary>MD5</primary> |
| 1233 |
</indexterm> |
| 1234 |
<indexterm> |
| 1235 |
<primary>SCRAM</primary> |
| 1236 |
</indexterm> |
| 1237 |
<indexterm> |
| 1238 |
<primary>password</primary> |
| 1239 |
<secondary>authentication</secondary> |
| 1240 |
</indexterm> |
| 1241 |
|
| 1242 |
<para> |
| 1243 |
There are several password-based authentication methods. These methods |
| 1244 |
operate similarly but differ in how the users' passwords are stored on the |
| 1245 |
server and how the password provided by a client is sent across the |
| 1246 |
connection. |
| 1247 |
</para> |
| 1248 |
|
| 1249 |
<variablelist> |
| 1250 |
<varlistentry> |
| 1251 |
<term><literal>scram-sha-256</literal></term> |
| 1252 |
<listitem> |
| 1253 |
<para> |
| 1254 |
The method <literal>scram-sha-256</literal> performs SCRAM-SHA-256 |
| 1255 |
authentication, as described in |
| 1256 |
<ulink url="https://datatracker.ietf.org/doc/html/rfc7677">RFC 7677</ulink>. It |
| 1257 |
is a challenge-response scheme that prevents password sniffing on |
| 1258 |
untrusted connections and supports storing passwords on the server in a |
| 1259 |
cryptographically hashed form that is thought to be secure. |
| 1260 |
</para> |
| 1261 |
|
| 1262 |
<para> |
| 1263 |
This is the most secure of the currently provided methods, but it is |
| 1264 |
not supported by older client libraries. |
| 1265 |
</para> |
| 1266 |
</listitem> |
| 1267 |
</varlistentry> |
| 1268 |
|
| 1269 |
<varlistentry> |
| 1270 |
<term><literal>md5</literal></term> |
| 1271 |
<listitem> |
| 1272 |
<para> |
| 1273 |
The method <literal>md5</literal> uses a custom less secure challenge-response |
| 1274 |
mechanism. It prevents password sniffing and avoids storing passwords |
| 1275 |
on the server in plain text but provides no protection if an attacker |
| 1276 |
manages to steal the password hash from the server. Also, the MD5 hash |
| 1277 |
algorithm is nowadays no longer considered secure against determined |
| 1278 |
attacks. |
| 1279 |
</para> |
| 1280 |
|
| 1281 |
<para> |
| 1282 |
To ease transition from the <literal>md5</literal> method to the newer |
| 1283 |
SCRAM method, if <literal>md5</literal> is specified as a method |
| 1284 |
in <filename>pg_hba.conf</filename> but the user's password on the |
| 1285 |
server is encrypted for SCRAM (see below), then SCRAM-based |
| 1286 |
authentication will automatically be chosen instead. |
| 1287 |
</para> |
| 1288 |
|
| 1289 |
<warning> |
| 1290 |
<para> |
| 1291 |
Support for MD5-encrypted passwords is deprecated and will be removed |
| 1292 |
in a future release of <productname>PostgreSQL</productname>. Refer to |
| 1293 |
the text below for details about migrating to another password type. |
| 1294 |
</para> |
| 1295 |
</warning> |
| 1296 |
</listitem> |
| 1297 |
</varlistentry> |
| 1298 |
|
| 1299 |
<varlistentry> |
| 1300 |
<term><literal>password</literal></term> |
| 1301 |
<listitem> |
| 1302 |
<para> |
| 1303 |
The method <literal>password</literal> sends the password in clear-text and is |
| 1304 |
therefore vulnerable to password <quote>sniffing</quote> attacks. It should |
| 1305 |
always be avoided if possible. If the connection is protected by SSL |
| 1306 |
encryption then <literal>password</literal> can be used safely, though. |
| 1307 |
(Though SSL certificate authentication might be a better choice if one |
| 1308 |
is depending on using SSL). |
| 1309 |
</para> |
| 1310 |
</listitem> |
| 1311 |
</varlistentry> |
| 1312 |
</variablelist> |
| 1313 |
|
| 1314 |
<para> |
| 1315 |
<productname>PostgreSQL</productname> database passwords are |
| 1316 |
separate from operating system user passwords. The password for |
| 1317 |
each database user is stored in the <literal>pg_authid</literal> system |
| 1318 |
catalog. Passwords can be managed with the SQL commands |
| 1319 |
<xref linkend="sql-createrole"/> and |
| 1320 |
<xref linkend="sql-alterrole"/>, |
| 1321 |
e.g., <userinput>CREATE ROLE foo WITH LOGIN PASSWORD 'secret'</userinput>, |
| 1322 |
or the <application>psql</application> |
| 1323 |
command <literal>\password</literal>. |
| 1324 |
If no password has been set up for a user, the stored password |
| 1325 |
is null and password authentication will always fail for that user. |
| 1326 |
</para> |
| 1327 |
|
| 1328 |
<para> |
| 1329 |
The availability of the different password-based authentication methods |
| 1330 |
depends on how a user's password on the server is encrypted (or hashed, |
| 1331 |
more accurately). This is controlled by the configuration |
| 1332 |
parameter <xref linkend="guc-password-encryption"/> at the time the |
| 1333 |
password is set. If a password was encrypted using |
| 1334 |
the <literal>scram-sha-256</literal> setting, then it can be used for the |
| 1335 |
authentication methods <literal>scram-sha-256</literal> |
| 1336 |
and <literal>password</literal> (but password transmission will be in |
| 1337 |
plain text in the latter case). The authentication method |
| 1338 |
specification <literal>md5</literal> will automatically switch to using |
| 1339 |
the <literal>scram-sha-256</literal> method in this case, as explained |
| 1340 |
above, so it will also work. If a password was encrypted using |
| 1341 |
the <literal>md5</literal> setting, then it can be used only for |
| 1342 |
the <literal>md5</literal> and <literal>password</literal> authentication |
| 1343 |
method specifications (again, with the password transmitted in plain text |
| 1344 |
in the latter case). (Previous PostgreSQL releases supported storing the |
| 1345 |
password on the server in plain text. This is no longer possible.) To |
| 1346 |
check the currently stored password hashes, see the system |
| 1347 |
catalog <literal>pg_authid</literal>. |
| 1348 |
</para> |
| 1349 |
|
| 1350 |
<para> |
| 1351 |
To upgrade an existing installation from <literal>md5</literal> |
| 1352 |
to <literal>scram-sha-256</literal>, after having ensured that all client |
| 1353 |
libraries in use are new enough to support SCRAM, |
| 1354 |
set <literal>password_encryption = 'scram-sha-256'</literal> |
| 1355 |
in <filename>postgresql.conf</filename>, make all users set new passwords, |
| 1356 |
and change the authentication method specifications |
| 1357 |
in <filename>pg_hba.conf</filename> to <literal>scram-sha-256</literal>. |
| 1358 |
</para> |
| 1359 |
</sect1> |
| 1360 |
|
| 1361 |
<sect1 id="gssapi-auth"> |
| 1362 |
<title>GSSAPI Authentication</title> |
| 1363 |
|
| 1364 |
<indexterm zone="gssapi-auth"> |
| 1365 |
<primary>GSSAPI</primary> |
| 1366 |
</indexterm> |
| 1367 |
|
| 1368 |
<para> |
| 1369 |
<productname>GSSAPI</productname> is an industry-standard protocol |
| 1370 |
for secure authentication defined in |
| 1371 |
<ulink url="https://datatracker.ietf.org/doc/html/rfc2743">RFC 2743</ulink>. |
| 1372 |
<productname>PostgreSQL</productname> |
| 1373 |
supports <productname>GSSAPI</productname> for authentication, |
| 1374 |
communications encryption, or both. |
| 1375 |
<productname>GSSAPI</productname> provides automatic authentication |
| 1376 |
(single sign-on) for systems that support it. The authentication itself is |
| 1377 |
secure. If <productname>GSSAPI</productname> encryption |
| 1378 |
or <acronym>SSL</acronym> encryption is |
| 1379 |
used, the data sent along the database connection will be encrypted; |
| 1380 |
otherwise, it will not. |
| 1381 |
</para> |
| 1382 |
|
| 1383 |
<para> |
| 1384 |
GSSAPI support has to be enabled when <productname>PostgreSQL</productname> is built; |
| 1385 |
see <xref linkend="installation"/> for more information. |
| 1386 |
</para> |
| 1387 |
|
| 1388 |
<para> |
| 1389 |
When <productname>GSSAPI</productname> uses |
| 1390 |
<productname>Kerberos</productname>, it uses a standard service |
| 1391 |
principal (authentication identity) name in the format |
| 1392 |
<literal><replaceable>servicename</replaceable>/<replaceable>hostname</replaceable>@<replaceable>realm</replaceable></literal>. |
| 1393 |
The principal name used by a particular installation is not encoded in |
| 1394 |
the <productname>PostgreSQL</productname> server in any way; rather it |
| 1395 |
is specified in the <firstterm>keytab</firstterm> file that the server |
| 1396 |
reads to determine its identity. If multiple principals are listed in |
| 1397 |
the keytab file, the server will accept any one of them. |
| 1398 |
The server's realm name is the preferred realm specified in the Kerberos |
| 1399 |
configuration file(s) accessible to the server. |
| 1400 |
</para> |
| 1401 |
|
| 1402 |
<para> |
| 1403 |
When connecting, the client must know the principal name of the server |
| 1404 |
it intends to connect to. The <replaceable>servicename</replaceable> |
| 1405 |
part of the principal is ordinarily <literal>postgres</literal>, |
| 1406 |
but another value can be selected via <application>libpq</application>'s |
| 1407 |
<xref linkend="libpq-connect-krbsrvname"/> connection parameter. |
| 1408 |
The <replaceable>hostname</replaceable> part is the fully qualified |
| 1409 |
host name that <application>libpq</application> is told to connect to. |
| 1410 |
The realm name is the preferred realm specified in the Kerberos |
| 1411 |
configuration file(s) accessible to the client. |
| 1412 |
</para> |
| 1413 |
|
| 1414 |
<para> |
| 1415 |
The client will also have a principal name for its own identity |
| 1416 |
(and it must have a valid ticket for this principal). To |
| 1417 |
use <productname>GSSAPI</productname> for authentication, the client |
| 1418 |
principal must be associated with |
| 1419 |
a <productname>PostgreSQL</productname> database user name. |
| 1420 |
The <filename>pg_ident.conf</filename> configuration file can be used |
| 1421 |
to map principals to user names; for example, |
| 1422 |
<literal>pgusername@realm</literal> could be mapped to just <literal>pgusername</literal>. |
| 1423 |
Alternatively, you can use the full <literal>username@realm</literal> principal as |
| 1424 |
the role name in <productname>PostgreSQL</productname> without any mapping. |
| 1425 |
</para> |
| 1426 |
|
| 1427 |
<para> |
| 1428 |
<productname>PostgreSQL</productname> also supports mapping |
| 1429 |
client principals to user names by just stripping the realm from |
| 1430 |
the principal. This method is supported for backwards compatibility and is |
| 1431 |
strongly discouraged as it is then impossible to distinguish different users |
| 1432 |
with the same user name but coming from different realms. To enable this, |
| 1433 |
set <literal>include_realm</literal> to 0. For simple single-realm |
| 1434 |
installations, doing that combined with setting the |
| 1435 |
<literal>krb_realm</literal> parameter (which checks that the principal's realm |
| 1436 |
matches exactly what is in the <literal>krb_realm</literal> parameter) |
| 1437 |
is still secure; but this is a |
| 1438 |
less capable approach compared to specifying an explicit mapping in |
| 1439 |
<filename>pg_ident.conf</filename>. |
| 1440 |
</para> |
| 1441 |
|
| 1442 |
<para> |
| 1443 |
The location of the server's keytab file is specified by the <xref |
| 1444 |
linkend="guc-krb-server-keyfile"/> configuration parameter. |
| 1445 |
For security reasons, it is recommended to use a separate keytab |
| 1446 |
just for the <productname>PostgreSQL</productname> server rather |
| 1447 |
than allowing the server to read the system keytab file. |
| 1448 |
Make sure that your server keytab file is readable (and preferably |
| 1449 |
only readable, not writable) by the <productname>PostgreSQL</productname> |
| 1450 |
server account. (See also <xref linkend="postgres-user"/>.) |
| 1451 |
</para> |
| 1452 |
|
| 1453 |
<para> |
| 1454 |
The keytab file is generated using the Kerberos software; see the |
| 1455 |
Kerberos documentation for details. The following example shows |
| 1456 |
doing this using the <application>kadmin</application> tool of |
| 1457 |
MIT Kerberos: |
| 1458 |
<screen> |
| 1459 |
<prompt>kadmin% </prompt><userinput>addprinc -randkey postgres/server.my.domain.org</userinput> |
| 1460 |
<prompt>kadmin% </prompt><userinput>ktadd -k krb5.keytab postgres/server.my.domain.org</userinput> |
| 1461 |
</screen> |
| 1462 |
</para> |
| 1463 |
|
| 1464 |
<para> |
| 1465 |
The following authentication options are supported for |
| 1466 |
the <productname>GSSAPI</productname> authentication method: |
| 1467 |
<variablelist> |
| 1468 |
<varlistentry> |
| 1469 |
<term><literal>include_realm</literal></term> |
| 1470 |
<listitem> |
| 1471 |
<para> |
| 1472 |
If set to 0, the realm name from the authenticated user principal is |
| 1473 |
stripped off before being passed through the user name mapping |
| 1474 |
(<xref linkend="auth-username-maps"/>). This is discouraged and is |
| 1475 |
primarily available for backwards compatibility, as it is not secure |
| 1476 |
in multi-realm environments unless <literal>krb_realm</literal> is |
| 1477 |
also used. It is recommended to |
| 1478 |
leave <literal>include_realm</literal> set to the default (1) and to |
| 1479 |
provide an explicit mapping in <filename>pg_ident.conf</filename> to convert |
| 1480 |
principal names to <productname>PostgreSQL</productname> user names. |
| 1481 |
</para> |
| 1482 |
</listitem> |
| 1483 |
</varlistentry> |
| 1484 |
|
| 1485 |
<varlistentry> |
| 1486 |
<term><literal>map</literal></term> |
| 1487 |
<listitem> |
| 1488 |
<para> |
| 1489 |
Allows mapping from client principals to database user names. See |
| 1490 |
<xref linkend="auth-username-maps"/> for details. For a GSSAPI/Kerberos |
| 1491 |
principal, such as <literal>[email protected]</literal> (or, less |
| 1492 |
commonly, <literal>username/[email protected]</literal>), the |
| 1493 |
user name used for mapping is |
| 1494 |
<literal>[email protected]</literal> (or |
| 1495 |
<literal>username/[email protected]</literal>, respectively), |
| 1496 |
unless <literal>include_realm</literal> has been set to 0, in which case |
| 1497 |
<literal>username</literal> (or <literal>username/hostbased</literal>) |
| 1498 |
is what is seen as the system user name when mapping. |
| 1499 |
</para> |
| 1500 |
</listitem> |
| 1501 |
</varlistentry> |
| 1502 |
|
| 1503 |
<varlistentry> |
| 1504 |
<term><literal>krb_realm</literal></term> |
| 1505 |
<listitem> |
| 1506 |
<para> |
| 1507 |
Sets the realm to match user principal names against. If this parameter |
| 1508 |
is set, only users of that realm will be accepted. If it is not set, |
| 1509 |
users of any realm can connect, subject to whatever user name mapping |
| 1510 |
is done. |
| 1511 |
</para> |
| 1512 |
</listitem> |
| 1513 |
</varlistentry> |
| 1514 |
</variablelist> |
| 1515 |
</para> |
| 1516 |
|
| 1517 |
<para> |
| 1518 |
In addition to these settings, which can be different for |
| 1519 |
different <filename>pg_hba.conf</filename> entries, there is the |
| 1520 |
server-wide <xref linkend="guc-krb-caseins-users"/> configuration |
| 1521 |
parameter. If that is set to true, client principals are matched to |
| 1522 |
user map entries case-insensitively. <literal>krb_realm</literal>, if |
| 1523 |
set, is also matched case-insensitively. |
| 1524 |
</para> |
| 1525 |
</sect1> |
| 1526 |
|
| 1527 |
<sect1 id="sspi-auth"> |
| 1528 |
<title>SSPI Authentication</title> |
| 1529 |
|
| 1530 |
<indexterm zone="sspi-auth"> |
| 1531 |
<primary>SSPI</primary> |
| 1532 |
</indexterm> |
| 1533 |
|
| 1534 |
<para> |
| 1535 |
<productname>SSPI</productname> is a <productname>Windows</productname> |
| 1536 |
technology for secure authentication with single sign-on. |
| 1537 |
<productname>PostgreSQL</productname> will use SSPI in |
| 1538 |
<literal>negotiate</literal> mode, which will use |
| 1539 |
<productname>Kerberos</productname> when possible and automatically |
| 1540 |
fall back to <productname>NTLM</productname> in other cases. |
| 1541 |
<productname>SSPI</productname> and <productname>GSSAPI</productname> |
| 1542 |
interoperate as clients and servers, e.g., an |
| 1543 |
<productname>SSPI</productname> client can authenticate to an |
| 1544 |
<productname>GSSAPI</productname> server. It is recommended to use |
| 1545 |
<productname>SSPI</productname> on Windows clients and servers and |
| 1546 |
<productname>GSSAPI</productname> on non-Windows platforms. |
| 1547 |
</para> |
| 1548 |
|
| 1549 |
<para> |
| 1550 |
When using <productname>Kerberos</productname> authentication, |
| 1551 |
<productname>SSPI</productname> works the same way |
| 1552 |
<productname>GSSAPI</productname> does; see <xref linkend="gssapi-auth"/> |
| 1553 |
for details. |
| 1554 |
</para> |
| 1555 |
|
| 1556 |
<para> |
| 1557 |
The following configuration options are supported for <productname>SSPI</productname>: |
| 1558 |
<variablelist> |
| 1559 |
|
| 1560 |
<varlistentry> |
| 1561 |
<term><literal>include_realm</literal></term> |
| 1562 |
<listitem> |
| 1563 |
<para> |
| 1564 |
If set to 0, the realm name from the authenticated user principal is |
| 1565 |
stripped off before being passed through the user name mapping |
| 1566 |
(<xref linkend="auth-username-maps"/>). This is discouraged and is |
| 1567 |
primarily available for backwards compatibility, as it is not secure |
| 1568 |
in multi-realm environments unless <literal>krb_realm</literal> is |
| 1569 |
also used. It is recommended to |
| 1570 |
leave <literal>include_realm</literal> set to the default (1) and to |
| 1571 |
provide an explicit mapping in <filename>pg_ident.conf</filename> to convert |
| 1572 |
principal names to <productname>PostgreSQL</productname> user names. |
| 1573 |
</para> |
| 1574 |
</listitem> |
| 1575 |
</varlistentry> |
| 1576 |
|
| 1577 |
<varlistentry> |
| 1578 |
<term><literal>compat_realm</literal></term> |
| 1579 |
<listitem> |
| 1580 |
<para> |
| 1581 |
If set to 1, the domain's SAM-compatible name (also known as the |
| 1582 |
NetBIOS name) is used for the <literal>include_realm</literal> |
| 1583 |
option. This is the default. If set to 0, the true realm name from |
| 1584 |
the Kerberos user principal name is used. |
| 1585 |
</para> |
| 1586 |
<para> |
| 1587 |
Do not disable this option unless your server runs under a domain |
| 1588 |
account (this includes virtual service accounts on a domain member |
| 1589 |
system) and all clients authenticating through SSPI are also using |
| 1590 |
domain accounts, or authentication will fail. |
| 1591 |
</para> |
| 1592 |
</listitem> |
| 1593 |
</varlistentry> |
| 1594 |
|
| 1595 |
<varlistentry> |
| 1596 |
<term><literal>upn_username</literal></term> |
| 1597 |
<listitem> |
| 1598 |
<para> |
| 1599 |
If this option is enabled along with <literal>compat_realm</literal>, |
| 1600 |
the user name from the Kerberos UPN is used for authentication. If |
| 1601 |
it is disabled (the default), the SAM-compatible user name is used. |
| 1602 |
By default, these two names are identical for new user accounts. |
| 1603 |
</para> |
| 1604 |
<para> |
| 1605 |
Note that <application>libpq</application> uses the SAM-compatible name if no |
| 1606 |
explicit user name is specified. If you use |
| 1607 |
<application>libpq</application> or a driver based on it, you should |
| 1608 |
leave this option disabled or explicitly specify user name in the |
| 1609 |
connection string. |
| 1610 |
</para> |
| 1611 |
</listitem> |
| 1612 |
</varlistentry> |
| 1613 |
|
| 1614 |
<varlistentry> |
| 1615 |
<term><literal>map</literal></term> |
| 1616 |
<listitem> |
| 1617 |
<para> |
| 1618 |
Allows for mapping between system and database user names. See |
| 1619 |
<xref linkend="auth-username-maps"/> for details. For an SSPI/Kerberos |
| 1620 |
principal, such as <literal>[email protected]</literal> (or, less |
| 1621 |
commonly, <literal>username/[email protected]</literal>), the |
| 1622 |
user name used for mapping is |
| 1623 |
<literal>[email protected]</literal> (or |
| 1624 |
<literal>username/[email protected]</literal>, respectively), |
| 1625 |
unless <literal>include_realm</literal> has been set to 0, in which case |
| 1626 |
<literal>username</literal> (or <literal>username/hostbased</literal>) |
| 1627 |
is what is seen as the system user name when mapping. |
| 1628 |
</para> |
| 1629 |
</listitem> |
| 1630 |
</varlistentry> |
| 1631 |
|
| 1632 |
<varlistentry> |
| 1633 |
<term><literal>krb_realm</literal></term> |
| 1634 |
<listitem> |
| 1635 |
<para> |
| 1636 |
Sets the realm to match user principal names against. If this parameter |
| 1637 |
is set, only users of that realm will be accepted. If it is not set, |
| 1638 |
users of any realm can connect, subject to whatever user name mapping |
| 1639 |
is done. |
| 1640 |
</para> |
| 1641 |
</listitem> |
| 1642 |
</varlistentry> |
| 1643 |
</variablelist> |
| 1644 |
</para> |
| 1645 |
</sect1> |
| 1646 |
|
| 1647 |
<sect1 id="auth-ident"> |
| 1648 |
<title>Ident Authentication</title> |
| 1649 |
|
| 1650 |
<indexterm> |
| 1651 |
<primary>ident</primary> |
| 1652 |
</indexterm> |
| 1653 |
|
| 1654 |
<para> |
| 1655 |
The ident authentication method works by obtaining the client's |
| 1656 |
operating system user name from an ident server and using it as |
| 1657 |
the allowed database user name (with an optional user name mapping). |
| 1658 |
This is only supported on TCP/IP connections. |
| 1659 |
</para> |
| 1660 |
|
| 1661 |
<note> |
| 1662 |
<para> |
| 1663 |
When ident is specified for a local (non-TCP/IP) connection, |
| 1664 |
peer authentication (see <xref linkend="auth-peer"/>) will be |
| 1665 |
used instead. |
| 1666 |
</para> |
| 1667 |
</note> |
| 1668 |
|
| 1669 |
<para> |
| 1670 |
The following configuration options are supported for <literal>ident</literal>: |
| 1671 |
<variablelist> |
| 1672 |
<varlistentry> |
| 1673 |
<term><literal>map</literal></term> |
| 1674 |
<listitem> |
| 1675 |
<para> |
| 1676 |
Allows for mapping between system and database user names. See |
| 1677 |
<xref linkend="auth-username-maps"/> for details. |
| 1678 |
</para> |
| 1679 |
</listitem> |
| 1680 |
</varlistentry> |
| 1681 |
</variablelist> |
| 1682 |
</para> |
| 1683 |
|
| 1684 |
<para> |
| 1685 |
The <quote>Identification Protocol</quote> is described in |
| 1686 |
<ulink url="https://datatracker.ietf.org/doc/html/rfc1413">RFC 1413</ulink>. |
| 1687 |
Virtually every Unix-like |
| 1688 |
operating system ships with an ident server that listens on TCP |
| 1689 |
port 113 by default. The basic functionality of an ident server |
| 1690 |
is to answer questions like <quote>What user initiated the |
| 1691 |
connection that goes out of your port <replaceable>X</replaceable> |
| 1692 |
and connects to my port <replaceable>Y</replaceable>?</quote>. |
| 1693 |
Since <productname>PostgreSQL</productname> knows both <replaceable>X</replaceable> and |
| 1694 |
<replaceable>Y</replaceable> when a physical connection is established, it |
| 1695 |
can interrogate the ident server on the host of the connecting |
| 1696 |
client and can theoretically determine the operating system user |
| 1697 |
for any given connection. |
| 1698 |
</para> |
| 1699 |
|
| 1700 |
<para> |
| 1701 |
The drawback of this procedure is that it depends on the integrity |
| 1702 |
of the client: if the client machine is untrusted or compromised, |
| 1703 |
an attacker could run just about any program on port 113 and |
| 1704 |
return any user name they choose. This authentication method is |
| 1705 |
therefore only appropriate for closed networks where each client |
| 1706 |
machine is under tight control and where the database and system |
| 1707 |
administrators operate in close contact. In other words, you must |
| 1708 |
trust the machine running the ident server. |
| 1709 |
Heed the warning: |
| 1710 |
<blockquote> |
| 1711 |
<attribution>RFC 1413</attribution> |
| 1712 |
<para> |
| 1713 |
The Identification Protocol is not intended as an authorization |
| 1714 |
or access control protocol. |
| 1715 |
</para> |
| 1716 |
</blockquote> |
| 1717 |
</para> |
| 1718 |
|
| 1719 |
<para> |
| 1720 |
Some ident servers have a nonstandard option that causes the returned |
| 1721 |
user name to be encrypted, using a key that only the originating |
| 1722 |
machine's administrator knows. This option <emphasis>must not</emphasis> be |
| 1723 |
used when using the ident server with <productname>PostgreSQL</productname>, |
| 1724 |
since <productname>PostgreSQL</productname> does not have any way to decrypt the |
| 1725 |
returned string to determine the actual user name. |
| 1726 |
</para> |
| 1727 |
</sect1> |
| 1728 |
|
| 1729 |
<sect1 id="auth-peer"> |
| 1730 |
<title>Peer Authentication</title> |
| 1731 |
|
| 1732 |
<indexterm> |
| 1733 |
<primary>peer</primary> |
| 1734 |
</indexterm> |
| 1735 |
|
| 1736 |
<para> |
| 1737 |
The peer authentication method works by obtaining the client's |
| 1738 |
operating system user name from the kernel and using it as the |
| 1739 |
allowed database user name (with optional user name mapping). This |
| 1740 |
method is only supported on local connections. |
| 1741 |
</para> |
| 1742 |
|
| 1743 |
<para> |
| 1744 |
The following configuration options are supported for <literal>peer</literal>: |
| 1745 |
<variablelist> |
| 1746 |
<varlistentry> |
| 1747 |
<term><literal>map</literal></term> |
| 1748 |
<listitem> |
| 1749 |
<para> |
| 1750 |
Allows for mapping between system and database user names. See |
| 1751 |
<xref linkend="auth-username-maps"/> for details. |
| 1752 |
</para> |
| 1753 |
</listitem> |
| 1754 |
</varlistentry> |
| 1755 |
</variablelist> |
| 1756 |
</para> |
| 1757 |
|
| 1758 |
<para> |
| 1759 |
Peer authentication is only available on operating systems providing |
| 1760 |
the <function>getpeereid()</function> function, the <symbol>SO_PEERCRED</symbol> |
| 1761 |
socket parameter, or similar mechanisms. Currently that includes |
| 1762 |
<systemitem class="osname">Linux</systemitem>, |
| 1763 |
most flavors of <systemitem class="osname">BSD</systemitem> including |
| 1764 |
<systemitem class="osname">macOS</systemitem>, |
| 1765 |
and <systemitem class="osname">Solaris</systemitem>. |
| 1766 |
</para> |
| 1767 |
|
| 1768 |
</sect1> |
| 1769 |
|
| 1770 |
<sect1 id="auth-ldap"> |
| 1771 |
<title>LDAP Authentication</title> |
| 1772 |
|
| 1773 |
<indexterm zone="auth-ldap"> |
| 1774 |
<primary>LDAP</primary> |
| 1775 |
</indexterm> |
| 1776 |
|
| 1777 |
<para> |
| 1778 |
This authentication method operates similarly to |
| 1779 |
<literal>password</literal> except that it uses LDAP |
| 1780 |
as the password verification method. LDAP is used only to validate |
| 1781 |
the user name/password pairs. Therefore the user must already |
| 1782 |
exist in the database before LDAP can be used for |
| 1783 |
authentication. |
| 1784 |
</para> |
| 1785 |
|
| 1786 |
<para> |
| 1787 |
LDAP authentication can operate in two modes. In the first mode, |
| 1788 |
which we will call the simple bind mode, |
| 1789 |
the server will bind to the distinguished name constructed as |
| 1790 |
<replaceable>prefix</replaceable> <replaceable>username</replaceable> <replaceable>suffix</replaceable>. |
| 1791 |
Typically, the <replaceable>prefix</replaceable> parameter is used to specify |
| 1792 |
<literal>cn=</literal>, or <replaceable>DOMAIN</replaceable><literal>\</literal> in an Active |
| 1793 |
Directory environment. <replaceable>suffix</replaceable> is used to specify the |
| 1794 |
remaining part of the DN in a non-Active Directory environment. |
| 1795 |
</para> |
| 1796 |
|
| 1797 |
<para> |
| 1798 |
In the second mode, which we will call the search+bind mode, |
| 1799 |
the server first binds to the LDAP directory with |
| 1800 |
a fixed user name and password, specified with <replaceable>ldapbinddn</replaceable> |
| 1801 |
and <replaceable>ldapbindpasswd</replaceable>, and performs a search for the user trying |
| 1802 |
to log in to the database. If no user and password is configured, an |
| 1803 |
anonymous bind will be attempted to the directory. The search will be |
| 1804 |
performed over the subtree at <replaceable>ldapbasedn</replaceable>, and will try to |
| 1805 |
do an exact match of the attribute specified in |
| 1806 |
<replaceable>ldapsearchattribute</replaceable>. |
| 1807 |
Once the user has been found in |
| 1808 |
this search, the server re-binds to the directory as |
| 1809 |
this user, using the password specified by the client, to verify that the |
| 1810 |
login is correct. This mode is the same as that used by LDAP authentication |
| 1811 |
schemes in other software, such as Apache <literal>mod_authnz_ldap</literal> and <literal>pam_ldap</literal>. |
| 1812 |
This method allows for significantly more flexibility |
| 1813 |
in where the user objects are located in the directory, but will cause |
| 1814 |
two additional requests to the LDAP server to be made. |
| 1815 |
</para> |
| 1816 |
|
| 1817 |
<para> |
| 1818 |
The following configuration options are used in both modes: |
| 1819 |
<variablelist> |
| 1820 |
<varlistentry> |
| 1821 |
<term><literal>ldapserver</literal></term> |
| 1822 |
<listitem> |
| 1823 |
<para> |
| 1824 |
Names or IP addresses of LDAP servers to connect to. Multiple |
| 1825 |
servers may be specified, separated by spaces. |
| 1826 |
</para> |
| 1827 |
</listitem> |
| 1828 |
</varlistentry> |
| 1829 |
<varlistentry> |
| 1830 |
<term><literal>ldapport</literal></term> |
| 1831 |
<listitem> |
| 1832 |
<para> |
| 1833 |
Port number on LDAP server to connect to. If no port is specified, |
| 1834 |
the LDAP library's default port setting will be used. |
| 1835 |
</para> |
| 1836 |
</listitem> |
| 1837 |
</varlistentry> |
| 1838 |
<varlistentry> |
| 1839 |
<term><literal>ldapscheme</literal></term> |
| 1840 |
<listitem> |
| 1841 |
<para> |
| 1842 |
Set to <literal>ldaps</literal> to use LDAPS. This is a non-standard |
| 1843 |
way of using LDAP over SSL, supported by some LDAP server |
| 1844 |
implementations. See also the <literal>ldaptls</literal> option for |
| 1845 |
an alternative. |
| 1846 |
</para> |
| 1847 |
</listitem> |
| 1848 |
</varlistentry> |
| 1849 |
<varlistentry> |
| 1850 |
<term><literal>ldaptls</literal></term> |
| 1851 |
<listitem> |
| 1852 |
<para> |
| 1853 |
Set to 1 to make the connection between PostgreSQL and the LDAP server |
| 1854 |
use TLS encryption. This uses the <literal>StartTLS</literal> |
| 1855 |
operation per <ulink url="https://datatracker.ietf.org/doc/html/rfc4513">RFC 4513</ulink>. |
| 1856 |
See also the <literal>ldapscheme</literal> option for an alternative. |
| 1857 |
</para> |
| 1858 |
</listitem> |
| 1859 |
</varlistentry> |
| 1860 |
</variablelist> |
| 1861 |
</para> |
| 1862 |
|
| 1863 |
<para> |
| 1864 |
Note that using <literal>ldapscheme</literal> or |
| 1865 |
<literal>ldaptls</literal> only encrypts the traffic between the |
| 1866 |
PostgreSQL server and the LDAP server. The connection between the |
| 1867 |
PostgreSQL server and the PostgreSQL client will still be unencrypted |
| 1868 |
unless SSL is used there as well. |
| 1869 |
</para> |
| 1870 |
|
| 1871 |
<para> |
| 1872 |
The following options are used in simple bind mode only: |
| 1873 |
<variablelist> |
| 1874 |
<varlistentry> |
| 1875 |
<term><literal>ldapprefix</literal></term> |
| 1876 |
<listitem> |
| 1877 |
<para> |
| 1878 |
String to prepend to the user name when forming the DN to bind as, |
| 1879 |
when doing simple bind authentication. |
| 1880 |
</para> |
| 1881 |
</listitem> |
| 1882 |
</varlistentry> |
| 1883 |
<varlistentry> |
| 1884 |
<term><literal>ldapsuffix</literal></term> |
| 1885 |
<listitem> |
| 1886 |
<para> |
| 1887 |
String to append to the user name when forming the DN to bind as, |
| 1888 |
when doing simple bind authentication. |
| 1889 |
</para> |
| 1890 |
</listitem> |
| 1891 |
</varlistentry> |
| 1892 |
</variablelist> |
| 1893 |
</para> |
| 1894 |
|
| 1895 |
<para> |
| 1896 |
The following options are used in search+bind mode only: |
| 1897 |
<variablelist> |
| 1898 |
<varlistentry> |
| 1899 |
<term><literal>ldapbasedn</literal></term> |
| 1900 |
<listitem> |
| 1901 |
<para> |
| 1902 |
Root DN to begin the search for the user in, when doing search+bind |
| 1903 |
authentication. |
| 1904 |
</para> |
| 1905 |
</listitem> |
| 1906 |
</varlistentry> |
| 1907 |
<varlistentry> |
| 1908 |
<term><literal>ldapbinddn</literal></term> |
| 1909 |
<listitem> |
| 1910 |
<para> |
| 1911 |
DN of user to bind to the directory with to perform the search when |
| 1912 |
doing search+bind authentication. |
| 1913 |
</para> |
| 1914 |
</listitem> |
| 1915 |
</varlistentry> |
| 1916 |
<varlistentry> |
| 1917 |
<term><literal>ldapbindpasswd</literal></term> |
| 1918 |
<listitem> |
| 1919 |
<para> |
| 1920 |
Password for user to bind to the directory with to perform the search |
| 1921 |
when doing search+bind authentication. |
| 1922 |
</para> |
| 1923 |
</listitem> |
| 1924 |
</varlistentry> |
| 1925 |
<varlistentry> |
| 1926 |
<term><literal>ldapsearchattribute</literal></term> |
| 1927 |
<listitem> |
| 1928 |
<para> |
| 1929 |
Attribute to match against the user name in the search when doing |
| 1930 |
search+bind authentication. If no attribute is specified, the |
| 1931 |
<literal>uid</literal> attribute will be used. |
| 1932 |
</para> |
| 1933 |
</listitem> |
| 1934 |
</varlistentry> |
| 1935 |
<varlistentry> |
| 1936 |
<term><literal>ldapsearchfilter</literal></term> |
| 1937 |
<listitem> |
| 1938 |
<para> |
| 1939 |
The search filter to use when doing search+bind authentication. |
| 1940 |
Occurrences of <literal>$username</literal> will be replaced with the |
| 1941 |
user name. This allows for more flexible search filters than |
| 1942 |
<literal>ldapsearchattribute</literal>. |
| 1943 |
</para> |
| 1944 |
</listitem> |
| 1945 |
</varlistentry> |
| 1946 |
</variablelist> |
| 1947 |
</para> |
| 1948 |
|
| 1949 |
<para> |
| 1950 |
The following option may be used as an alternative way to write some of the |
| 1951 |
above LDAP options in a more compact and standard form: |
| 1952 |
<variablelist> |
| 1953 |
<varlistentry> |
| 1954 |
<term><literal>ldapurl</literal></term> |
| 1955 |
<listitem> |
| 1956 |
<para> |
| 1957 |
An <ulink url="https://datatracker.ietf.org/doc/html/rfc4516">RFC 4516</ulink> |
| 1958 |
LDAP URL. The format is |
| 1959 |
<synopsis> |
| 1960 |
ldap[s]://<replaceable>host</replaceable>[:<replaceable>port</replaceable>]/<replaceable>basedn</replaceable>[?[<replaceable>attribute</replaceable>][?[<replaceable>scope</replaceable>][?[<replaceable>filter</replaceable>]]]] |
| 1961 |
</synopsis> |
| 1962 |
<replaceable>scope</replaceable> must be one |
| 1963 |
of <literal>base</literal>, <literal>one</literal>, <literal>sub</literal>, |
| 1964 |
typically the last. (The default is <literal>base</literal>, which |
| 1965 |
is normally not useful in this application.) <replaceable>attribute</replaceable> can |
| 1966 |
nominate a single attribute, in which case it is used as a value for |
| 1967 |
<literal>ldapsearchattribute</literal>. If |
| 1968 |
<replaceable>attribute</replaceable> is empty then |
| 1969 |
<replaceable>filter</replaceable> can be used as a value for |
| 1970 |
<literal>ldapsearchfilter</literal>. |
| 1971 |
</para> |
| 1972 |
|
| 1973 |
<para> |
| 1974 |
The URL scheme <literal>ldaps</literal> chooses the LDAPS method for |
| 1975 |
making LDAP connections over SSL, equivalent to using |
| 1976 |
<literal>ldapscheme=ldaps</literal>. To use encrypted LDAP |
| 1977 |
connections using the <literal>StartTLS</literal> operation, use the |
| 1978 |
normal URL scheme <literal>ldap</literal> and specify the |
| 1979 |
<literal>ldaptls</literal> option in addition to |
| 1980 |
<literal>ldapurl</literal>. |
| 1981 |
</para> |
| 1982 |
|
| 1983 |
<para> |
| 1984 |
For non-anonymous binds, <literal>ldapbinddn</literal> |
| 1985 |
and <literal>ldapbindpasswd</literal> must be specified as separate |
| 1986 |
options. |
| 1987 |
</para> |
| 1988 |
|
| 1989 |
<para> |
| 1990 |
LDAP URLs are currently only supported with |
| 1991 |
<productname>OpenLDAP</productname>, not on Windows. |
| 1992 |
</para> |
| 1993 |
</listitem> |
| 1994 |
</varlistentry> |
| 1995 |
</variablelist> |
| 1996 |
</para> |
| 1997 |
|
| 1998 |
<para> |
| 1999 |
It is an error to mix configuration options for simple bind with options |
| 2000 |
for search+bind. To use <literal>ldapurl</literal> in simple bind mode, the |
| 2001 |
URL must not contain a <literal>basedn</literal> or query elements. |
| 2002 |
</para> |
| 2003 |
|
| 2004 |
<para> |
| 2005 |
When using search+bind mode, the search can be performed using a single |
| 2006 |
attribute specified with <literal>ldapsearchattribute</literal>, or using |
| 2007 |
a custom search filter specified with |
| 2008 |
<literal>ldapsearchfilter</literal>. |
| 2009 |
Specifying <literal>ldapsearchattribute=foo</literal> is equivalent to |
| 2010 |
specifying <literal>ldapsearchfilter="(foo=$username)"</literal>. If neither |
| 2011 |
option is specified the default is |
| 2012 |
<literal>ldapsearchattribute=uid</literal>. |
| 2013 |
</para> |
| 2014 |
|
| 2015 |
<para> |
| 2016 |
If <productname>PostgreSQL</productname> was compiled with |
| 2017 |
<productname>OpenLDAP</productname> as the LDAP client library, the |
| 2018 |
<literal>ldapserver</literal> setting may be omitted. In that case, a |
| 2019 |
list of host names and ports is looked up via |
| 2020 |
<ulink url="https://datatracker.ietf.org/doc/html/rfc2782">RFC 2782</ulink> DNS SRV records. |
| 2021 |
The name <literal>_ldap._tcp.DOMAIN</literal> is looked up, where |
| 2022 |
<literal>DOMAIN</literal> is extracted from <literal>ldapbasedn</literal>. |
| 2023 |
</para> |
| 2024 |
|
| 2025 |
<para> |
| 2026 |
Here is an example for a simple-bind LDAP configuration: |
| 2027 |
<programlisting> |
| 2028 |
host ... ldap ldapserver=ldap.example.net ldapprefix="cn=" ldapsuffix=", dc=example, dc=net" |
| 2029 |
</programlisting> |
| 2030 |
When a connection to the database server as database |
| 2031 |
user <literal>someuser</literal> is requested, PostgreSQL will attempt to |
| 2032 |
bind to the LDAP server using the DN <literal>cn=someuser, dc=example, |
| 2033 |
dc=net</literal> and the password provided by the client. If that connection |
| 2034 |
succeeds, the database access is granted. |
| 2035 |
</para> |
| 2036 |
|
| 2037 |
<para> |
| 2038 |
Here is a different simple-bind configuration, which uses the LDAPS scheme |
| 2039 |
and a custom port number, written as a URL: |
| 2040 |
<programlisting> |
| 2041 |
host ... ldap ldapurl="ldaps://ldap.example.net:49151" ldapprefix="cn=" ldapsuffix=", dc=example, dc=net" |
| 2042 |
</programlisting> |
| 2043 |
This is slightly more compact than specifying <literal>ldapserver</literal>, |
| 2044 |
<literal>ldapscheme</literal>, and <literal>ldapport</literal> separately. |
| 2045 |
</para> |
| 2046 |
|
| 2047 |
<para> |
| 2048 |
Here is an example for a search+bind configuration: |
| 2049 |
<programlisting> |
| 2050 |
host ... ldap ldapserver=ldap.example.net ldapbasedn="dc=example, dc=net" ldapsearchattribute=uid |
| 2051 |
</programlisting> |
| 2052 |
When a connection to the database server as database |
| 2053 |
user <literal>someuser</literal> is requested, PostgreSQL will attempt to |
| 2054 |
bind anonymously (since <literal>ldapbinddn</literal> was not specified) to |
| 2055 |
the LDAP server, perform a search for <literal>(uid=someuser)</literal> |
| 2056 |
under the specified base DN. If an entry is found, it will then attempt to |
| 2057 |
bind using that found information and the password supplied by the client. |
| 2058 |
If that second bind succeeds, the database access is granted. |
| 2059 |
</para> |
| 2060 |
|
| 2061 |
<para> |
| 2062 |
Here is the same search+bind configuration written as a URL: |
| 2063 |
<programlisting> |
| 2064 |
host ... ldap ldapurl="ldap://ldap.example.net/dc=example,dc=net?uid?sub" |
| 2065 |
</programlisting> |
| 2066 |
Some other software that supports authentication against LDAP uses the |
| 2067 |
same URL format, so it will be easier to share the configuration. |
| 2068 |
</para> |
| 2069 |
|
| 2070 |
<para> |
| 2071 |
Here is an example for a search+bind configuration that uses |
| 2072 |
<literal>ldapsearchfilter</literal> instead of |
| 2073 |
<literal>ldapsearchattribute</literal> to allow authentication by |
| 2074 |
user ID or email address: |
| 2075 |
<programlisting> |
| 2076 |
host ... ldap ldapserver=ldap.example.net ldapbasedn="dc=example, dc=net" ldapsearchfilter="(|(uid=$username)(mail=$username))" |
| 2077 |
</programlisting> |
| 2078 |
</para> |
| 2079 |
|
| 2080 |
<para> |
| 2081 |
Here is an example for a search+bind configuration that uses DNS SRV |
| 2082 |
discovery to find the host name(s) and port(s) for the LDAP service for the |
| 2083 |
domain name <literal>example.net</literal>: |
| 2084 |
<programlisting> |
| 2085 |
host ... ldap ldapbasedn="dc=example,dc=net" |
| 2086 |
</programlisting> |
| 2087 |
</para> |
| 2088 |
|
| 2089 |
<tip> |
| 2090 |
<para> |
| 2091 |
Since LDAP often uses commas and spaces to separate the different |
| 2092 |
parts of a DN, it is often necessary to use double-quoted parameter |
| 2093 |
values when configuring LDAP options, as shown in the examples. |
| 2094 |
</para> |
| 2095 |
</tip> |
| 2096 |
|
| 2097 |
</sect1> |
| 2098 |
|
| 2099 |
<sect1 id="auth-radius"> |
| 2100 |
<title>RADIUS Authentication</title> |
| 2101 |
|
| 2102 |
<indexterm zone="auth-radius"> |
| 2103 |
<primary>RADIUS</primary> |
| 2104 |
</indexterm> |
| 2105 |
|
| 2106 |
<para> |
| 2107 |
This authentication method operates similarly to |
| 2108 |
<literal>password</literal> except that it uses RADIUS |
| 2109 |
as the password verification method. RADIUS is used only to validate |
| 2110 |
the user name/password pairs. Therefore the user must already |
| 2111 |
exist in the database before RADIUS can be used for |
| 2112 |
authentication. |
| 2113 |
</para> |
| 2114 |
|
| 2115 |
<para> |
| 2116 |
When using RADIUS authentication, an Access Request message will be sent |
| 2117 |
to the configured RADIUS server. This request will be of type |
| 2118 |
<literal>Authenticate Only</literal>, and include parameters for |
| 2119 |
<literal>user name</literal>, <literal>password</literal> (encrypted) and |
| 2120 |
<literal>NAS Identifier</literal>. The request will be encrypted using |
| 2121 |
a secret shared with the server. The RADIUS server will respond to |
| 2122 |
this request with either <literal>Access Accept</literal> or |
| 2123 |
<literal>Access Reject</literal>. There is no support for RADIUS accounting. |
| 2124 |
</para> |
| 2125 |
|
| 2126 |
<para> |
| 2127 |
Multiple RADIUS servers can be specified, in which case they will |
| 2128 |
be tried sequentially. If a negative response is received from |
| 2129 |
a server, the authentication will fail. If no response is received, |
| 2130 |
the next server in the list will be tried. To specify multiple |
| 2131 |
servers, separate the server names with commas and surround the list |
| 2132 |
with double quotes. If multiple servers are specified, the other |
| 2133 |
RADIUS options can also be given as comma-separated lists, to provide |
| 2134 |
individual values for each server. They can also be specified as |
| 2135 |
a single value, in which case that value will apply to all servers. |
| 2136 |
</para> |
| 2137 |
|
| 2138 |
<para> |
| 2139 |
The following configuration options are supported for RADIUS: |
| 2140 |
<variablelist> |
| 2141 |
<varlistentry> |
| 2142 |
<term><literal>radiusservers</literal></term> |
| 2143 |
<listitem> |
| 2144 |
<para> |
| 2145 |
The DNS names or IP addresses of the RADIUS servers to connect to. |
| 2146 |
This parameter is required. |
| 2147 |
</para> |
| 2148 |
</listitem> |
| 2149 |
</varlistentry> |
| 2150 |
|
| 2151 |
<varlistentry> |
| 2152 |
<term><literal>radiussecrets</literal></term> |
| 2153 |
<listitem> |
| 2154 |
<para> |
| 2155 |
The shared secrets used when talking securely to the RADIUS |
| 2156 |
servers. This must have exactly the same value on the PostgreSQL |
| 2157 |
and RADIUS servers. It is recommended that this be a string of |
| 2158 |
at least 16 characters. This parameter is required. |
| 2159 |
<note> |
| 2160 |
<para> |
| 2161 |
The encryption vector used will only be cryptographically |
| 2162 |
strong if <productname>PostgreSQL</productname> is built with support for |
| 2163 |
<productname>OpenSSL</productname>. In other cases, the transmission to the |
| 2164 |
RADIUS server should only be considered obfuscated, not secured, and |
| 2165 |
external security measures should be applied if necessary. |
| 2166 |
</para> |
| 2167 |
</note> |
| 2168 |
</para> |
| 2169 |
</listitem> |
| 2170 |
</varlistentry> |
| 2171 |
|
| 2172 |
<varlistentry> |
| 2173 |
<term><literal>radiusports</literal></term> |
| 2174 |
<listitem> |
| 2175 |
<para> |
| 2176 |
The port numbers to connect to on the RADIUS servers. If no port |
| 2177 |
is specified, the default RADIUS port (<literal>1812</literal>) |
| 2178 |
will be used. |
| 2179 |
</para> |
| 2180 |
</listitem> |
| 2181 |
</varlistentry> |
| 2182 |
|
| 2183 |
<varlistentry> |
| 2184 |
<term><literal>radiusidentifiers</literal></term> |
| 2185 |
<listitem> |
| 2186 |
<para> |
| 2187 |
The strings to be used as <literal>NAS Identifier</literal> in the |
| 2188 |
RADIUS requests. This parameter can be used, for example, to |
| 2189 |
identify which database cluster the user is attempting to connect |
| 2190 |
to, which can be useful for policy matching on |
| 2191 |
the RADIUS server. If no identifier is specified, the default |
| 2192 |
<literal>postgresql</literal> will be used. |
| 2193 |
</para> |
| 2194 |
</listitem> |
| 2195 |
</varlistentry> |
| 2196 |
|
| 2197 |
</variablelist> |
| 2198 |
</para> |
| 2199 |
|
| 2200 |
<para> |
| 2201 |
If it is necessary to have a comma or whitespace in a RADIUS parameter |
| 2202 |
value, that can be done by putting double quotes around the value, but |
| 2203 |
it is tedious because two layers of double-quoting are now required. |
| 2204 |
An example of putting whitespace into RADIUS secret strings is: |
| 2205 |
<programlisting> |
| 2206 |
host ... radius radiusservers="server1,server2" radiussecrets="""secret one"",""secret two""" |
| 2207 |
</programlisting> |
| 2208 |
</para> |
| 2209 |
</sect1> |
| 2210 |
|
| 2211 |
<sect1 id="auth-cert"> |
| 2212 |
<title>Certificate Authentication</title> |
| 2213 |
|
| 2214 |
<indexterm zone="auth-cert"> |
| 2215 |
<primary>Certificate</primary> |
| 2216 |
</indexterm> |
| 2217 |
|
| 2218 |
<para> |
| 2219 |
This authentication method uses SSL client certificates to perform |
| 2220 |
authentication. It is therefore only available for SSL connections; |
| 2221 |
see <xref linkend="ssl-openssl-config"/> for SSL configuration instructions. |
| 2222 |
When using this authentication method, the server will require that |
| 2223 |
the client provide a valid, trusted certificate. No password prompt |
| 2224 |
will be sent to the client. The <literal>cn</literal> (Common Name) |
| 2225 |
attribute of the certificate |
| 2226 |
will be compared to the requested database user name, and if they match |
| 2227 |
the login will be allowed. User name mapping can be used to allow |
| 2228 |
<literal>cn</literal> to be different from the database user name. |
| 2229 |
</para> |
| 2230 |
|
| 2231 |
<para> |
| 2232 |
The following configuration options are supported for SSL certificate |
| 2233 |
authentication: |
| 2234 |
<variablelist> |
| 2235 |
<varlistentry> |
| 2236 |
<term><literal>map</literal></term> |
| 2237 |
<listitem> |
| 2238 |
<para> |
| 2239 |
Allows for mapping between system and database user names. See |
| 2240 |
<xref linkend="auth-username-maps"/> for details. |
| 2241 |
</para> |
| 2242 |
</listitem> |
| 2243 |
</varlistentry> |
| 2244 |
</variablelist> |
| 2245 |
</para> |
| 2246 |
|
| 2247 |
<para> |
| 2248 |
It is redundant to use the <literal>clientcert</literal> option with |
| 2249 |
<literal>cert</literal> authentication because <literal>cert</literal> |
| 2250 |
authentication is effectively <literal>trust</literal> authentication |
| 2251 |
with <literal>clientcert=verify-full</literal>. |
| 2252 |
</para> |
| 2253 |
</sect1> |
| 2254 |
|
| 2255 |
<sect1 id="auth-pam"> |
| 2256 |
<title>PAM Authentication</title> |
| 2257 |
|
| 2258 |
<indexterm zone="auth-pam"> |
| 2259 |
<primary>PAM</primary> |
| 2260 |
</indexterm> |
| 2261 |
|
| 2262 |
<para> |
| 2263 |
This authentication method operates similarly to |
| 2264 |
<literal>password</literal> except that it uses PAM (Pluggable |
| 2265 |
Authentication Modules) as the authentication mechanism. The |
| 2266 |
default PAM service name is <literal>postgresql</literal>. |
| 2267 |
PAM is used only to validate user name/password pairs and optionally the |
| 2268 |
connected remote host name or IP address. Therefore the user must already |
| 2269 |
exist in the database before PAM can be used for authentication. For more |
| 2270 |
information about PAM, please read the |
| 2271 |
<ulink url="https://www.kernel.org/pub/linux/libs/pam/"> |
| 2272 |
<productname>Linux-PAM</productname> Page</ulink>. |
| 2273 |
</para> |
| 2274 |
|
| 2275 |
<para> |
| 2276 |
The following configuration options are supported for PAM: |
| 2277 |
<variablelist> |
| 2278 |
<varlistentry> |
| 2279 |
<term><literal>pamservice</literal></term> |
| 2280 |
<listitem> |
| 2281 |
<para> |
| 2282 |
PAM service name. |
| 2283 |
</para> |
| 2284 |
</listitem> |
| 2285 |
</varlistentry> |
| 2286 |
<varlistentry> |
| 2287 |
<term><literal>pam_use_hostname</literal></term> |
| 2288 |
<listitem> |
| 2289 |
<para> |
| 2290 |
Determines whether the remote IP address or the host name is provided |
| 2291 |
to PAM modules through the <symbol>PAM_RHOST</symbol> item. By |
| 2292 |
default, the IP address is used. Set this option to 1 to use the |
| 2293 |
resolved host name instead. Host name resolution can lead to login |
| 2294 |
delays. (Most PAM configurations don't use this information, so it is |
| 2295 |
only necessary to consider this setting if a PAM configuration was |
| 2296 |
specifically created to make use of it.) |
| 2297 |
</para> |
| 2298 |
</listitem> |
| 2299 |
</varlistentry> |
| 2300 |
</variablelist> |
| 2301 |
</para> |
| 2302 |
|
| 2303 |
<note> |
| 2304 |
<para> |
| 2305 |
If PAM is set up to read <filename>/etc/shadow</filename>, authentication |
| 2306 |
will fail because the PostgreSQL server is started by a non-root |
| 2307 |
user. However, this is not an issue when PAM is configured to use |
| 2308 |
LDAP or other authentication methods. |
| 2309 |
</para> |
| 2310 |
</note> |
| 2311 |
</sect1> |
| 2312 |
|
| 2313 |
<sect1 id="auth-bsd"> |
| 2314 |
<title>BSD Authentication</title> |
| 2315 |
|
| 2316 |
<indexterm zone="auth-bsd"> |
| 2317 |
<primary>BSD Authentication</primary> |
| 2318 |
</indexterm> |
| 2319 |
|
| 2320 |
<para> |
| 2321 |
This authentication method operates similarly to |
| 2322 |
<literal>password</literal> except that it uses BSD Authentication |
| 2323 |
to verify the password. BSD Authentication is used only |
| 2324 |
to validate user name/password pairs. Therefore the user's role must |
| 2325 |
already exist in the database before BSD Authentication can be used |
| 2326 |
for authentication. The BSD Authentication framework is currently |
| 2327 |
only available on OpenBSD. |
| 2328 |
</para> |
| 2329 |
|
| 2330 |
<para> |
| 2331 |
BSD Authentication in <productname>PostgreSQL</productname> uses |
| 2332 |
the <literal>auth-postgresql</literal> login type and authenticates with |
| 2333 |
the <literal>postgresql</literal> login class if that's defined |
| 2334 |
in <filename>login.conf</filename>. By default that login class does not |
| 2335 |
exist, and <productname>PostgreSQL</productname> will use the default login class. |
| 2336 |
</para> |
| 2337 |
|
| 2338 |
<note> |
| 2339 |
<para> |
| 2340 |
To use BSD Authentication, the PostgreSQL user account (that is, the |
| 2341 |
operating system user running the server) must first be added to |
| 2342 |
the <literal>auth</literal> group. The <literal>auth</literal> group |
| 2343 |
exists by default on OpenBSD systems. |
| 2344 |
</para> |
| 2345 |
</note> |
| 2346 |
</sect1> |
| 2347 |
|
| 2348 |
<sect1 id="auth-oauth"> |
| 2349 |
<title>OAuth Authorization/Authentication</title> |
| 2350 |
|
| 2351 |
<indexterm zone="auth-oauth"> |
| 2352 |
<primary>OAuth Authorization/Authentication</primary> |
| 2353 |
</indexterm> |
| 2354 |
|
| 2355 |
<para> |
| 2356 |
OAuth 2.0 is an industry-standard framework, defined in |
| 2357 |
<ulink url="https://datatracker.ietf.org/doc/html/rfc6749">RFC 6749</ulink>, |
| 2358 |
to enable third-party applications to obtain limited access to a protected |
| 2359 |
resource. |
| 2360 |
|
| 2361 |
OAuth client support has to be enabled when <productname>PostgreSQL</productname> |
| 2362 |
is built, see <xref linkend="installation"/> for more information. |
| 2363 |
</para> |
| 2364 |
|
| 2365 |
<para> |
| 2366 |
This documentation uses the following terminology when discussing the OAuth |
| 2367 |
ecosystem: |
| 2368 |
|
| 2369 |
<variablelist> |
| 2370 |
|
| 2371 |
<varlistentry> |
| 2372 |
<term>Resource Owner (or End User)</term> |
| 2373 |
<listitem> |
| 2374 |
<para> |
| 2375 |
The user or system who owns protected resources and can grant access to |
| 2376 |
them. This documentation also uses the term <emphasis>end user</emphasis> |
| 2377 |
when the resource owner is a person. When you use |
| 2378 |
<application>psql</application> to connect to the database using OAuth, |
| 2379 |
you are the resource owner/end user. |
| 2380 |
</para> |
| 2381 |
</listitem> |
| 2382 |
</varlistentry> |
| 2383 |
|
| 2384 |
<varlistentry> |
| 2385 |
<term>Client</term> |
| 2386 |
<listitem> |
| 2387 |
<para> |
| 2388 |
The system which accesses the protected resources using access |
| 2389 |
tokens. Applications using libpq, such as <application>psql</application>, |
| 2390 |
are the OAuth clients when connecting to a |
| 2391 |
<productname>PostgreSQL</productname> cluster. |
| 2392 |
</para> |
| 2393 |
</listitem> |
| 2394 |
</varlistentry> |
| 2395 |
|
| 2396 |
<varlistentry> |
| 2397 |
<term>Resource Server</term> |
| 2398 |
<listitem> |
| 2399 |
<para> |
| 2400 |
The system hosting the protected resources which are |
| 2401 |
accessed by the client. The <productname>PostgreSQL</productname> |
| 2402 |
cluster being connected to is the resource server. |
| 2403 |
</para> |
| 2404 |
</listitem> |
| 2405 |
</varlistentry> |
| 2406 |
|
| 2407 |
<varlistentry> |
| 2408 |
<term>Provider</term> |
| 2409 |
<listitem> |
| 2410 |
<para> |
| 2411 |
The organization, product vendor, or other entity which develops and/or |
| 2412 |
administers the OAuth authorization servers and clients for a given application. |
| 2413 |
Different providers typically choose different implementation details |
| 2414 |
for their OAuth systems; a client of one provider is not generally |
| 2415 |
guaranteed to have access to the servers of another. |
| 2416 |
</para> |
| 2417 |
<para> |
| 2418 |
This use of the term "provider" is not standard, but it seems to be in |
| 2419 |
wide use colloquially. (It should not be confused with OpenID's similar |
| 2420 |
term "Identity Provider". While the implementation of OAuth in |
| 2421 |
<productname>PostgreSQL</productname> is intended to be interoperable |
| 2422 |
and compatible with OpenID Connect/OIDC, it is not itself an OIDC client |
| 2423 |
and does not require its use.) |
| 2424 |
</para> |
| 2425 |
</listitem> |
| 2426 |
</varlistentry> |
| 2427 |
|
| 2428 |
<varlistentry> |
| 2429 |
<term>Authorization Server</term> |
| 2430 |
<listitem> |
| 2431 |
<para> |
| 2432 |
The system which receives requests from, and issues access tokens to, |
| 2433 |
the client after the authenticated resource owner has given approval. |
| 2434 |
<productname>PostgreSQL</productname> does not provide an authorization |
| 2435 |
server; it is the responsibility of the OAuth provider. |
| 2436 |
</para> |
| 2437 |
</listitem> |
| 2438 |
</varlistentry> |
| 2439 |
|
| 2440 |
<varlistentry> |
| 2441 |
<term id="auth-oauth-issuer">Issuer</term> |
| 2442 |
<listitem> |
| 2443 |
<para> |
| 2444 |
An identifier for an authorization server, printed as an |
| 2445 |
<literal>https://</literal> URL, which provides a trusted "namespace" |
| 2446 |
for OAuth clients and applications. The issuer identifier allows a |
| 2447 |
single authorization server to talk to the clients of mutually |
| 2448 |
untrusting entities, as long as they maintain separate issuers. |
| 2449 |
</para> |
| 2450 |
</listitem> |
| 2451 |
</varlistentry> |
| 2452 |
|
| 2453 |
</variablelist> |
| 2454 |
|
| 2455 |
<note> |
| 2456 |
<para> |
| 2457 |
For small deployments, there may not be a meaningful distinction between |
| 2458 |
the "provider", "authorization server", and "issuer". However, for more |
| 2459 |
complicated setups, there may be a one-to-many (or many-to-many) |
| 2460 |
relationship: a provider may rent out multiple issuer identifiers to |
| 2461 |
separate tenants, then provide multiple authorization servers, possibly |
| 2462 |
with different supported feature sets, to interact with their clients. |
| 2463 |
</para> |
| 2464 |
</note> |
| 2465 |
</para> |
| 2466 |
|
| 2467 |
<para> |
| 2468 |
<productname>PostgreSQL</productname> supports bearer tokens, defined in |
| 2469 |
<ulink url="https://datatracker.ietf.org/doc/html/rfc6750">RFC 6750</ulink>, |
| 2470 |
which are a type of access token used with OAuth 2.0 where the token is an |
| 2471 |
opaque string. The format of the access token is implementation specific |
| 2472 |
and is chosen by each authorization server. |
| 2473 |
</para> |
| 2474 |
|
| 2475 |
<para> |
| 2476 |
The following configuration options are supported for OAuth: |
| 2477 |
<variablelist> |
| 2478 |
<varlistentry> |
| 2479 |
<term><literal>issuer</literal></term> |
| 2480 |
<listitem> |
| 2481 |
<para> |
| 2482 |
An HTTPS URL which is either the exact |
| 2483 |
<link linkend="auth-oauth-issuer">issuer identifier</link> of the |
| 2484 |
authorization server, as defined by its discovery document, or a |
| 2485 |
well-known URI that points directly to that discovery document. This |
| 2486 |
parameter is required. |
| 2487 |
</para> |
| 2488 |
<para> |
| 2489 |
When an OAuth client connects to the server, a URL for the discovery |
| 2490 |
document will be constructed using the issuer identifier. By default, |
| 2491 |
this URL uses the conventions of OpenID Connect Discovery: the path |
| 2492 |
<literal>/.well-known/openid-configuration</literal> will be appended |
| 2493 |
to the end of the issuer identifier. Alternatively, if the |
| 2494 |
<literal>issuer</literal> contains a <literal>/.well-known/</literal> |
| 2495 |
path segment, that URL will be provided to the client as-is. |
| 2496 |
</para> |
| 2497 |
<warning> |
| 2498 |
<para> |
| 2499 |
The OAuth client in libpq requires the server's issuer setting to |
| 2500 |
exactly match the issuer identifier which is provided in the discovery |
| 2501 |
document, which must in turn match the client's |
| 2502 |
<xref linkend="libpq-connect-oauth-issuer"/> setting. No variations in |
| 2503 |
case or formatting are permitted. |
| 2504 |
</para> |
| 2505 |
</warning> |
| 2506 |
</listitem> |
| 2507 |
</varlistentry> |
| 2508 |
|
| 2509 |
<varlistentry> |
| 2510 |
<term><literal>scope</literal></term> |
| 2511 |
<listitem> |
| 2512 |
<para> |
| 2513 |
A space-separated list of the OAuth scopes needed for the server to |
| 2514 |
both authorize the client and authenticate the user. Appropriate values |
| 2515 |
are determined by the authorization server and the OAuth validation |
| 2516 |
module used (see <xref linkend="oauth-validators" /> for more |
| 2517 |
information on validators). This parameter is required. |
| 2518 |
</para> |
| 2519 |
</listitem> |
| 2520 |
</varlistentry> |
| 2521 |
|
| 2522 |
<varlistentry> |
| 2523 |
<term><literal>validator</literal></term> |
| 2524 |
<listitem> |
| 2525 |
<para> |
| 2526 |
The library to use for validating bearer tokens. If given, the name must |
| 2527 |
exactly match one of the libraries listed in |
| 2528 |
<xref linkend="guc-oauth-validator-libraries" />. This parameter is |
| 2529 |
optional unless <literal>oauth_validator_libraries</literal> contains |
| 2530 |
more than one library, in which case it is required. |
| 2531 |
</para> |
| 2532 |
</listitem> |
| 2533 |
</varlistentry> |
| 2534 |
|
| 2535 |
<varlistentry> |
| 2536 |
<term><literal>map</literal></term> |
| 2537 |
<listitem> |
| 2538 |
<para> |
| 2539 |
Allows for mapping between OAuth identity provider and database user |
| 2540 |
names. See <xref linkend="auth-username-maps"/> for details. If a |
| 2541 |
map is not specified, the user name associated with the token (as |
| 2542 |
determined by the OAuth validator) must exactly match the role name |
| 2543 |
being requested. This parameter is optional. |
| 2544 |
</para> |
| 2545 |
</listitem> |
| 2546 |
</varlistentry> |
| 2547 |
|
| 2548 |
<varlistentry> |
| 2549 |
<term id="auth-oauth-delegate-ident-mapping" xreflabel="delegate_ident_mapping"> |
| 2550 |
<literal>delegate_ident_mapping</literal> |
| 2551 |
</term> |
| 2552 |
<listitem> |
| 2553 |
<para> |
| 2554 |
An advanced option which is not intended for common use. |
| 2555 |
</para> |
| 2556 |
<para> |
| 2557 |
When set to <literal>1</literal>, standard user mapping with |
| 2558 |
<filename>pg_ident.conf</filename> is skipped, and the OAuth validator |
| 2559 |
takes full responsibility for mapping end user identities to database |
| 2560 |
roles. If the validator authorizes the token, the server trusts that |
| 2561 |
the user is allowed to connect under the requested role, and the |
| 2562 |
connection is allowed to proceed regardless of the authentication |
| 2563 |
status of the user. |
| 2564 |
</para> |
| 2565 |
<para> |
| 2566 |
This parameter is incompatible with <literal>map</literal>. |
| 2567 |
</para> |
| 2568 |
<warning> |
| 2569 |
<para> |
| 2570 |
<literal>delegate_ident_mapping</literal> provides additional |
| 2571 |
flexibility in the design of the authentication system, but it also |
| 2572 |
requires careful implementation of the OAuth validator, which must |
| 2573 |
determine whether the provided token carries sufficient end-user |
| 2574 |
privileges in addition to the <link linkend="oauth-validators">standard |
| 2575 |
checks</link> required of all validators. Use with caution. |
| 2576 |
</para> |
| 2577 |
</warning> |
| 2578 |
</listitem> |
| 2579 |
</varlistentry> |
| 2580 |
</variablelist> |
| 2581 |
</para> |
| 2582 |
</sect1> |
| 2583 |
|
| 2584 |
<sect1 id="client-authentication-problems"> |
| 2585 |
<title>Authentication Problems</title> |
| 2586 |
|
| 2587 |
<para> |
| 2588 |
Authentication failures and related problems generally |
| 2589 |
manifest themselves through error messages like the following: |
| 2590 |
</para> |
| 2591 |
|
| 2592 |
<para> |
| 2593 |
<programlisting> |
| 2594 |
FATAL: no pg_hba.conf entry for host "123.123.123.123", user "andym", database "testdb" |
| 2595 |
</programlisting> |
| 2596 |
This is what you are most likely to get if you succeed in contacting |
| 2597 |
the server, but it does not want to talk to you. As the message |
| 2598 |
suggests, the server refused the connection request because it found |
| 2599 |
no matching entry in its <filename>pg_hba.conf</filename> |
| 2600 |
configuration file. |
| 2601 |
</para> |
| 2602 |
|
| 2603 |
<para> |
| 2604 |
<programlisting> |
| 2605 |
FATAL: password authentication failed for user "andym" |
| 2606 |
</programlisting> |
| 2607 |
Messages like this indicate that you contacted the server, and it is |
| 2608 |
willing to talk to you, but not until you pass the authorization |
| 2609 |
method specified in the <filename>pg_hba.conf</filename> file. Check |
| 2610 |
the password you are providing, or check your Kerberos or ident |
| 2611 |
software if the complaint mentions one of those authentication |
| 2612 |
types. |
| 2613 |
</para> |
| 2614 |
|
| 2615 |
<para> |
| 2616 |
<programlisting> |
| 2617 |
FATAL: user "andym" does not exist |
| 2618 |
</programlisting> |
| 2619 |
The indicated database user name was not found. |
| 2620 |
</para> |
| 2621 |
|
| 2622 |
<para> |
| 2623 |
<programlisting> |
| 2624 |
FATAL: database "testdb" does not exist |
| 2625 |
</programlisting> |
| 2626 |
The database you are trying to connect to does not exist. Note that |
| 2627 |
if you do not specify a database name, it defaults to the database |
| 2628 |
user name. |
| 2629 |
</para> |
| 2630 |
|
| 2631 |
<tip> |
| 2632 |
<para> |
| 2633 |
The server log might contain more information about an |
| 2634 |
authentication failure than is reported to the client. If you are |
| 2635 |
confused about the reason for a failure, check the server log. |
| 2636 |
</para> |
| 2637 |
</tip> |
| 2638 |
</sect1> |
| 2639 |
|
| 2640 |
</chapter> |