gooderp18绿色标准版
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

471 rinda
36KB

  1. <?xml version="1.0" encoding="UTF-8" standalone="no"?>
  2. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /><title>20.1. The pg_hba.conf File</title><link rel="stylesheet" type="text/css" href="stylesheet.css" /><link rev="made" href="pgsql-docs@lists.postgresql.org" /><meta name="generator" content="DocBook XSL Stylesheets V1.79.1" /><link rel="prev" href="client-authentication.html" title="Chapter 20. Client Authentication" /><link rel="next" href="auth-username-maps.html" title="20.2. User Name Maps" /></head><body><div xmlns="http://www.w3.org/TR/xhtml1/transitional" class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="5" align="center">20.1. The <code xmlns="http://www.w3.org/1999/xhtml" class="filename">pg_hba.conf</code> File</th></tr><tr><td width="10%" align="left"><a accesskey="p" href="client-authentication.html" title="Chapter 20. Client Authentication">Prev</a> </td><td width="10%" align="left"><a accesskey="u" href="client-authentication.html" title="Chapter 20. Client Authentication">Up</a></td><th width="60%" align="center">Chapter 20. Client Authentication</th><td width="10%" align="right"><a accesskey="h" href="index.html" title="PostgreSQL 12.4 Documentation">Home</a></td><td width="10%" align="right"> <a accesskey="n" href="auth-username-maps.html" title="20.2. User Name Maps">Next</a></td></tr></table><hr></hr></div><div class="sect1" id="AUTH-PG-HBA-CONF"><div class="titlepage"><div><div><h2 class="title" style="clear: both">20.1. The <code class="filename">pg_hba.conf</code> File</h2></div></div></div><a id="id-1.6.7.8.2" class="indexterm"></a><p>
  3. Client authentication is controlled by a configuration file,
  4. which traditionally is named
  5. <code class="filename">pg_hba.conf</code> and is stored in the database
  6. cluster's data directory.
  7. (<acronym class="acronym">HBA</acronym> stands for host-based authentication.) A default
  8. <code class="filename">pg_hba.conf</code> file is installed when the data
  9. directory is initialized by <code class="command">initdb</code>. It is
  10. possible to place the authentication configuration file elsewhere,
  11. however; see the <a class="xref" href="runtime-config-file-locations.html#GUC-HBA-FILE">hba_file</a> configuration parameter.
  12. </p><p>
  13. The general format of the <code class="filename">pg_hba.conf</code> file is
  14. a set of records, one per line. Blank lines are ignored, as is any
  15. text after the <code class="literal">#</code> comment character.
  16. Records cannot be continued across lines.
  17. A record is made
  18. up of a number of fields which are separated by spaces and/or tabs.
  19. Fields can contain white space if the field value is double-quoted.
  20. Quoting one of the keywords in a database, user, or address field (e.g.,
  21. <code class="literal">all</code> or <code class="literal">replication</code>) makes the word lose its special
  22. meaning, and just match a database, user, or host with that name.
  23. </p><p>
  24. Each record specifies a connection type, a client IP address range
  25. (if relevant for the connection type), a database name, a user name,
  26. and the authentication method to be used for connections matching
  27. these parameters. The first record with a matching connection type,
  28. client address, requested database, and user name is used to perform
  29. authentication. There is no <span class="quote">“<span class="quote">fall-through</span>”</span> or
  30. <span class="quote">“<span class="quote">backup</span>”</span>: if one record is chosen and the authentication
  31. fails, subsequent records are not considered. If no record matches,
  32. access is denied.
  33. </p><p>
  34. A record can have several formats:
  35. </p><pre class="synopsis">
  36. local <em class="replaceable"><code>database</code></em> <em class="replaceable"><code>user</code></em> <em class="replaceable"><code>auth-method</code></em> [<span class="optional"><em class="replaceable"><code>auth-options</code></em></span>]
  37. host <em class="replaceable"><code>database</code></em> <em class="replaceable"><code>user</code></em> <em class="replaceable"><code>address</code></em> <em class="replaceable"><code>auth-method</code></em> [<span class="optional"><em class="replaceable"><code>auth-options</code></em></span>]
  38. hostssl <em class="replaceable"><code>database</code></em> <em class="replaceable"><code>user</code></em> <em class="replaceable"><code>address</code></em> <em class="replaceable"><code>auth-method</code></em> [<span class="optional"><em class="replaceable"><code>auth-options</code></em></span>]
  39. hostnossl <em class="replaceable"><code>database</code></em> <em class="replaceable"><code>user</code></em> <em class="replaceable"><code>address</code></em> <em class="replaceable"><code>auth-method</code></em> [<span class="optional"><em class="replaceable"><code>auth-options</code></em></span>]
  40. hostgssenc <em class="replaceable"><code>database</code></em> <em class="replaceable"><code>user</code></em> <em class="replaceable"><code>address</code></em> <em class="replaceable"><code>auth-method</code></em> [<span class="optional"><em class="replaceable"><code>auth-options</code></em></span>]
  41. hostnogssenc <em class="replaceable"><code>database</code></em> <em class="replaceable"><code>user</code></em> <em class="replaceable"><code>address</code></em> <em class="replaceable"><code>auth-method</code></em> [<span class="optional"><em class="replaceable"><code>auth-options</code></em></span>]
  42. host <em class="replaceable"><code>database</code></em> <em class="replaceable"><code>user</code></em> <em class="replaceable"><code>IP-address</code></em> <em class="replaceable"><code>IP-mask</code></em> <em class="replaceable"><code>auth-method</code></em> [<span class="optional"><em class="replaceable"><code>auth-options</code></em></span>]
  43. hostssl <em class="replaceable"><code>database</code></em> <em class="replaceable"><code>user</code></em> <em class="replaceable"><code>IP-address</code></em> <em class="replaceable"><code>IP-mask</code></em> <em class="replaceable"><code>auth-method</code></em> [<span class="optional"><em class="replaceable"><code>auth-options</code></em></span>]
  44. hostnossl <em class="replaceable"><code>database</code></em> <em class="replaceable"><code>user</code></em> <em class="replaceable"><code>IP-address</code></em> <em class="replaceable"><code>IP-mask</code></em> <em class="replaceable"><code>auth-method</code></em> [<span class="optional"><em class="replaceable"><code>auth-options</code></em></span>]
  45. hostgssenc <em class="replaceable"><code>database</code></em> <em class="replaceable"><code>user</code></em> <em class="replaceable"><code>IP-address</code></em> <em class="replaceable"><code>IP-mask</code></em> <em class="replaceable"><code>auth-method</code></em> [<span class="optional"><em class="replaceable"><code>auth-options</code></em></span>]
  46. hostnogssenc <em class="replaceable"><code>database</code></em> <em class="replaceable"><code>user</code></em> <em class="replaceable"><code>IP-address</code></em> <em class="replaceable"><code>IP-mask</code></em> <em class="replaceable"><code>auth-method</code></em> [<span class="optional"><em class="replaceable"><code>auth-options</code></em></span>]
  47. </pre><p>
  48. The meaning of the fields is as follows:
  49. </p><div class="variablelist"><dl class="variablelist"><dt><span class="term"><code class="literal">local</code></span></dt><dd><p>
  50. This record matches connection attempts using Unix-domain
  51. sockets. Without a record of this type, Unix-domain socket
  52. connections are disallowed.
  53. </p></dd><dt><span class="term"><code class="literal">host</code></span></dt><dd><p>
  54. This record matches connection attempts made using TCP/IP.
  55. <code class="literal">host</code> records match
  56. <acronym class="acronym">SSL</acronym> or non-<acronym class="acronym">SSL</acronym> connection
  57. attempts as well as <acronym class="acronym">GSSAPI</acronym> encrypted or
  58. non-<acronym class="acronym">GSSAPI</acronym> encrypted connection attempts.
  59. </p><div class="note"><h3 class="title">Note</h3><p>
  60. Remote TCP/IP connections will not be possible unless
  61. the server is started with an appropriate value for the
  62. <a class="xref" href="runtime-config-connection.html#GUC-LISTEN-ADDRESSES">listen_addresses</a> configuration parameter,
  63. since the default behavior is to listen for TCP/IP connections
  64. only on the local loopback address <code class="literal">localhost</code>.
  65. </p></div></dd><dt><span class="term"><code class="literal">hostssl</code></span></dt><dd><p>
  66. This record matches connection attempts made using TCP/IP,
  67. but only when the connection is made with <acronym class="acronym">SSL</acronym>
  68. encryption.
  69. </p><p>
  70. To make use of this option the server must be built with
  71. <acronym class="acronym">SSL</acronym> support. Furthermore,
  72. <acronym class="acronym">SSL</acronym> must be enabled
  73. by setting the <a class="xref" href="runtime-config-connection.html#GUC-SSL">ssl</a> configuration parameter (see
  74. <a class="xref" href="ssl-tcp.html" title="18.9. Secure TCP/IP Connections with SSL">Section 18.9</a> for more information).
  75. Otherwise, the <code class="literal">hostssl</code> record is ignored except for
  76. logging a warning that it cannot match any connections.
  77. </p></dd><dt><span class="term"><code class="literal">hostnossl</code></span></dt><dd><p>
  78. This record type has the opposite behavior of <code class="literal">hostssl</code>;
  79. it only matches connection attempts made over
  80. TCP/IP that do not use <acronym class="acronym">SSL</acronym>.
  81. </p></dd><dt><span class="term"><code class="literal">hostgssenc</code></span></dt><dd><p>
  82. This record matches connection attempts made using TCP/IP,
  83. but only when the connection is made with <acronym class="acronym">GSSAPI</acronym>
  84. encryption.
  85. </p><p>
  86. To make use of this option the server must be built with
  87. <acronym class="acronym">GSSAPI</acronym> support. Otherwise,
  88. the <code class="literal">hostgssenc</code> record is ignored except for logging
  89. a warning that it cannot match any connections.
  90. </p><p>
  91. Note that the only supported
  92. <a class="link" href="auth-methods.html" title="20.3. Authentication Methods">authentication methods</a> for use
  93. with <acronym class="acronym">GSSAPI</acronym> encryption
  94. are <code class="literal">gss</code>, <code class="literal">reject</code>,
  95. and <code class="literal">trust</code>.
  96. </p></dd><dt><span class="term"><code class="literal">hostnogssenc</code></span></dt><dd><p>
  97. This record type has the opposite behavior of <code class="literal">hostgssenc</code>;
  98. it only matches connection attempts made over
  99. TCP/IP that do not use <acronym class="acronym">GSSAPI</acronym> encryption.
  100. </p></dd><dt><span class="term"><em class="replaceable"><code>database</code></em></span></dt><dd><p>
  101. Specifies which database name(s) this record matches. The value
  102. <code class="literal">all</code> specifies that it matches all databases.
  103. The value <code class="literal">sameuser</code> specifies that the record
  104. matches if the requested database has the same name as the
  105. requested user. The value <code class="literal">samerole</code> specifies that
  106. the requested user must be a member of the role with the same
  107. name as the requested database. (<code class="literal">samegroup</code> is an
  108. obsolete but still accepted spelling of <code class="literal">samerole</code>.)
  109. Superusers are not considered to be members of a role for the
  110. purposes of <code class="literal">samerole</code> unless they are explicitly
  111. members of the role, directly or indirectly, and not just by
  112. virtue of being a superuser.
  113. The value <code class="literal">replication</code> specifies that the record
  114. matches if a physical replication connection is requested (note that
  115. replication connections do not specify any particular database).
  116. Otherwise, this is the name of
  117. a specific <span class="productname">PostgreSQL</span> database.
  118. Multiple database names can be supplied by separating them with
  119. commas. A separate file containing database names can be specified by
  120. preceding the file name with <code class="literal">@</code>.
  121. </p></dd><dt><span class="term"><em class="replaceable"><code>user</code></em></span></dt><dd><p>
  122. Specifies which database user name(s) this record
  123. matches. The value <code class="literal">all</code> specifies that it
  124. matches all users. Otherwise, this is either the name of a specific
  125. database user, or a group name preceded by <code class="literal">+</code>.
  126. (Recall that there is no real distinction between users and groups
  127. in <span class="productname">PostgreSQL</span>; a <code class="literal">+</code> mark really means
  128. <span class="quote">“<span class="quote">match any of the roles that are directly or indirectly members
  129. of this role</span>”</span>, while a name without a <code class="literal">+</code> mark matches
  130. only that specific role.) For this purpose, a superuser is only
  131. considered to be a member of a role if they are explicitly a member
  132. of the role, directly or indirectly, and not just by virtue of
  133. being a superuser.
  134. Multiple user names can be supplied by separating them with commas.
  135. A separate file containing user names can be specified by preceding the
  136. file name with <code class="literal">@</code>.
  137. </p></dd><dt><span class="term"><em class="replaceable"><code>address</code></em></span></dt><dd><p>
  138. Specifies the client machine address(es) that this record
  139. matches. This field can contain either a host name, an IP
  140. address range, or one of the special key words mentioned below.
  141. </p><p>
  142. An IP address range is specified using standard numeric notation
  143. for the range's starting address, then a slash (<code class="literal">/</code>)
  144. and a <acronym class="acronym">CIDR</acronym> mask length. The mask
  145. length indicates the number of high-order bits of the client
  146. IP address that must match. Bits to the right of this should
  147. be zero in the given IP address.
  148. There must not be any white space between the IP address, the
  149. <code class="literal">/</code>, and the CIDR mask length.
  150. </p><p>
  151. Typical examples of an IPv4 address range specified this way are
  152. <code class="literal">172.20.143.89/32</code> for a single host, or
  153. <code class="literal">172.20.143.0/24</code> for a small network, or
  154. <code class="literal">10.6.0.0/16</code> for a larger one.
  155. An IPv6 address range might look like <code class="literal">::1/128</code>
  156. for a single host (in this case the IPv6 loopback address) or
  157. <code class="literal">fe80::7a31:c1ff:0000:0000/96</code> for a small
  158. network.
  159. <code class="literal">0.0.0.0/0</code> represents all
  160. IPv4 addresses, and <code class="literal">::0/0</code> represents
  161. all IPv6 addresses.
  162. To specify a single host, use a mask length of 32 for IPv4 or
  163. 128 for IPv6. In a network address, do not omit trailing zeroes.
  164. </p><p>
  165. An entry given in IPv4 format will match only IPv4 connections,
  166. and an entry given in IPv6 format will match only IPv6 connections,
  167. even if the represented address is in the IPv4-in-IPv6 range.
  168. Note that entries in IPv6 format will be rejected if the system's
  169. C library does not have support for IPv6 addresses.
  170. </p><p>
  171. You can also write <code class="literal">all</code> to match any IP address,
  172. <code class="literal">samehost</code> to match any of the server's own IP
  173. addresses, or <code class="literal">samenet</code> to match any address in any
  174. subnet that the server is directly connected to.
  175. </p><p>
  176. If a host name is specified (anything that is not an IP address
  177. range or a special key word is treated as a host name),
  178. that name is compared with the result of a reverse name
  179. resolution of the client's IP address (e.g., reverse DNS
  180. lookup, if DNS is used). Host name comparisons are case
  181. insensitive. If there is a match, then a forward name
  182. resolution (e.g., forward DNS lookup) is performed on the host
  183. name to check whether any of the addresses it resolves to are
  184. equal to the client's IP address. If both directions match,
  185. then the entry is considered to match. (The host name that is
  186. used in <code class="filename">pg_hba.conf</code> should be the one that
  187. address-to-name resolution of the client's IP address returns,
  188. otherwise the line won't be matched. Some host name databases
  189. allow associating an IP address with multiple host names, but
  190. the operating system will only return one host name when asked
  191. to resolve an IP address.)
  192. </p><p>
  193. A host name specification that starts with a dot
  194. (<code class="literal">.</code>) matches a suffix of the actual host
  195. name. So <code class="literal">.example.com</code> would match
  196. <code class="literal">foo.example.com</code> (but not just
  197. <code class="literal">example.com</code>).
  198. </p><p>
  199. When host names are specified
  200. in <code class="filename">pg_hba.conf</code>, you should make sure that
  201. name resolution is reasonably fast. It can be of advantage to
  202. set up a local name resolution cache such
  203. as <code class="command">nscd</code>. Also, you may wish to enable the
  204. configuration parameter <code class="varname">log_hostname</code> to see
  205. the client's host name instead of the IP address in the log.
  206. </p><p>
  207. These fields do not apply to <code class="literal">local</code> records.
  208. </p><div class="note"><h3 class="title">Note</h3><p>
  209. Users sometimes wonder why host names are handled
  210. in this seemingly complicated way, with two name resolutions
  211. including a reverse lookup of the client's IP address. This
  212. complicates use of the feature in case the client's reverse DNS
  213. entry is not set up or yields some undesirable host name.
  214. It is done primarily for efficiency: this way, a connection attempt
  215. requires at most two resolver lookups, one reverse and one forward.
  216. If there is a resolver problem with some address, it becomes only
  217. that client's problem. A hypothetical alternative
  218. implementation that only did forward lookups would have to
  219. resolve every host name mentioned in
  220. <code class="filename">pg_hba.conf</code> during every connection attempt.
  221. That could be quite slow if many names are listed.
  222. And if there is a resolver problem with one of the host names,
  223. it becomes everyone's problem.
  224. </p><p>
  225. Also, a reverse lookup is necessary to implement the suffix
  226. matching feature, because the actual client host name needs to
  227. be known in order to match it against the pattern.
  228. </p><p>
  229. Note that this behavior is consistent with other popular
  230. implementations of host name-based access control, such as the
  231. Apache HTTP Server and TCP Wrappers.
  232. </p></div></dd><dt><span class="term"><em class="replaceable"><code>IP-address</code></em><br /></span><span class="term"><em class="replaceable"><code>IP-mask</code></em></span></dt><dd><p>
  233. These two fields can be used as an alternative to the
  234. <em class="replaceable"><code>IP-address</code></em><code class="literal">/</code><em class="replaceable"><code>mask-length</code></em>
  235. notation. Instead of
  236. specifying the mask length, the actual mask is specified in a
  237. separate column. For example, <code class="literal">255.0.0.0</code> represents an IPv4
  238. CIDR mask length of 8, and <code class="literal">255.255.255.255</code> represents a
  239. CIDR mask length of 32.
  240. </p><p>
  241. These fields do not apply to <code class="literal">local</code> records.
  242. </p></dd><dt><span class="term"><em class="replaceable"><code>auth-method</code></em></span></dt><dd><p>
  243. Specifies the authentication method to use when a connection matches
  244. this record. The possible choices are summarized here; details
  245. are in <a class="xref" href="auth-methods.html" title="20.3. Authentication Methods">Section 20.3</a>.
  246. </p><div class="variablelist"><dl class="variablelist"><dt><span class="term"><code class="literal">trust</code></span></dt><dd><p>
  247. Allow the connection unconditionally. This method
  248. allows anyone that can connect to the
  249. <span class="productname">PostgreSQL</span> database server to login as
  250. any <span class="productname">PostgreSQL</span> user they wish,
  251. without the need for a password or any other authentication. See <a class="xref" href="auth-trust.html" title="20.4. Trust Authentication">Section 20.4</a> for details.
  252. </p></dd><dt><span class="term"><code class="literal">reject</code></span></dt><dd><p>
  253. Reject the connection unconditionally. This is useful for
  254. <span class="quote">“<span class="quote">filtering out</span>”</span> certain hosts from a group, for example a
  255. <code class="literal">reject</code> line could block a specific host from connecting,
  256. while a later line allows the remaining hosts in a specific
  257. network to connect.
  258. </p></dd><dt><span class="term"><code class="literal">scram-sha-256</code></span></dt><dd><p>
  259. Perform SCRAM-SHA-256 authentication to verify the user's
  260. password. See <a class="xref" href="auth-password.html" title="20.5. Password Authentication">Section 20.5</a> for details.
  261. </p></dd><dt><span class="term"><code class="literal">md5</code></span></dt><dd><p>
  262. Perform SCRAM-SHA-256 or MD5 authentication to verify the
  263. user's password. See <a class="xref" href="auth-password.html" title="20.5. Password Authentication">Section 20.5</a>
  264. for details.
  265. </p></dd><dt><span class="term"><code class="literal">password</code></span></dt><dd><p>
  266. Require the client to supply an unencrypted password for
  267. authentication.
  268. Since the password is sent in clear text over the
  269. network, this should not be used on untrusted networks.
  270. See <a class="xref" href="auth-password.html" title="20.5. Password Authentication">Section 20.5</a> for details.
  271. </p></dd><dt><span class="term"><code class="literal">gss</code></span></dt><dd><p>
  272. Use GSSAPI to authenticate the user. This is only
  273. available for TCP/IP connections. See <a class="xref" href="gssapi-auth.html" title="20.6. GSSAPI Authentication">Section 20.6</a> for details. It can be used in conjunction
  274. with GSSAPI encryption.
  275. </p></dd><dt><span class="term"><code class="literal">sspi</code></span></dt><dd><p>
  276. Use SSPI to authenticate the user. This is only
  277. available on Windows. See <a class="xref" href="sspi-auth.html" title="20.7. SSPI Authentication">Section 20.7</a> for details.
  278. </p></dd><dt><span class="term"><code class="literal">ident</code></span></dt><dd><p>
  279. Obtain the operating system user name of the client
  280. by contacting the ident server on the client
  281. and check if it matches the requested database user name.
  282. Ident authentication can only be used on TCP/IP
  283. connections. When specified for local connections, peer
  284. authentication will be used instead.
  285. See <a class="xref" href="auth-ident.html" title="20.8. Ident Authentication">Section 20.8</a> for details.
  286. </p></dd><dt><span class="term"><code class="literal">peer</code></span></dt><dd><p>
  287. Obtain the client's operating system user name from the operating
  288. system and check if it matches the requested database user name.
  289. This is only available for local connections.
  290. See <a class="xref" href="auth-peer.html" title="20.9. Peer Authentication">Section 20.9</a> for details.
  291. </p></dd><dt><span class="term"><code class="literal">ldap</code></span></dt><dd><p>
  292. Authenticate using an <acronym class="acronym">LDAP</acronym> server. See <a class="xref" href="auth-ldap.html" title="20.10. LDAP Authentication">Section 20.10</a> for details.
  293. </p></dd><dt><span class="term"><code class="literal">radius</code></span></dt><dd><p>
  294. Authenticate using a RADIUS server. See <a class="xref" href="auth-radius.html" title="20.11. RADIUS Authentication">Section 20.11</a> for details.
  295. </p></dd><dt><span class="term"><code class="literal">cert</code></span></dt><dd><p>
  296. Authenticate using SSL client certificates. See
  297. <a class="xref" href="auth-cert.html" title="20.12. Certificate Authentication">Section 20.12</a> for details.
  298. </p></dd><dt><span class="term"><code class="literal">pam</code></span></dt><dd><p>
  299. Authenticate using the Pluggable Authentication Modules
  300. (PAM) service provided by the operating system. See <a class="xref" href="auth-pam.html" title="20.13. PAM Authentication">Section 20.13</a> for details.
  301. </p></dd><dt><span class="term"><code class="literal">bsd</code></span></dt><dd><p>
  302. Authenticate using the BSD Authentication service provided by the
  303. operating system. See <a class="xref" href="auth-bsd.html" title="20.14. BSD Authentication">Section 20.14</a> for details.
  304. </p></dd></dl></div><p>
  305. </p></dd><dt><span class="term"><em class="replaceable"><code>auth-options</code></em></span></dt><dd><p>
  306. After the <em class="replaceable"><code>auth-method</code></em> field, there can be field(s) of
  307. the form <em class="replaceable"><code>name</code></em><code class="literal">=</code><em class="replaceable"><code>value</code></em> that
  308. specify options for the authentication method. Details about which
  309. options are available for which authentication methods appear below.
  310. </p><p>
  311. In addition to the method-specific options listed below, there is one
  312. method-independent authentication option <code class="literal">clientcert</code>, which
  313. can be specified in any <code class="literal">hostssl</code> record.
  314. This option can be set to <code class="literal">verify-ca</code> or
  315. <code class="literal">verify-full</code>. Both options require the client
  316. to present a valid (trusted) SSL certificate, while
  317. <code class="literal">verify-full</code> additionally enforces that the
  318. <code class="literal">cn</code> (Common Name) in the certificate matches
  319. the username or an applicable mapping.
  320. This behavior is similar to the <code class="literal">cert</code> authentication
  321. method (see <a class="xref" href="auth-cert.html" title="20.12. Certificate Authentication">Section 20.12</a>) but enables pairing
  322. the verification of client certificates with any authentication
  323. method that supports <code class="literal">hostssl</code> entries.
  324. </p></dd></dl></div><p>
  325. </p><p>
  326. Files included by <code class="literal">@</code> constructs are read as lists of names,
  327. which can be separated by either whitespace or commas. Comments are
  328. introduced by <code class="literal">#</code>, just as in
  329. <code class="filename">pg_hba.conf</code>, and nested <code class="literal">@</code> constructs are
  330. allowed. Unless the file name following <code class="literal">@</code> is an absolute
  331. path, it is taken to be relative to the directory containing the
  332. referencing file.
  333. </p><p>
  334. Since the <code class="filename">pg_hba.conf</code> records are examined
  335. sequentially for each connection attempt, the order of the records is
  336. significant. Typically, earlier records will have tight connection
  337. match parameters and weaker authentication methods, while later
  338. records will have looser match parameters and stronger authentication
  339. methods. For example, one might wish to use <code class="literal">trust</code>
  340. authentication for local TCP/IP connections but require a password for
  341. remote TCP/IP connections. In this case a record specifying
  342. <code class="literal">trust</code> authentication for connections from 127.0.0.1 would
  343. appear before a record specifying password authentication for a wider
  344. range of allowed client IP addresses.
  345. </p><p>
  346. The <code class="filename">pg_hba.conf</code> file is read on start-up and when
  347. the main server process receives a
  348. <span class="systemitem">SIGHUP</span><a id="id-1.6.7.8.9.3" class="indexterm"></a>
  349. signal. If you edit the file on an
  350. active system, you will need to signal the postmaster
  351. (using <code class="literal">pg_ctl reload</code>, calling the SQL function
  352. <code class="function">pg_reload_conf()</code>, or using <code class="literal">kill
  353. -HUP</code>) to make it re-read the file.
  354. </p><div class="note"><h3 class="title">Note</h3><p>
  355. The preceding statement is not true on Microsoft Windows: there, any
  356. changes in the <code class="filename">pg_hba.conf</code> file are immediately
  357. applied by subsequent new connections.
  358. </p></div><p>
  359. The system view
  360. <a class="link" href="view-pg-hba-file-rules.html" title="51.72. pg_hba_file_rules"><code class="structname">pg_hba_file_rules</code></a>
  361. can be helpful for pre-testing changes to the <code class="filename">pg_hba.conf</code>
  362. file, or for diagnosing problems if loading of the file did not have the
  363. desired effects. Rows in the view with
  364. non-null <code class="structfield">error</code> fields indicate problems in the
  365. corresponding lines of the file.
  366. </p><div class="tip"><h3 class="title">Tip</h3><p>
  367. To connect to a particular database, a user must not only pass the
  368. <code class="filename">pg_hba.conf</code> checks, but must have the
  369. <code class="literal">CONNECT</code> privilege for the database. If you wish to
  370. restrict which users can connect to which databases, it's usually
  371. easier to control this by granting/revoking <code class="literal">CONNECT</code> privilege
  372. than to put the rules in <code class="filename">pg_hba.conf</code> entries.
  373. </p></div><p>
  374. Some examples of <code class="filename">pg_hba.conf</code> entries are shown in
  375. <a class="xref" href="auth-pg-hba-conf.html#EXAMPLE-PG-HBA.CONF" title="Example 20.1. Example pg_hba.conf Entries">Example 20.1</a>. See the next section for details on the
  376. different authentication methods.
  377. </p><div class="example" id="EXAMPLE-PG-HBA.CONF"><p class="title"><strong>Example 20.1. Example <code class="filename">pg_hba.conf</code> Entries</strong></p><div class="example-contents"><pre class="programlisting">
  378. # Allow any user on the local system to connect to any database with
  379. # any database user name using Unix-domain sockets (the default for local
  380. # connections).
  381. #
  382. # TYPE DATABASE USER ADDRESS METHOD
  383. local all all trust
  384. # The same using local loopback TCP/IP connections.
  385. #
  386. # TYPE DATABASE USER ADDRESS METHOD
  387. host all all 127.0.0.1/32 trust
  388. # The same as the previous line, but using a separate netmask column
  389. #
  390. # TYPE DATABASE USER IP-ADDRESS IP-MASK METHOD
  391. host all all 127.0.0.1 255.255.255.255 trust
  392. # The same over IPv6.
  393. #
  394. # TYPE DATABASE USER ADDRESS METHOD
  395. host all all ::1/128 trust
  396. # The same using a host name (would typically cover both IPv4 and IPv6).
  397. #
  398. # TYPE DATABASE USER ADDRESS METHOD
  399. host all all localhost trust
  400. # Allow any user from any host with IP address 192.168.93.x to connect
  401. # to database "postgres" as the same user name that ident reports for
  402. # the connection (typically the operating system user name).
  403. #
  404. # TYPE DATABASE USER ADDRESS METHOD
  405. host postgres all 192.168.93.0/24 ident
  406. # Allow any user from host 192.168.12.10 to connect to database
  407. # "postgres" if the user's password is correctly supplied.
  408. #
  409. # TYPE DATABASE USER ADDRESS METHOD
  410. host postgres all 192.168.12.10/32 scram-sha-256
  411. # Allow any user from hosts in the example.com domain to connect to
  412. # any database if the user's password is correctly supplied.
  413. #
  414. # Require SCRAM authentication for most users, but make an exception
  415. # for user 'mike', who uses an older client that doesn't support SCRAM
  416. # authentication.
  417. #
  418. # TYPE DATABASE USER ADDRESS METHOD
  419. host all mike .example.com md5
  420. host all all .example.com scram-sha-256
  421. # In the absence of preceding "host" lines, these three lines will
  422. # reject all connections from 192.168.54.1 (since that entry will be
  423. # matched first), but allow GSSAPI-encrypted connections from anywhere else
  424. # on the Internet. The zero mask causes no bits of the host IP address to
  425. # be considered, so it matches any host. Unencrypted GSSAPI connections
  426. # (which "fall through" to the third line since "hostgssenc" only matches
  427. # encrypted GSSAPI connections) are allowed, but only from 192.168.12.10.
  428. #
  429. # TYPE DATABASE USER ADDRESS METHOD
  430. host all all 192.168.54.1/32 reject
  431. hostgssenc all all 0.0.0.0/0 gss
  432. host all all 192.168.12.10/32 gss
  433. # Allow users from 192.168.x.x hosts to connect to any database, if
  434. # they pass the ident check. If, for example, ident says the user is
  435. # "bryanh" and he requests to connect as PostgreSQL user "guest1", the
  436. # connection is allowed if there is an entry in pg_ident.conf for map
  437. # "omicron" that says "bryanh" is allowed to connect as "guest1".
  438. #
  439. # TYPE DATABASE USER ADDRESS METHOD
  440. host all all 192.168.0.0/16 ident map=omicron
  441. # If these are the only three lines for local connections, they will
  442. # allow local users to connect only to their own databases (databases
  443. # with the same name as their database user name) except for administrators
  444. # and members of role "support", who can connect to all databases. The file
  445. # $PGDATA/admins contains a list of names of administrators. Passwords
  446. # are required in all cases.
  447. #
  448. # TYPE DATABASE USER ADDRESS METHOD
  449. local sameuser all md5
  450. local all @admins md5
  451. local all +support md5
  452. # The last two lines above can be combined into a single line:
  453. local all @admins,+support md5
  454. # The database column can also use lists and file names:
  455. local db1,db2,@demodbs all md5
  456. </pre></div></div><br class="example-break" /></div><div class="navfooter"><hr /><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="client-authentication.html">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="client-authentication.html">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="auth-username-maps.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">Chapter 20. Client Authentication </td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top"> 20.2. User Name Maps</td></tr></table></div></body></html>
上海开阖软件有限公司 沪ICP备12045867号-1