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

21.2. ユーザ名マップ #

<title>User Name Maps</title>

When using an external authentication system such as Ident or GSSAPI, the name of the operating system user that initiated the connection might not be the same as the database user (role) that is to be used. In this case, a user name map can be applied to map the operating system user name to a database user. To use user name mapping, specify <literal>map</literal>=<replaceable>map-name</replaceable> in the options field in <filename>pg_hba.conf</filename>. This option is supported for all authentication methods that receive external user names. Since different mappings might be needed for different connections, the name of the map to be used is specified in the <replaceable>map-name</replaceable> parameter in <filename>pg_hba.conf</filename> to indicate which map to use for each individual connection. identやGSSAPIといった外部の認証システムを使用する場合は、接続を開始したオペレーティングシステムのユーザ名が接続先のデータベースユーザ(ロール)名と同じであるとは限りません。 ユーザ名マップを使用するには、pg_hba.conf内でmap=map-nameオプションを指定してください。 このオプションは、外部ユーザ名を受け取るすべての認証方式をサポートしています。 異なる接続に対して、異なるマップを必要とする可能性があります。そのため、それぞれの接続に対して使用されるマップを指定するために、使用するマップの名称はpg_hba.conf内のmap-nameパラメータで指定されます。

User name maps are defined in the ident map file, which by default is named <filename>pg_ident.conf</filename><indexterm><primary>pg_ident.conf</primary></indexterm> and is stored in the cluster's data directory. (It is possible to place the map file elsewhere, however; see the <xref linkend="guc-ident-file"/> configuration parameter.) The ident map file contains lines of the general forms: ユーザ名マップはidentマップファイルに定義されています。デフォルトではファイル名はpg_ident.confで、クラスタのデータディレクトリに保存されています。 (マップファイルを他の場所にも保存できますが、詳細はident_file設定パラメータを参照してください。) identマップファイルは以下のような一般的な形式の行を含んでいます。

map-name system-username database-username
include file
include_if_exists file
include_dir directory

Comments, whitespace and line continuations are handled in the same way as in <filename>pg_hba.conf</filename>. The <replaceable>map-name</replaceable> is an arbitrary name that will be used to refer to this mapping in <filename>pg_hba.conf</filename>. The other two fields specify an operating system user name and a matching database user name. The same <replaceable>map-name</replaceable> can be used repeatedly to specify multiple user-mappings within a single map. コメント、空白、行継続はpg_hba.confと同様に扱われます。 map-namepg_hba.conf内で参照される任意の名称です。 他の2つのフィールドは、どのオペレーティングシステムユーザが、どのデータベースユーザに接続することを許可されているかを指定しています。 同じmap-nameは、1つのマップ内でユーザをマップするために繰り返し使用されます。

As for <filename>pg_hba.conf</filename>, the lines in this file can be include directives, following the same rules. pg_hba.confに関しては、同じ規則に従って、このファイルの行にincludeディレクティブを書くことができます。

There is no restriction regarding how many database users a given operating system user can correspond to, nor vice versa. Thus, entries in a map should be thought of as meaning <quote>this operating system user is allowed to connect as this database user</quote>, rather than implying that they are equivalent. The connection will be allowed if there is any map entry that pairs the user name obtained from the external authentication system with the database user name that the user has requested to connect as. The value <literal>all</literal> can be used as the <replaceable>database-username</replaceable> to specify that if the <replaceable>system-user</replaceable> matches, then this user is allowed to log in as any of the existing database users. Quoting <literal>all</literal> makes the keyword lose its special meaning. どれだけのデータベースユーザがオペレーティングシステムのユーザに対して一致しているか、またその逆に対しても制限はありません。 よってマップ内のエントリは、それらが等しいというよりもむしろこのオペレーティングシステムのユーザはこのデータベースユーザとして接続するという意味になります。 もし外部の認証システムから得られたユーザ名と接続要求を行ったデータベースユーザ名が対となるエントリがマップ内にある場合は、接続は許可されます。 値alldatabase-usernameとして使用して、system-userが一致する場合、このユーザは既存のデータベースユーザのいずれかとしてログインできるように指定できます。 allを引用符で囲むと、キーワードはその特別な意味を失います。

If the <replaceable>database-username</replaceable> begins with a <literal>+</literal> character, then the operating system user can login as any user belonging to that role, similarly to how user names beginning with <literal>+</literal> are treated in <literal>pg_hba.conf</literal>. Thus, a <literal>+</literal> mark means <quote>match any of the roles that are directly or indirectly members of this role</quote>, while a name without a <literal>+</literal> mark matches only that specific role. Quoting a username starting with a <literal>+</literal> makes the <literal>+</literal> lose its special meaning. database-username+文字で始まる場合、オペレーティングシステムユーザはそのロールに属するユーザとしてログインできます。これは+で始まるユーザ名のpg_hba.confでの扱い方と同様です。 したがって、+マークはこのロールの直接または間接的なメンバーであるロールのいずれかに一致したことを意味し、+マークのない名前はその特定のロールにのみ一致します。 +で始まるユーザ名を引用符で囲むと、+はその特別な意味を失います。

If the <replaceable>system-username</replaceable> field starts with a slash (<literal>/</literal>), the remainder of the field is treated as a regular expression. (See <xref linkend="posix-syntax-details"/> for details of <productname>PostgreSQL</productname>'s regular expression syntax.) The regular expression can include a single capture, or parenthesized subexpression, which can then be referenced in the <replaceable>database-username</replaceable> field as <literal>\1</literal> (backslash-one). This allows the mapping of multiple user names in a single line, which is particularly useful for simple syntax substitutions. For example, these entries もしsystem-usernameフィールドがスラッシュ(/)で始まっている場合は、 このフィールドの残りは正規表現として扱われます。 (PostgreSQLの正規表現構文の詳細については9.7.3.1を参照してください。) 正規表現は単一検索や括弧を使用した表現、database-usernameフィールドで\1(バックスラッシュ-1)で参照されるような表現を含みます。 これにより、1行で複数のユーザ名のマップが可能となり、簡単な構文で特に使いやすくなります。例を以下に示します。

mymap   /^(.*)@mydomain\.com$      \1
mymap   /^(.*)@otherdomain\.com$   guest

will remove the domain part for users with system user names that end with <literal>@mydomain.com</literal>, and allow any user whose system name ends with <literal>@otherdomain.com</literal> to log in as <literal>guest</literal>. Quoting a <replaceable>database-username</replaceable> containing <literal>\1</literal> <emphasis>does not</emphasis> make <literal>\1</literal> lose its special meaning. 上記のエントリでは、@mydomain.comで終わるシステムユーザ名のドメイン部分を削除して、@otherdomain.comで終わるシステムユーザ名のユーザがguestとしてログインすることを許可します。 \1を含むdatabase-usernameを引用符で括っても、\1はその特別な意味を失いません

If the <replaceable>database-username</replaceable> field starts with a slash (<literal>/</literal>), the remainder of the field is treated as a regular expression (see <xref linkend="posix-syntax-details"/> for details of <productname>PostgreSQL</productname>'s regular expression syntax. It is not possible to use <literal>\1</literal> to use a capture from regular expression on <replaceable>system-username</replaceable> for a regular expression on <replaceable>database-username</replaceable>. database-usernameフィールドがスラッシュ(/)で始まる場合、フィールドの残りは正規表現として扱われます(PostgreSQLの正規表現構文の詳細については、9.7.3.1を参照してください)。 system-usernameの正規表現からのキャプチャを使用するためにdatabase-usernameでの正規表現に対して\1を使用することはできません。

ヒント

Keep in mind that by default, a regular expression can match just part of a string. It's usually wise to use <literal>^</literal> and <literal>$</literal>, as shown in the above example, to force the match to be to the entire system user name. デフォルトでは正規表現は、文字列の一部を一致させることに注意してください。 上記の例で示したように、システムユーザ名全体を強制的に一致させるために^$を使用すると有用です。

The <filename>pg_ident.conf</filename> file is read on start-up and when the main server process receives a <systemitem>SIGHUP</systemitem><indexterm><primary>SIGHUP</primary></indexterm> signal. If you edit the file on an active system, you will need to signal the postmaster (using <literal>pg_ctl reload</literal>, calling the SQL function <function>pg_reload_conf()</function>, or using <literal>kill -HUP</literal>) to make it re-read the file. pg_ident.confファイルは起動時と、メインサーバのプロセスが SIGHUPを受信したときに読み込まれます。 起動しているシステムで編集した場合は、ファイルを再読み込みするために(pg_ctl reloadの使用、SQL関数pg_reload_conf()の呼び出し、またはkill -HUPを使用して)postmasterにシグナルを送信する必要があります。

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

A <filename>pg_ident.conf</filename> file that could be used in conjunction with the <filename>pg_hba.conf</filename> file in <xref linkend="example-pg-hba.conf"/> is shown in <xref linkend="example-pg-ident.conf"/>. In this example, anyone logged in to a machine on the 192.168 network that does not have the operating system user name <literal>bryanh</literal>, <literal>ann</literal>, or <literal>robert</literal> would not be granted access. Unix user <literal>robert</literal> would only be allowed access when he tries to connect as <productname>PostgreSQL</productname> user <literal>bob</literal>, not as <literal>robert</literal> or anyone else. <literal>ann</literal> would only be allowed to connect as <literal>ann</literal>. User <literal>bryanh</literal> would be allowed to connect as either <literal>bryanh</literal> or as <literal>guest1</literal>. pg_ident.confファイルは、pg_hba.confファイルと結合して使用されます。 例 21.2例 21.1の例があります。 この例では、192.168のネットワーク内のマシンにログインしている、 オペレーティングシステムのユーザ名でbryanhannrobert以外の誰もが、アクセスを許可されていません。 UnixユーザrobertPostgreSQLユーザであるbobとして接続しようとした時のみ アクセス可能で、 robertや他の名前ではアクセスできません。 annannとして接続した時のみ許可され、bryanhbryanh自身もしくはguest1として アクセスが可能となります。

例21.2 pg_ident.confファイルの例

<title>An Example <filename>pg_ident.conf</filename> File</title>
# MAPNAME       SYSTEM-USERNAME         PG-USERNAME

omicron         bryanh                  bryanh
omicron         ann                     ann

# bob has user name robert on these machines

# bobはこれらのマシン内でrobertというユーザ名を持っています。
omicron         robert                  bob

# bryanh can also connect as guest1

# bryanhはguest1としても接続可能です。
omicron         bryanh                  guest1