バージョンごとのドキュメント一覧

21.1. pg_hba.confファイル #

<title>The <filename>pg_hba.conf</filename> File</title>

Client authentication is controlled by a configuration file, which traditionally is named <filename>pg_hba.conf</filename> and is stored in the database cluster's data directory. (<acronym>HBA</acronym> stands for host-based authentication.) A default <filename>pg_hba.conf</filename> file is installed when the data directory is initialized by <xref linkend="app-initdb"/>. It is possible to place the authentication configuration file elsewhere, however; see the <xref linkend="guc-hba-file"/> configuration parameter. クライアント認証はデータベースクラスタのデータディレクトリ内の、伝統的にpg_hba.confという名前の設定ファイルで管理されています (HBAとは、host-based authentication: ホストベース認証の略です)。 デフォルトのpg_hba.confファイルは、データディレクトリがinitdbで初期化される時にインストールされます。 しかし、この認証設定ファイルを他の場所に設置することができます。 hba_file設定パラメータを参照してください。

The general format of the <filename>pg_hba.conf</filename> file is a set of records, one per line. Blank lines are ignored, as is any text after the <literal>#</literal> comment character. A record can be continued onto the next line by ending the line with a backslash. (Backslashes are not special except at the end of a line.) A record is made up of a number of fields which are separated by spaces and/or tabs. Fields can contain white space if the field value is double-quoted. Quoting one of the keywords in a database, user, or address field (e.g., <literal>all</literal> or <literal>replication</literal>) makes the word lose its special meaning, and just match a database, user, or host with that name. Backslash line continuation applies even within quoted text or comments. pg_hba.confファイルの一般的な書式は、1行につき1つのレコードというレコードの集合です。 空行はコメント用の#文字以降の文字と同じく無視されます。 行の最後をバックスラッシュで終えることによりレコードを次の行に継続できます。(行の最後を除き、バックスラッシュは特別扱いされません。) レコードはスペースもしくはタブ、もしくはその両方で区切られた、複数のフィールドで構成されています。 フィールドには、フィールド値が二重引用符付きの場合空白文字を含むことができます。 データベース、ユーザもしくはアドレスフィールド内のキーワード(例:allまたはreplication)の一つを引用するとその特別な意味が失われ、その名称のデータベース、ユーザもしくはホストと一致するようになります。 引用テキストあるいはコメントもバックスラッシュで行を継続できます。

Each authentication record specifies a connection type, a client IP address range (if relevant for the connection type), a database name, a user name, and the authentication method to be used for connections matching these parameters. The first record with a matching connection type, client address, requested database, and user name is used to perform authentication. There is no <quote>fall-through</quote> or <quote>backup</quote>: if one record is chosen and the authentication fails, subsequent records are not considered. If no record matches, access is denied. それぞれの認証レコードは接続形式、(接続形式に対して意味を持つのであれば)クライアントのIPアドレス範囲、データベースの名前、ユーザ名およびこれらのパラメータに一致する接続で使用される認証方法を指定します。 接続形式、クライアントアドレス、要求されたデータベース、およびユーザ名に一致する最初のレコードが認証処理に使用されます。 失敗時の継続や、 あるいはバックアップはありません。 これは、もしあるレコードが選択されて認証に失敗した場合、後続のレコードは考慮されないということです。 どのレコードも一致しない時はアクセスが拒否されます。

Each record can be an include directive or an authentication record. Include directives specify files that can be included, that contain additional records. The records will be inserted in place of the include directives. Include directives only contain two fields: <literal>include</literal>, <literal>include_if_exists</literal> or <literal>include_dir</literal> directive and the file or directory to be included. The file or directory can be a relative or absolute path, and can be double-quoted. For the <literal>include_dir</literal> form, all files not starting with a <literal>.</literal> and ending with <literal>.conf</literal> will be included. Multiple files within an include directory are processed in file name order (according to C locale rules, i.e., numbers before letters, and uppercase letters before lowercase ones). 各レコードは、includeディレクティブまたは認証レコードにできます。 includeディレクティブは、追加レコードを含むインクルード可能なファイルを指定します。 レコードは、includeディレクティブの代わりに挿入されます。 includeディレクティブには以下の2つのフィールドのみが含まれます。includeinclude_if_existsまたはinclude_dirディレクティブと、インクルードするファイルまたはディレクトリです。 ファイルまたはディレクトリは、相対または絶対パスにでき、二重引用符で囲むことができます。 include_dir形式の場合、.で始まらず.confで終わるすべてのファイルがインクルードされます。 インクルードディレクトリ内の複数のファイルは、ファイル名の順(Cロケールの規則に従って、すなわち、文字より先に数字、小文字より先に大文字)に処理されます。

A record can have several formats: レコードはいくつかの形式があります。

local               database  user  auth-method [auth-options]
host                database  user  address     auth-method  [auth-options]
hostssl             database  user  address     auth-method  [auth-options]
hostnossl           database  user  address     auth-method  [auth-options]
hostgssenc          database  user  address     auth-method  [auth-options]
hostnogssenc        database  user  address     auth-method  [auth-options]
host                database  user  IP-address  IP-mask      auth-method  [auth-options]
hostssl             database  user  IP-address  IP-mask      auth-method  [auth-options]
hostnossl           database  user  IP-address  IP-mask      auth-method  [auth-options]
hostgssenc          database  user  IP-address  IP-mask      auth-method  [auth-options]
hostnogssenc        database  user  IP-address  IP-mask      auth-method  [auth-options]
include             file
include_if_exists   file
include_dir         directory

The meaning of the fields is as follows: フィールドの意味は以下のようになっています。

local

This record matches connection attempts using Unix-domain sockets. Without a record of this type, Unix-domain socket connections are disallowed. このレコードはUnixドメインソケットを使用する接続に対応します。 この種類のレコードを使用しないと、Unixドメインソケット経由の接続は拒否されます。

host

This record matches connection attempts made using TCP/IP. <literal>host</literal> records match <acronym>SSL</acronym> or non-<acronym>SSL</acronym> connection attempts as well as <acronym>GSSAPI</acronym> encrypted or non-<acronym>GSSAPI</acronym> encrypted connection attempts. このレコードは、TCP/IPを使用した接続に対応します。 hostレコードは、SSLまたは非SSL接続、GSSAPI暗号化、非GSSAPI暗号化のいずれかに対応します。

注記

Remote TCP/IP connections will not be possible unless the server is started with an appropriate value for the <xref linkend="guc-listen-addresses"/> configuration parameter, since the default behavior is to listen for TCP/IP connections only on the local loopback address <literal>localhost</literal>. サーバのデフォルトの動作は、ローカルループバックアドレスであるlocalhostのみTCP/IP接続を監視しています。 よってサーバにおいてlisten_addressesパラメータが適切な値に設定された状態で起動されていない限り、リモートのTCP/IP接続はできません。

hostssl

This record matches connection attempts made using TCP/IP, but only when the connection is made with <acronym>SSL</acronym> encryption. このレコードは、接続がSSLで暗号化されている場合にのみTCP/IPネットワークを使用する接続に対応します。

To make use of this option the server must be built with <acronym>SSL</acronym> support. Furthermore, <acronym>SSL</acronym> must be enabled by setting the <xref linkend="guc-ssl"/> configuration parameter (see <xref linkend="ssl-tcp"/> for more information). Otherwise, the <literal>hostssl</literal> record is ignored except for logging a warning that it cannot match any connections. このオプションを使用するためには、サーバはSSLサポートができるように構築されていなければいけません。 また、 SSLsslパラメータを設定することによりサーバの起動時に有効になっていなくてはなりません(詳細は19.9を参照してください)。 そうでなければ、どのような接続にも対応していないという警告が表示されることを除き、hostsslレコードは無視されます。

hostnossl

This record type has the opposite behavior of <literal>hostssl</literal>; it only matches connection attempts made over TCP/IP that do not use <acronym>SSL</acronym>. このレコードは、hostsslと反対の動作で、SSLを使用していないTCP/IPの接続のみに対応します。

hostgssenc

This record matches connection attempts made using TCP/IP, but only when the connection is made with <acronym>GSSAPI</acronym> encryption. このレコードは、TCP/IPを使用した接続に対応しますが、GSSAPI暗号化を使用して接続が行われた場合に限ります。

To make use of this option the server must be built with <acronym>GSSAPI</acronym> support. Otherwise, the <literal>hostgssenc</literal> record is ignored except for logging a warning that it cannot match any connections. このオプションを使用するためには、サーバはGSSAPIサポートができるように構築されていなければいけません。 そうでなければ、どのような接続にも対応していないという警告が表示されることを除き、hostgssencレコードは無視されます。

hostnogssenc

This record type has the opposite behavior of <literal>hostgssenc</literal>; it only matches connection attempts made over TCP/IP that do not use <acronym>GSSAPI</acronym> encryption. このレコードは、hostgssencとは反対の動作で、GSSAPI暗号化を使用していないTCP/IPの接続のみに対応します。

database

Specifies which database name(s) this record matches. The value <literal>all</literal> specifies that it matches all databases. The value <literal>sameuser</literal> specifies that the record matches if the requested database has the same name as the requested user. The value <literal>samerole</literal> specifies that the requested user must be a member of the role with the same name as the requested database. (<literal>samegroup</literal> is an obsolete but still accepted spelling of <literal>samerole</literal>.) Superusers are not considered to be members of a role for the purposes of <literal>samerole</literal> unless they are explicitly members of the role, directly or indirectly, and not just by virtue of being a superuser. The value <literal>replication</literal> specifies that the record matches if a physical replication connection is requested, however, it doesn't match with logical replication connections. Note that physical replication connections do not specify any particular database whereas logical replication connections do specify it. Otherwise, this is the name of a specific <productname>PostgreSQL</productname> database or a regular expression. Multiple database names and/or regular expressions can be supplied by separating them with commas. このレコードで対応するデータベース名を指定します。 all という値は、全てのデータベースと対応することを指定します。 sameuserという値は、要求されたデータベースが要求ユーザと同じ名前を持つ場合にレコードが対応することを指定します。 sameroleという値は、要求ユーザが要求されたデータベースと同じ名前のロールのメンバでなければならないことを指定します。 (以前はsamegroupと書いていましたが、sameroleと記述してください) スーパーユーザは、直接的であれ間接的であれ、明示的にsameroleのメンバでない限りsameroleのメンバとはみなされません。 また、スーパーユーザであるからといってsameroleのメンバとはみなされません。 replicationという値は、もし物理レプリケーション接続が要求された場合にレコードが一致することを指定します。 しかし、論理レプリケーションによる接続には一致しません。 物理レプリケーション接続は特定のデータベースを指定しないのに対し、論理レプリケーション接続は特定のデータベースを指定することに注意してください。 それ以外の場合には、特定のPostgreSQLデータベースの名前または正規表現になります。 データベースの名前や正規表現はカンマで区切ることで複数指定できます。

If the database name starts with a slash (<literal>/</literal>), the remainder of the name is treated as a regular expression. (See <xref linkend="posix-syntax-details"/> for details of <productname>PostgreSQL</productname>'s regular expression syntax.) データベース名がスラッシュ(/)で始まる場合、名前の残りの部分は正規表現として扱われます。 (PostgreSQLの正規表現構文の詳細については、9.7.3.1を参照してください。)

A separate file containing database names and/or regular expressions can be specified by preceding the file name with <literal>@</literal>. データベース名や正規表現を含む別のファイルを、そのファイル名の前に@を付けることで指定できます。

user

Specifies which database user name(s) this record matches. The value <literal>all</literal> specifies that it matches all users. Otherwise, this is either the name of a specific database user, a regular expression (when starting with a slash (<literal>/</literal>), or a group name preceded by <literal>+</literal>. (Recall that there is no real distinction between users and groups in <productname>PostgreSQL</productname>; a <literal>+</literal> mark really means <quote>match any of the roles that are directly or indirectly members of this role</quote>, while a name without a <literal>+</literal> mark matches only that specific role.) For this purpose, a superuser is only considered to be a member of a role if they are explicitly a member of the role, directly or indirectly, and not just by virtue of being a superuser. Multiple user names and/or regular expressions can be supplied by separating them with commas. このレコードで対応するデータベースユーザ名を指定します。 allという値は、全てのユーザが対応することを指定します。 それ以外の場合には特定のデータベースユーザの名前、(スラッシュ(/)で始まる場合には)正規表現、もしくは+で始まるグループ名のいずれかになります。 (PostgreSQLではユーザとグループの明確な区別がないことを思い出してください。 +のマークは実のところ、このロールの直接的もしくは間接的なメンバのどちらかに一致していることを意味しています。 一方、+のマークがない名前はその特定のロールにのみ一致します。) このため、スーパーユーザは、直接的であれ間接的であれ明示的にロールのメンバである場合にのみ、ロールのメンバとみなされます。 スーパーユーザであるからといってロールのメンバとはみなされません。 ユーザ名や正規表現は、カンマで区切ることで複数指定できます。

If the user name starts with a slash (<literal>/</literal>), the remainder of the name is treated as a regular expression. (See <xref linkend="posix-syntax-details"/> for details of <productname>PostgreSQL</productname>'s regular expression syntax.) ユーザ名がスラッシュ(/)で始まる場合、名前の残りの部分は正規表現として扱われます。 (PostgreSQLの正規表現構文の詳細については、9.7.3.1を参照してください。)

A separate file containing user names and/or regular expressions can be specified by preceding the file name with <literal>@</literal>. ユーザ名や正規表現を含む別のファイルを、そのファイル名の前に@を付けることで指定できます。

address

Specifies the client machine address(es) that this record matches. This field can contain either a host name, an IP address range, or one of the special key words mentioned below. このレコードに対応しているクライアントマシンのアドレス。 このフィールドはホスト名、IPアドレスの範囲、もしくは下記の特別なキーワードの1つを含んでいます。

An IP address range is specified using standard numeric notation for the range's starting address, then a slash (<literal>/</literal>) and a <acronym>CIDR</acronym> mask length. The mask length indicates the number of high-order bits of the client IP address that must match. Bits to the right of this should be zero in the given IP address. There must not be any white space between the IP address, the <literal>/</literal>, and the CIDR mask length. IPアドレスの範囲は、範囲の開始アドレス、続いてスラッシュ(/)とCIDRマスクの長さという標準の数値表記で指定されます。 CIDRマスク長とは、クライアントIPアドレスが一致しなければならない、高位のビット数を表すものです。 指定するIPアドレスのこれより右側のビットには、0を指定しなければなりません。 IPアドレスと/、およびCIDRマスク長の間に空白を入れてはいけません。

Typical examples of an IPv4 address range specified this way are <literal>172.20.143.89/32</literal> for a single host, or <literal>172.20.143.0/24</literal> for a small network, or <literal>10.6.0.0/16</literal> for a larger one. An IPv6 address range might look like <literal>::1/128</literal> for a single host (in this case the IPv6 loopback address) or <literal>fe80::7a31:c1ff:0000:0000/96</literal> for a small network. <literal>0.0.0.0/0</literal> represents all IPv4 addresses, and <literal>::0/0</literal> represents all IPv6 addresses. To specify a single host, use a mask length of 32 for IPv4 or 128 for IPv6. In a network address, do not omit trailing zeroes. 典型的なIPv4アドレス範囲の例は、単一のホストでは172.20.143.89/32、小規模ネットワークでは172.20.143.0/24、大規模ネットワークでは10.6.0.0/16のようなものです。 IPv6アドレスの範囲は、単一のホストでは::1/128(この場合はIPv6ループバックアドレス)、小規模ネットワークではfe80::7a31:c1ff:0000:0000/96のようなものです。 0.0.0.0/0は全てのIPv4アドレスを意味します。また、::0/0は全てのIPv6アドレスを意味しています。 単一ホストを指定するには、IPv4では32、IPv6では128というマスク長を使用してください。 ネットワークアドレスでは末尾の0を省略できません。

An entry given in IPv4 format will match only IPv4 connections, and an entry given in IPv6 format will match only IPv6 connections, even if the represented address is in the IPv4-in-IPv6 range. IPv4書式で与えられたエントリは、IPv4接続のみに対応し、IPv6書式で与えられた項目は、たとえそのアドレスがIPv6内のIPv4の範囲内であったとしてもIPv6接続のみに対応します。

You can also write <literal>all</literal> to match any IP address, <literal>samehost</literal> to match any of the server's own IP addresses, or <literal>samenet</literal> to match any address in any subnet that the server is directly connected to. どのIPアドレスにも一致するようにallと書くこともできますし、 サーバ自身のIPアドレスのいずれかにも一致するようにsamehostと書くこともできます。 もしくは、サーバが直接接続されているサブネット内のアドレスのいずれかにも一致するようにsamenetと書くことができます。

If a host name is specified (anything that is not an IP address range or a special key word is treated as a host name), that name is compared with the result of a reverse name resolution of the client's IP address (e.g., reverse DNS lookup, if DNS is used). Host name comparisons are case insensitive. If there is a match, then a forward name resolution (e.g., forward DNS lookup) is performed on the host name to check whether any of the addresses it resolves to are equal to the client's IP address. If both directions match, then the entry is considered to match. (The host name that is used in <filename>pg_hba.conf</filename> should be the one that address-to-name resolution of the client's IP address returns, otherwise the line won't be matched. Some host name databases allow associating an IP address with multiple host names, but the operating system will only return one host name when asked to resolve an IP address.) もし、ホスト名(IPアドレスの範囲ではない場合の全て、もしくはホスト名として処理される特別なキーワード)が指定されている場合は、その名前は、クライアントのIPアドレスの逆引き名前解決の結果と比較されます(例えば、もしDNSが使用されている場合は逆引きDNS検索により解決されます)。 ホスト名の比較は、大文字小文字が区別されません。 もし一致するものがあった場合は、解決された、どのアドレスもクライアントのIPアドレスと等しいか否かをチェックするために(例えば、正引きDNS検索のような)ホスト名の正引き名前解決が実行されます。 もし正引き、逆引きの両方で一致した場合は、エントリは一致するものとみなされます。 (pg_hba.conf内で使用されているホスト名は、クライアントのIPアドレスのアドレス-名前解決が返すホスト名の1つでなければいけません。 もしそうでなければこの行は一致しません。 1つのIPアドレスを複数のホスト名に関連付けるホスト名データベースもありますが、IPアドレスの解決を要求された場合にオペレーティングシステムは1つのホスト名のみを返します。)

A host name specification that starts with a dot (<literal>.</literal>) matches a suffix of the actual host name. So <literal>.example.com</literal> would match <literal>foo.example.com</literal> (but not just <literal>example.com</literal>). ドット(.)で始まるホスト名の特定は実際のホスト名のサフィックスに一致します。 よって、.example.comは、foo.example.comに一致します (example.comだけでは一致しません)。

When host names are specified in <filename>pg_hba.conf</filename>, you should make sure that name resolution is reasonably fast. It can be of advantage to set up a local name resolution cache such as <command>nscd</command>. Also, you may wish to enable the configuration parameter <varname>log_hostname</varname> to see the client's host name instead of the IP address in the log. ホスト名がpg_hba.conf内で指定されている場合、名前解決が適度に早いことを 確かめてください。 nscdのようなローカル名前解決のキャッシュを設定すると便利です。 また、クライアントのIPアドレスの代わりにホスト名がログで見られるように、log_hostnameの 設定パラメータを有効化することもできます。

These fields do not apply to <literal>local</literal> records. これらのフィールドはlocalレコードに適用されません。

注記

Users sometimes wonder why host names are handled in this seemingly complicated way, with two name resolutions including a reverse lookup of the client's IP address. This complicates use of the feature in case the client's reverse DNS entry is not set up or yields some undesirable host name. It is done primarily for efficiency: this way, a connection attempt requires at most two resolver lookups, one reverse and one forward. If there is a resolver problem with some address, it becomes only that client's problem. A hypothetical alternative implementation that only did forward lookups would have to resolve every host name mentioned in <filename>pg_hba.conf</filename> during every connection attempt. That could be quite slow if many names are listed. And if there is a resolver problem with one of the host names, it becomes everyone's problem. 時折、ユーザは、クライアントのIPアドレスの逆引きを含む2つの名前解決が必要になる、というような一見複雑に見える方法でなぜホスト名が扱われるのか不思議に思うことがあります。 このため、クライアントの逆引きDNSエントリが設定されていなかったり、いくつかの望ましくないホスト名を生成する場合にこの機能の使用が複雑になります。 これは主に効率のために行われます。このように、接続要求では最大2つのリゾルバの検索、1つは逆引き、1つは正引き、が必要になります。 もしリゾルバにおいて、アドレスに問題があった場合、クライアントのみの問題となります。 正引き検索のみを行うような実装を仮に行っていると、全ての接続要求においてpg_hba.conf内に記載された全てのホスト名を解決しなくてはいけなくなります。 これは、多くの名前が列挙されていた場合にかなり遅くなります。 また、リゾルバにおいて1つのホスト名に問題があった場合、全員の問題となってしまいます。

Also, a reverse lookup is necessary to implement the suffix matching feature, because the actual client host name needs to be known in order to match it against the pattern. さらに、逆引き検索はサフィックス一致の機能を実装するために必要です。というのも実際のクライアントのホスト名は ホスト名がパターンに対して一致するために、知られる必要があるためです。

Note that this behavior is consistent with other popular implementations of host name-based access control, such as the Apache HTTP Server and TCP Wrappers. このふるまいは、Apache HTTPサーバやTCPラッパーのような他のよくあるホスト名ベースのアクセス制御の実装と 一致していることに注意してください。

IP-address
IP-mask

These two fields can be used as an alternative to the <replaceable>IP-address</replaceable><literal>/</literal><replaceable>mask-length</replaceable> notation. Instead of specifying the mask length, the actual mask is specified in a separate column. For example, <literal>255.0.0.0</literal> represents an IPv4 CIDR mask length of 8, and <literal>255.255.255.255</literal> represents a CIDR mask length of 32. この2つのフィールドはIP-address/mask-length表記の代替として使用可能です。 マスク長を指定する代わりに、実際のマスクを分離した列で指定します。 例えば255.0.0.0はIPv4のCIDRマスク長8を意味し、255.255.255.255はCIDRマスク長32を意味しています。

These fields do not apply to <literal>local</literal> records. これらのフィールドはlocalレコードに適用されません。

auth-method

Specifies the authentication method to use when a connection matches this record. The possible choices are summarized here; details are in <xref linkend="auth-methods"/>. All the options are lower case and treated case sensitively, so even acronyms like <literal>ldap</literal> must be specified as lower case. 接続がこのレコードに一致する場合に使用する認証方式を指定します。 使用できる選択肢は以下にまとめていますが、詳しくは21.3を参照してください。 すべてのオプションは小文字で、大文字小文字の区別が認識されます。ですから、ldapのような頭文字であっても小文字で指定しなければなりません。

trust

Allow the connection unconditionally. This method allows anyone that can connect to the <productname>PostgreSQL</productname> database server to login as any <productname>PostgreSQL</productname> user they wish, without the need for a password or any other authentication. See <xref linkend="auth-trust"/> for details. 接続を無条件で許可します。 この方式は、PostgreSQLデータベースサーバに接続できる全てのユーザが、任意のPostgreSQLユーザとしてパスワードや他の認証なしでログインすることを許可します。 詳細は21.4を参照してください。

reject

Reject the connection unconditionally. This is useful for <quote>filtering out</quote> certain hosts from a group, for example a <literal>reject</literal> line could block a specific host from connecting, while a later line allows the remaining hosts in a specific network to connect. 接続を無条件に拒否します。 特定のホストをあるグループから除外するために便利です。 例えば、1行のrejectは特定のホストが接続することを拒否します。一方、 後ろの行では特定のネットワーク内の残りのホストが接続することを許可します。

scram-sha-256

Perform SCRAM-SHA-256 authentication to verify the user's password. See <xref linkend="auth-password"/> for details. ユーザのパスワードを検証するためにSCRAM-SHA-256認証を実行します。 詳細は21.5をご覧ください。

md5

Perform SCRAM-SHA-256 or MD5 authentication to verify the user's password. See <xref linkend="auth-password"/> for details. ユーザのパスワードを検証するために、SCRAM-SHA-256あるいはMD5認証を実行します。 詳細は21.5を参照してください。

password

Require the client to supply an unencrypted password for authentication. Since the password is sent in clear text over the network, this should not be used on untrusted networks. See <xref linkend="auth-password"/> for details. クライアントに対して認証時に平文のパスワードを要求します。 パスワードはネットワークを通じて普通のテキスト形式で送られますので、信頼されていないネットワークでは使用しないでください。 詳細は21.5を参照してください。

gss

Use GSSAPI to authenticate the user. This is only available for TCP/IP connections. See <xref linkend="gssapi-auth"/> for details. It can be used in conjunction with GSSAPI encryption. ユーザの認証にGSSAPIを使用します。 これはTCP/IP接続を使用するときのみ使用可能です。 詳細は21.6を参照してください。 GSSAPI暗号化と組み合わせて使用できます。

sspi

Use SSPI to authenticate the user. This is only available on Windows. See <xref linkend="sspi-auth"/> for details. ユーザの認証にSSPIを使用します。 これはWindowsを使用するときのみ使用可能です。 詳細は21.7を参照してください。

ident

Obtain the operating system user name of the client by contacting the ident server on the client and check if it matches the requested database user name. Ident authentication can only be used on TCP/IP connections. When specified for local connections, peer authentication will be used instead. See <xref linkend="auth-ident"/> for details. クライアントのオペレーティングシステムにおけるユーザ名をクライアント上のidentサーバに尋ねてユーザ名が要求されたデータベースユーザ名と一致するか検査します。 ident認証は、TCP/IP接続でのみ使用可能です。ローカル接続が指定されている場合は、peer認証が代わりに使用されます。 詳細は21.8を参照してください。

peer

Obtain the client's operating system user name from the operating system and check if it matches the requested database user name. This is only available for local connections. See <xref linkend="auth-peer"/> for details. クライアントのオペレーティングシステムにおけるユーザ名をオペレーティングシステムから取得し、ユーザ名が要求されたデータベースユーザ名と一致するか検査します。 これはローカル接続の時にのみ使用可能です。詳細は21.9を参照してください。

ldap

Authenticate using an <acronym>LDAP</acronym> server. See <xref linkend="auth-ldap"/> for details. LDAPサーバを使用して認証します。 詳細は21.10を参照してください。

radius

Authenticate using a RADIUS server. See <xref linkend="auth-radius"/> for details. RADIUSサーバを使用して認証します。 詳細は21.11を参照してください。

cert

Authenticate using SSL client certificates. See <xref linkend="auth-cert"/> for details. SSLクライアント証明書を使用して認証します。 詳細は21.12を参照してください。

pam

Authenticate using the Pluggable Authentication Modules (PAM) service provided by the operating system. See <xref linkend="auth-pam"/> for details. オペレーティングシステムによって提供されるPAM(Pluggable Authentication Modules)サービスを使用した認証です。 詳細は21.13を参照してください。

bsd

Authenticate using the BSD Authentication service provided by the operating system. See <xref linkend="auth-bsd"/> for details. オペレーティングシステムによって提供されたBSD認証サービスを使用して認証します。 詳細は21.14を参照してください。

auth-options

After the <replaceable>auth-method</replaceable> field, there can be field(s) of the form <replaceable>name</replaceable><literal>=</literal><replaceable>value</replaceable> that specify options for the authentication method. Details about which options are available for which authentication methods appear below. auth-methodフィールドの後ろに、 認証方式のオプションを指定する、name=valueの形式のフィールドが存在する可能性があります。 どのオプションがどの認証方式に使用できるのか、についての詳細は以下で説明します。

In addition to the method-specific options listed below, there is a method-independent authentication option <literal>clientcert</literal>, which can be specified in any <literal>hostssl</literal> record. This option can be set to <literal>verify-ca</literal> or <literal>verify-full</literal>. Both options require the client to present a valid (trusted) SSL certificate, while <literal>verify-full</literal> additionally enforces that the <literal>cn</literal> (Common Name) in the certificate matches the username or an applicable mapping. This behavior is similar to the <literal>cert</literal> authentication method (see <xref linkend="auth-cert"/>) but enables pairing the verification of client certificates with any authentication method that supports <literal>hostssl</literal> entries. 以下に示された方式特定のオプションに加えて、方式に依存しないのひとつの認証オプションclientcertがあり、hostsslレコードで指定できます。 このオプションは、verify-caまたはverify-fullに設定できます。 どちらのオプションも、クライアントに有効な(信頼された)SSL証明書の提出を要求し、verify fullは、証明書のcn(Common Name)がユーザー名または適用可能なマッピングと一致することをさらに強制します。 この動作はcert認証方式(詳細は21.12を参照してください)に似ていますが、クライアント証明書の検証をhostsslエントリをサポートする任意の認証方式と組み合わせることができます。

On any record using client certificate authentication (i.e. one using the <literal>cert</literal> authentication method or one using the <literal>clientcert</literal> option), you can specify which part of the client certificate credentials to match using the <literal>clientname</literal> option. This option can have one of two values. If you specify <literal>clientname=CN</literal>, which is the default, the username is matched against the certificate's <literal>Common Name (CN)</literal>. If instead you specify <literal>clientname=DN</literal> the username is matched against the entire <literal>Distinguished Name (DN)</literal> of the certificate. This option is probably best used in conjunction with a username map. The comparison is done with the <literal>DN</literal> in <ulink url="https://tools.ietf.org/html/rfc2253">RFC 2253</ulink> format. To see the <literal>DN</literal> of a client certificate in this format, do クライアント証明書認証を使用するすべてのレコード(つまり、cert認証方式あるいはclientcertオプションを使用している)では、clientnameオプションを使ってクライアント証明書資格情報のどの部分を照合するかを指定できます。 このオプションは2つの値のうち1つを持つことができます。 デフォルトであるclientname=CNを指定すると、ユーザ名は証明書のCommon Name (CN)と照合されます。 その代わりにclientname=DNを指定すると、ユーザ名は証明書のDistinguished Name (DN)全体と照合されます。 このオプションはおそらくユーザ名マップとともに使うのが最善です。 RFC 2253DNと比較されます。 この形式のクライアント証明書のDNを参照するには以下のようにしてください。

openssl x509 -in myclient.crt -noout --subject -nameopt RFC2253 | sed "s/^subject=//"

Care needs to be taken when using this option, especially when using regular expression matching against the <literal>DN</literal>. このオプションを使ってDNに対して正規表現を使った比較を行う際にはとりわけ注意が必要です。

include

This line will be replaced by the contents of the given file. この行は、指定したファイルの内容に置き換えられます。

include_if_exists

This line will be replaced by the content of the given file if the file exists. Otherwise, a message is logged to indicate that the file has been skipped. ファイルが存在する場合、この行は指定したファイルの内容に置き換えられます。 存在しない場合は、ファイルがスキップされたことを示すメッセージが記録されます。

include_dir

This line will be replaced by the contents of all the files found in the directory, if they don't start with a <literal>.</literal> and end with <literal>.conf</literal>, processed in file name order (according to C locale rules, i.e., numbers before letters, and uppercase letters before lowercase ones). ファイル名が.で始まらず、.confで終わる場合、この行は、そのディレクトリで見つかったすべてのファイルの内容に置き換えられ、ファイル名の順(Cロケールの規則に従って、すなわち、文字より先に数字、小文字より先に大文字)に処理されます。

Files included by <literal>@</literal> constructs are read as lists of names, which can be separated by either whitespace or commas. Comments are introduced by <literal>#</literal>, just as in <filename>pg_hba.conf</filename>, and nested <literal>@</literal> constructs are allowed. Unless the file name following <literal>@</literal> is an absolute path, it is taken to be relative to the directory containing the referencing file. @式により含められるファイルは、空白文字あるいはカンマのどちらかで区切られた名前の列挙として読み込まれます。 コメントは、pg_hba.confと同様に#から始まります。 また、@式を入れ子にすることもできます。 @の後のファイル名が絶対パスでない限り、参照元ファイルが存在するディレクトリから見た相対パスであるとみなされます。

Since the <filename>pg_hba.conf</filename> records are examined sequentially for each connection attempt, the order of the records is significant. Typically, earlier records will have tight connection match parameters and weaker authentication methods, while later records will have looser match parameters and stronger authentication methods. For example, one might wish to use <literal>trust</literal> authentication for local TCP/IP connections but require a password for remote TCP/IP connections. In this case a record specifying <literal>trust</literal> authentication for connections from 127.0.0.1 would appear before a record specifying password authentication for a wider range of allowed client IP addresses. pg_hba.confレコードは接続が試みられる度に順番に検査されますので、レコードの順序はとても大切です。 典型的には、始めの方のレコードには厳しい接続照合パラメータと緩い認証方式があるのに対し、終わりの方のレコードにはより緩い照合パラメータとより厳しい認証方式があります。 例えば、ローカルTCP接続ではtrust認証方式、リモートTCP接続に対してはパスワードを要求したいとします。 この場合、広範囲にわたって許可されるクライアントのIPアドレスに対するパスワード認証を指定するレコードの前に127.0.0.1からの接続に対するtrust認証指定のレコードが置かれなければなりません。

The <filename>pg_hba.conf</filename> file is read on start-up and when the main server process receives a <systemitem>SIGHUP</systemitem><indexterm><primary>SIGHUP</primary></indexterm> signal. If you edit the file on an active system, you will need to signal the postmaster (using <literal>pg_ctl reload</literal>, calling the SQL function <function>pg_reload_conf()</function>, or using <literal>kill -HUP</literal>) to make it re-read the file. pg_hba.confファイルは起動時と、主サーバプロセスがSIGHUPシグナルを受け取った時に読み込まれます。 稼働中のシステムでファイルを編集した場合は、(pg_ctl reloadの使用、SQL関数のpg_reload_conf()の呼び出し、またはkill -HUPを使用して)postmasterにファイルをもう一度読み込むようにシグナルを出さなければなりません。

注記

The preceding statement is not true on Microsoft Windows: there, any changes in the <filename>pg_hba.conf</filename> file are immediately applied by subsequent new connections. 上記はマイクロソフトWindowsに対して当てはまりません。 つまり、pg_hba.confに対する変更は、ただちにそれ以降の新しい接続に反映されます。

The system view <link linkend="view-pg-hba-file-rules"><structname>pg_hba_file_rules</structname></link> can be helpful for pre-testing changes to the <filename>pg_hba.conf</filename> file, or for diagnosing problems if loading of the file did not have the desired effects. Rows in the view with non-null <structfield>error</structfield> fields indicate problems in the corresponding lines of the file. pg_hba.confに対する変更を事前にテストする際、あるいはそのファイルをロードしても期待していた結果が得られなかった場合には、システムビューpg_hba_file_rulesが役に立ちます。 そのビューのerrorフィールドがNULLでない行は、そのファイルの該当行に問題があることを示しています。

ヒント

To connect to a particular database, a user must not only pass the <filename>pg_hba.conf</filename> checks, but must have the <literal>CONNECT</literal> privilege for the database. If you wish to restrict which users can connect to which databases, it's usually easier to control this by granting/revoking <literal>CONNECT</literal> privilege than to put the rules in <filename>pg_hba.conf</filename> entries. 特定のデータベースに接続するためには、ユーザはpg_hba.confによる検査を通過しなければならない他、そのデータベースに対するCONNECT権限を持たなければなりません。 どのユーザがどのデータベースに接続できるかを制限したければ、通常、pg_hba.conf項目に規則を追加するよりも、CONNECT権限の付与・削除を行う方が簡単です。

Some examples of <filename>pg_hba.conf</filename> entries are shown in <xref linkend="example-pg-hba.conf"/>. See the next section for details on the different authentication methods. pg_hba.confファイルの例をいくつか例 21.1に示します。 各種認証方式の詳細についてはその後で説明します。

例21.1 pg_hba.confの項目の例

<title>Example <filename>pg_hba.conf</filename> Entries</title>

# Allow any user on the local system to connect to any database with
# any database user name using Unix-domain sockets (the default for local
# connections).

# ローカルシステム上の全てのユーザが、任意のデータベースに
# 任意のデータベースユーザ名でUnixドメインソケットを使用して接続することを許可
# (ローカル接続ではデフォルト)。
#
# TYPE  DATABASE        USER            ADDRESS                 METHOD
local   all             all                                     trust


# The same using local loopback TCP/IP connections.

# 上記と同じことをローカルループバックのTCP/IP接続を使って行う。
#
# TYPE  DATABASE        USER            ADDRESS                 METHOD
host    all             all             127.0.0.1/32            trust


# The same as the previous line, but using a separate netmask column

# 上記と同じだが、独立したネットマスク列を使用する
#
# TYPE  DATABASE        USER            IP-ADDRESS      IP-MASK             METHOD
host    all             all             127.0.0.1       255.255.255.255     trust


# The same over IPv6.

# IPv6で上記と同じことを行う。
#
# TYPE  DATABASE        USER            ADDRESS                 METHOD
host    all             all             ::1/128                 trust


# The same using a host name (would typically cover both IPv4 and IPv6).

# ホスト名を使用して上記と同じことを行う(通常はIPv4とIPv6の両方をカバーします)。
#
# TYPE  DATABASE        USER            ADDRESS                 METHOD
host    all             all             localhost               trust


# The same using a regular expression for DATABASE, that allows connection
# to the database db1, db2 and any databases with a name beginning with "db"
# and finishing with a number using two to four digits (like "db1234" or
# "db12").

# DATABASEに対して正規表現を使って同じことを行う。データベースdb1、db2と、
# 「db」で始まり(「db1234」や「db12」のような)2から4個の数字を使った番号で終わるデータベースへ
# 接続することを許可。
#
# TYPE  DATABASE                   USER            ADDRESS          METHOD
local   db1,"/^db\d{2,4}$",db2     all             localhost        trust


# Allow any user from any host with IP address 192.168.93.x to connect
# to database "postgres" as the same user name that ident reports for
# the connection (typically the operating system user name).

# IPアドレス192.168.93.xを持つ全てのホストの全てのユーザが、
# identがその接続について報告するのと同じユーザ名(典型的にはオペレーティングシステムのユーザ名)で
# データベース「postgres」へ接続することを許可。
#
# TYPE  DATABASE        USER            ADDRESS                 METHOD
host    postgres        all             192.168.93.0/24         ident


# Allow any user from host 192.168.12.10 to connect to database
# "postgres" if the user's password is correctly supplied.

# ユーザのパスワードが正しく入力された場合、
# ホスト192.168.12.10からのどのようなユーザでもデータベース「postgres」へ接続することを許可。
#
# TYPE  DATABASE        USER            ADDRESS                 METHOD
host    postgres        all             192.168.12.10/32        scram-sha-256


# Allow any user from hosts in the example.com domain to connect to
# any database if the user's password is correctly supplied.

# ユーザのパスワードが正しく指定された場合は、
# example.comドメイン内のホストからの、どのユーザからのデータベース接続も許可する。
#
# Require SCRAM authentication for most users, but make an exception
# for user 'mike', who uses an older client that doesn't support SCRAM
# authentication.
#
# TYPE  DATABASE        USER            ADDRESS                 METHOD
host    all             mike            .example.com            md5
host    all             all             .example.com            scram-sha-256


# In the absence of preceding "host" lines, these three lines will
# reject all connections from 192.168.54.1 (since that entry will be
# matched first), but allow GSSAPI-encrypted connections from anywhere else
# on the Internet.  The zero mask causes no bits of the host IP address to
# be considered, so it matches any host.  Unencrypted GSSAPI connections
# (which "fall through" to the third line since "hostgssenc" only matches
# encrypted GSSAPI connections) are allowed, but only from 192.168.12.10.

# 先行する「host」行がなければ、これら3行によって、
# 192.168.54.1からの接続の試みを全て拒否(この項目が最初に照合されるため)、
# ただし、インターネット上の他の全ての場所からのGSSAPI接続は許可。
# ゼロマスクは、ホストIPアドレスのビットが考慮されずに
# どのホストでも照合できることになる。
# 暗号化されていないGSSAPI接続(「hostgssenc」は暗号化されたGSSAPI接続
# にのみに一致するので、3行目までは「通過」)は許可されるが、192.168.12.10からのみ許可。
#
# TYPE  DATABASE        USER            ADDRESS                 METHOD
host    all             all             192.168.54.1/32         reject
hostgssenc all          all             0.0.0.0/0               gss
host    all             all             192.168.12.10/32        gss


# Allow users from 192.168.x.x hosts to connect to any database, if
# they pass the ident check.  If, for example, ident says the user is
# "bryanh" and he requests to connect as PostgreSQL user "guest1", the
# connection is allowed if there is an entry in pg_ident.conf for map
# "omicron" that says "bryanh" is allowed to connect as "guest1".

# 192.168.x.xホストからのユーザが、ident検査に通る場合、
# どのデータベースにでも接続を許可。もし、例えば、identが「bryanh」と認定し
# 「bryanh」がPostgreSQLのユーザ「guest1」として
# 接続要求を出す場合、「bryanh」は「guest1」として接続が許可されるという
# マップ「omicron」に対する記載事項がpg_ident.confにあれば接続を許可。
#
# TYPE  DATABASE        USER            ADDRESS                 METHOD
host    all             all             192.168.0.0/16          ident map=omicron


# If these are the only four lines for local connections, they will
# allow local users to connect only to their own databases (databases
# with the same name as their database user name) except for users whose
# name end with "helpdesk", administrators and members of role "support",
# who can connect to all databases.  The file $PGDATA/admins contains a
# list of names of administrators.  Passwords are required in all cases.

# ローカル接続に対して、以下のたった4行しか記載がない場合、ローカルユーザは
# 自分のデータベース(データベースユーザ名と同じ名前のデータベース)にのみ接続許可。
# ただし、名前が「helpdesk」で終わるユーザ、管理者、ロール「support」のメンバは
# 全てのデータベースに接続可能。$PGDATA/adminsファイルは管理者のリストを含む。
# 全ての場合にパスワードが必要。
#
# TYPE  DATABASE        USER            ADDRESS                 METHOD
local   sameuser        all                                     md5
local   all             /^.*helpdesk$                           md5
local   all             @admins                                 md5
local   all             +support                                md5


# The last two lines above can be combined into a single line:

# 上記の最後の2行は1つの行にまとめることが可能。
local   all             @admins,+support                        md5


# The database column can also use lists and file names:

# データベースの列にはリストやファイル名も使用できる。
local   db1,db2,@demodbs  all                                   md5