-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathauth-username-maps.html
More file actions
217 lines (216 loc) · 22 KB
/
auth-username-maps.html
File metadata and controls
217 lines (216 loc) · 22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!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.2. ユーザ名マップ</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 Vsnapshot" /><link rel="prev" href="auth-pg-hba-conf.html" title="20.1. pg_hba.confファイル" /><link rel="next" href="auth-methods.html" title="20.3. 認証方式" /><meta name="viewport" content="width=device-width,initial-scale=1.0" /></head><body id="docContent" class="container-fluid col-10"><div class="other_version"><a href="https://www.postgresql.jp/document/">バージョンごとのドキュメント一覧</a></div><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="4" align="center"><a accesskey="h" href="index.html">PostgreSQL 18.3文書</a></th></tr><tr><td width="10%" align="left"></td><td width="10%" align="left"></td><td width="60%" align="center"><a href="client-authentication.html" title="第20章 クライアント認証">第20章 クライアント認証</a></td><td width="20%" align="right"><div class="actions"><a class="issue" title="github" href="https://github.com/pgsql-jp/jpug-doc/issues/new?template=bug_report.yml&what-happened=version 18.3 : auth-username-maps.html">誤訳等の報告
</a></div></td></tr><tr><td width="10%" align="left"><a accesskey="p" href="auth-pg-hba-conf.html" title="20.1. pg_hba.confファイル">前へ</a> </td><td width="10%" align="left"><a accesskey="u" href="client-authentication.html" title="第20章 クライアント認証">上へ</a></td><td width="60%" align="center">20.2. ユーザ名マップ</td><td width="20%" align="right"> <a accesskey="n" href="auth-methods.html" title="20.3. 認証方式">次へ</a></td></tr></table><hr /></div><div class="sect1" id="AUTH-USERNAME-MAPS"><div class="titlepage"><div><div><h2 class="title" style="clear: both">20.2. ユーザ名マップ <a href="#AUTH-USERNAME-MAPS" class="id_link">#</a></h2></div></div></div><span class="original">
<title>User Name Maps</title>
</span><a id="id-1.6.7.10.2" class="indexterm"></a><a id="id-1.6.7.10.3" class="indexterm"></a><p>
<span class="original">
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.
</span>
identやGSSAPIといった外部の認証システムを使用する場合は、接続を開始したオペレーティングシステムのユーザ名が接続先のデータベースユーザ(ロール)名と同じであるとは限りません。
ユーザ名マップを使用するには、<code class="filename">pg_hba.conf</code>内で<code class="literal">map</code>=<em class="replaceable"><code>map-name</code></em>オプションを指定してください。
このオプションは、外部ユーザ名を受け取るすべての認証方式をサポートしています。
異なる接続に対して、異なるマップを必要とする可能性があります。そのため、それぞれの接続に対して使用されるマップを指定するために、使用するマップの名称は<code class="filename">pg_hba.conf</code>内の<em class="replaceable"><code>map-name</code></em>パラメータで指定されます。
</p><p>
<span class="original">
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:
</span>
ユーザ名マップはidentマップファイルに定義されています。デフォルトではファイル名は<code class="filename">pg_ident.conf</code><a id="id-1.6.7.10.5.2" class="indexterm"></a>で、クラスタのデータディレクトリに保存されています。
(マップファイルを他の場所にも保存できますが、詳細は<a class="xref" href="runtime-config-file-locations.html#GUC-IDENT-FILE">ident_file</a>設定パラメータを参照してください。)
identマップファイルは以下のような一般的な形式の行を含んでいます。
</p><pre class="synopsis">
<em class="replaceable"><code>map-name</code></em> <em class="replaceable"><code>system-username</code></em> <em class="replaceable"><code>database-username</code></em>
<em class="replaceable"><code>include</code></em> <em class="replaceable"><code>file</code></em>
<em class="replaceable"><code>include_if_exists</code></em> <em class="replaceable"><code>file</code></em>
<em class="replaceable"><code>include_dir</code></em> <em class="replaceable"><code>directory</code></em>
</pre><p>
<span class="original">
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.
</span>
コメント、空白、行継続は<code class="filename">pg_hba.conf</code>と同様に扱われます。 <em class="replaceable"><code>map-name</code></em>は
<code class="filename">pg_hba.conf</code>内で参照される任意の名称です。
他の2つのフィールドは、どのオペレーティングシステムユーザが、どのデータベースユーザに接続することを許可されているかを指定しています。
同じ<em class="replaceable"><code>map-name</code></em>は、1つのマップ内でユーザをマップするために繰り返し使用されます。
</p><p>
<span class="original">
As for <filename>pg_hba.conf</filename>, the lines in this file can
be include directives, following the same rules.
</span>
<code class="filename">pg_hba.conf</code>に関しては、同じ規則に従って、このファイルの行にincludeディレクティブを書くことができます。
</p><p>
<span class="original">
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.
</span>
<code class="filename">pg_ident.conf</code>ファイルは起動時と、メインサーバのプロセスが
<span class="systemitem">SIGHUP</span><a id="id-1.6.7.10.7.3" class="indexterm"></a>を受信したときに読み込まれます。
起動しているシステムで編集した場合は、ファイルを再読み込みするために(<code class="literal">pg_ctl reload</code>の使用、SQL関数<code class="function">pg_reload_conf()</code>の呼び出し、または<code class="literal">kill -HUP</code>を使用して)postmasterにシグナルを送信する必要があります。
</p><p>
<span class="original">
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.
</span>
<code class="filename">pg_ident.conf</code>に対する変更を事前にテストする際、あるいはそのファイルをロードしても期待していた結果が得られなかった場合には、システムビュー<a class="link" href="view-pg-ident-file-mappings.html" title="53.11. pg_ident_file_mappings"><code class="structname">pg_ident_file_mappings</code></a>が役に立ちます。
そのビューの<code class="structfield">error</code>フィールドがNULLでない行は、そのファイルの該当行に問題があることを示しています。
</p><p>
<span class="original">
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-username</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.
</span>
どれだけのデータベースユーザがオペレーティングシステムのユーザに対して一致しているか、またその逆に対しても制限はありません。
よってマップ内のエントリは、それらが等しいというよりもむしろ<span class="quote">「<span class="quote">このオペレーティングシステムのユーザはこのデータベースユーザとして接続する</span>」</span>という意味になります。
もし外部の認証システムから得られたユーザ名と接続要求を行ったデータベースユーザ名が対となるエントリがマップ内にある場合は、接続は許可されます。
値<code class="literal">all</code>を<em class="replaceable"><code>database-username</code></em>として使用して、<em class="replaceable"><code>system-username</code></em>が一致する場合、このユーザは既存のデータベースユーザのいずれかとしてログインできるように指定できます。
<code class="literal">all</code>を引用符で囲むと、キーワードはその特別な意味を失います。
</p><p>
<span class="original">
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.
</span>
<em class="replaceable"><code>database-username</code></em>が<code class="literal">+</code>文字で始まる場合、オペレーティングシステムユーザはそのロールに属するユーザとしてログインできます。これは<code class="literal">+</code>で始まるユーザ名の<code class="literal">pg_hba.conf</code>での扱い方と同様です。
したがって、<code class="literal">+</code>マークは<span class="quote">「<span class="quote">このロールの直接または間接的なメンバであるロールのいずれかに一致した</span>」</span>ことを意味し、<code class="literal">+</code>マークのない名前はその特定のロールにのみ一致します。
<code class="literal">+</code>で始まるユーザ名を引用符で囲むと、<code class="literal">+</code>はその特別な意味を失います。
</p><p>
<span class="original">
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.
The portion of the system user name that matched the capture 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
</span>
もし<em class="replaceable"><code>system-username</code></em>フィールドがスラッシュ(<code class="literal">/</code>)で始まっている場合は、このフィールドの残りは正規表現として扱われます。
(<span class="productname">PostgreSQL</span>の正規表現構文の詳細については<a class="xref" href="functions-matching.html#POSIX-SYNTAX-DETAILS" title="9.7.3.1. 正規表現の詳細">9.7.3.1</a>を参照してください。)
正規表現は単一キャプチャや括弧を使用した表現を含みます。
検索に一致したシステムユーザ名の一部は、<em class="replaceable"><code>database-username</code></em>フィールドで<code class="literal">\1</code>(バックスラッシュ1)として参照できます。
これにより、1行で複数のユーザ名のマップが可能となり、簡単な構文で特に使いやすくなります。例を以下に示します。
</p><pre class="programlisting">
mymap /^(.*)@mydomain\.com$ \1
mymap /^(.*)@otherdomain\.com$ guest
</pre><p>
<span class="original">
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.
</span>
上記のエントリでは、<code class="literal">@mydomain.com</code>で終わるシステムユーザ名のドメイン部分を削除して、<code class="literal">@otherdomain.com</code>で終わるシステムユーザ名のユーザが<code class="literal">guest</code>としてログインすることを許可します。
<code class="literal">\1</code>を含む<em class="replaceable"><code>database-username</code></em>を引用符で括っても、<code class="literal">\1</code>はその特別な意味を失い<span class="emphasis"><em>ません</em></span>。
</p><p>
<span class="original">
If the <replaceable>database-username</replaceable> field starts with
a slash (<literal>/</literal>), the remainder of the field is treated
as a regular expression.
When the <replaceable>database-username</replaceable> field is a regular
expression, it is not possible to use <literal>\1</literal> within it to
refer to a capture from the <replaceable>system-username</replaceable>
field.
</span>
<em class="replaceable"><code>database-username</code></em>フィールドがスラッシュ(<code class="literal">/</code>)で始まる場合、フィールドの残りは正規表現として扱われます。
<em class="replaceable"><code>database-username</code></em>フィールドが正規表現の場合、その中で<code class="literal">\1</code>を使用して<em class="replaceable"><code>system-username</code></em>フィールドからキャプチャを参照することはできません。
</p><div class="tip"><h3 class="title">ヒント</h3><p>
<span class="original">
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.
</span>
デフォルトでは正規表現は、文字列の一部を一致させることに注意してください。
上記の例で示したように、システムユーザ名全体を強制的に一致させるために<code class="literal">^</code>や<code class="literal">$</code>を使用すると有用です。
</p></div><p>
<span class="original">
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>.
</span>
<code class="filename">pg_ident.conf</code>ファイルは、<code class="filename">pg_hba.conf</code>ファイルと結合して使用されます。
<a class="xref" href="auth-username-maps.html#EXAMPLE-PG-IDENT.CONF" title="例20.2 pg_ident.confファイルの例">例 20.2</a>に<a class="xref" href="auth-pg-hba-conf.html#EXAMPLE-PG-HBA.CONF" title="例20.1 pg_hba.confの項目の例">例 20.1</a>の例があります。
この例では、192.168のネットワーク内のマシンにログインしている、
オペレーティングシステムのユーザ名で<code class="literal">bryanh</code>、<code class="literal">ann</code>、<code class="literal">robert</code>以外の誰もが、アクセスを許可されていません。
Unixユーザ<code class="literal">robert</code>は<span class="productname">PostgreSQL</span>ユーザである<code class="literal">bob</code>として接続しようとした時のみ
アクセス可能で、 <code class="literal">robert</code>や他の名前ではアクセスできません。
<code class="literal">ann</code>は<code class="literal">ann</code>として接続した時のみ許可され、<code class="literal">bryanh</code>は<code class="literal">bryanh</code>自身もしくは<code class="literal">guest1</code>として
アクセスが可能となります。
</p><div class="example" id="EXAMPLE-PG-IDENT.CONF"><p class="title"><strong>例20.2 <code class="filename">pg_ident.conf</code>ファイルの例</strong></p><div class="example-contents"><span class="original">
<title>An Example <filename>pg_ident.conf</filename> File</title>
</span><pre class="programlisting">
# MAPNAME SYSTEM-USERNAME PG-USERNAME
omicron bryanh bryanh
omicron ann ann
<span class="original">
# bob has user name robert on these machines
</span>
# bobはこれらのマシン内でrobertというユーザ名を持っています。
omicron robert bob
<span class="original">
# bryanh can also connect as guest1
</span>
# bryanhはguest1としても接続可能です。
omicron bryanh guest1
</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="auth-pg-hba-conf.html" title="20.1. pg_hba.confファイル">前へ</a> </td><td width="20%" align="center"><a accesskey="u" href="client-authentication.html" title="第20章 クライアント認証">上へ</a></td><td width="40%" align="right"> <a accesskey="n" href="auth-methods.html" title="20.3. 認証方式">次へ</a></td></tr><tr><td width="40%" align="left" valign="top">20.1. <code class="filename">pg_hba.conf</code>ファイル </td><td width="20%" align="center"><a accesskey="h" href="index.html" title="PostgreSQL 18.3文書">ホーム</a></td><td width="40%" align="right" valign="top"> 20.3. 認証方式</td></tr></table></div></body></html>