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

21.10. LDAP認証 #

<title>LDAP Authentication</title>

This authentication method operates similarly to <literal>password</literal> except that it uses LDAP as the password verification method. LDAP is used only to validate the user name/password pairs. Therefore the user must already exist in the database before LDAP can be used for authentication. この認証方式はpasswordと似ていますが、パスワード確認にLDAPを使用する点が異なります。 LDAPはユーザの名前とパスワードの組み合わせの検証のみに使用されます。 そのため、LDAPを使用して認証を行うようにする前に、ユーザはデータベースに存在しなければなりません。

LDAP authentication can operate in two modes. In the first mode, which we will call the simple bind mode, the server will bind to the distinguished name constructed as <replaceable>prefix</replaceable> <replaceable>username</replaceable> <replaceable>suffix</replaceable>. Typically, the <replaceable>prefix</replaceable> parameter is used to specify <literal>cn=</literal>, or <replaceable>DOMAIN</replaceable><literal>\</literal> in an Active Directory environment. <replaceable>suffix</replaceable> is used to specify the remaining part of the DN in a non-Active Directory environment. LDAP認証は2つのモードで動作します。1つ目のモードでは、それは単なるバインド・モードを呼び出すものですが、 サーバはprefix username suffixとして区別された名前にバインドします。 一般的に、prefixパラメータはActive Directory環境でのcn=DOMAIN\を特定するために使用されます。 suffixは、Active Directory環境ではない場合でのDNの残りの部分を特定するために使用されます。

In the second mode, which we will call the search+bind mode, the server first binds to the LDAP directory with a fixed user name and password, specified with <replaceable>ldapbinddn</replaceable> and <replaceable>ldapbindpasswd</replaceable>, and performs a search for the user trying to log in to the database. If no user and password is configured, an anonymous bind will be attempted to the directory. The search will be performed over the subtree at <replaceable>ldapbasedn</replaceable>, and will try to do an exact match of the attribute specified in <replaceable>ldapsearchattribute</replaceable>. Once the user has been found in this search, the server disconnects and re-binds to the directory as this user, using the password specified by the client, to verify that the login is correct. This mode is the same as that used by LDAP authentication schemes in other software, such as Apache <literal>mod_authnz_ldap</literal> and <literal>pam_ldap</literal>. This method allows for significantly more flexibility in where the user objects are located in the directory, but will cause two separate connections to the LDAP server to be made. 2つ目のモードでは、それはsearch+bindモードを呼び出すもので、サーバは最初にldapbinddnldapbindpasswdで指定された、 固定されたユーザ名とパスワードを使用してLDAPディレクトリにバインドします。 それからデータベースにログインしようとしているユーザを検索します。 もしユーザとパスワードが指定されていなかった場合は、ディレクトリに対して匿名でバインドします。 検索はldapbasednのサブツリーまで行われ、ldapsearchattributeで指定された属性に正確に一致するかどうかまで行われます。 この検索において、一度ユーザが見つかるとサーバは切断して、クライアントで指定されたパスワードを使用してこのユーザとして再度ディレクトリにバインドします。これはそのログインが正しいかどうかを検証するためです。 このモードはApache mod_authnz_ldapおよびpam_ldapなどの他のソフトウェアと同じように、LDAP認証の仕組みで使用されるものと同じです。 この方法は、ユーザオブジェクトがディレクトリに配置されている場合に、かなりの柔軟性があります。 しかし、LDAPサーバへの2つの分離した接続が作成されます。

The following configuration options are used in both modes: 次の設定オプションは両方のモードで使用されます。

ldapserver

Names or IP addresses of LDAP servers to connect to. Multiple servers may be specified, separated by spaces. 接続するLDAPサーバの名称もしくはIPアドレス。空白で区切ることで複数のサーバを指定できます。

ldapport

Port number on LDAP server to connect to. If no port is specified, the LDAP library's default port setting will be used. LDAPサーバに接続するためのポート番号。もしポートが指定されていない場合は LDAPライブラリ内のデフォルトポート設定が使用されます。

ldapscheme

Set to <literal>ldaps</literal> to use LDAPS. This is a non-standard way of using LDAP over SSL, supported by some LDAP server implementations. See also the <literal>ldaptls</literal> option for an alternative. ldapsに設定するとLDAPSを使用します。 これはいくつかのLDAPサーバーの実装でサポートされている、SSL経由のLDAPを使用する非標準の方法です。 代替方法については、ldaptlsオプションを参照してください。

ldaptls

Set to 1 to make the connection between PostgreSQL and the LDAP server use TLS encryption. This uses the <literal>StartTLS</literal> operation per <ulink url="https://tools.ietf.org/html/rfc4513">RFC 4513</ulink>. See also the <literal>ldapscheme</literal> option for an alternative. 1に設定すると、PostgreSQLとLDAPサーバ間の接続にTLSによる暗号化を使用します。 これはRFC 4513StartTLS操作を使用します。 代替方法については、ldapschemeオプションも参照してください。

Note that using <literal>ldapscheme</literal> or <literal>ldaptls</literal> only encrypts the traffic between the PostgreSQL server and the LDAP server. The connection between the PostgreSQL server and the PostgreSQL client will still be unencrypted unless SSL is used there as well. ldapschemeldaptlsを使うときにはPostgreSQLサーバとLDAPサーバ間のトラフィックのみが暗号化されることに注意してください。 SSLがそこでも使用されていない限り、PostgreSQLサーバとPostgreSQLクライアントとの接続は、暗号化されません。

The following options are used in simple bind mode only: 以下のオプションは単純バインド・モードのみで使用されます。

ldapprefix

String to prepend to the user name when forming the DN to bind as, when doing simple bind authentication. 単純なバインド認証を行う場合のDNを生成する際にユーザ名の前に追加する文字列

ldapsuffix

String to append to the user name when forming the DN to bind as, when doing simple bind authentication. 単純なバインド認証を行う場合のDNを生成する際にユーザ名の後に追加する文字列

The following options are used in search+bind mode only: 以下のオプションはsearch+bindモードのみで使用されます。

ldapbasedn

Root DN to begin the search for the user in, when doing search+bind authentication. 検索とバインドの認証を行う場合のユーザ名がログインするための検索を始めるためのルートDN

ldapbinddn

DN of user to bind to the directory with to perform the search when doing search+bind authentication. 検索とバインドの認証を行う場合のディレクトリと検索をバインドするためのユーザのDN

ldapbindpasswd

Password for user to bind to the directory with to perform the search when doing search+bind authentication. 検索とバインドの認証を行う場合のディレクトリと検索をバインドするためのユーザのパスワード

ldapsearchattribute

Attribute to match against the user name in the search when doing search+bind authentication. If no attribute is specified, the <literal>uid</literal> attribute will be used. 検索とバインドの認証を行う場合の検索時のユーザ名に対して一致させる属性。 属性が指定されない場合、属性uidが使用されます。

ldapsearchfilter

The search filter to use when doing search+bind authentication. Occurrences of <literal>$username</literal> will be replaced with the user name. This allows for more flexible search filters than <literal>ldapsearchattribute</literal>. search+bind認証を行うときに使用する検索フィルタです。 $usernameの出現はユーザ名に置き換えられます。 これによりldapsearchattributeよりも柔軟な検索フィルタが可能になります。

ldapurl

An <ulink url="https://tools.ietf.org/html/rfc4516">RFC 4516</ulink> LDAP URL. This is an alternative way to write some of the other LDAP options in a more compact and standard form. The format is RFC 4516LDAP URL。 これはその他いくつかのLDAPオプションをより簡潔、かつ一般的な形式で記述する別の方法です。 フォーマットは以下のようになっています。

ldap[s]://host[:port]/basedn[?[attribute][?[scope][?[filter]]]]

<replaceable>scope</replaceable> must be one of <literal>base</literal>, <literal>one</literal>, <literal>sub</literal>, typically the last. (The default is <literal>base</literal>, which is normally not useful in this application.) <replaceable>attribute</replaceable> can nominate a single attribute, in which case it is used as a value for <literal>ldapsearchattribute</literal>. If <replaceable>attribute</replaceable> is empty then <replaceable>filter</replaceable> can be used as a value for <literal>ldapsearchfilter</literal>. scopebaseonesubのいずれかでなくてはならず、一般的には最後のものです。 (デフォルトはbaseです。これは通常このアプリケーションでは役に立ちません。) attributeは単一の属性を指定できます。その場合、それはldapsearchattributeの値として使用されます。 もしattributeが空の場合は、ldapsearchfilterの値としてfilterを使用できます。

The URL scheme <literal>ldaps</literal> chooses the LDAPS method for making LDAP connections over SSL, equivalent to using <literal>ldapscheme=ldaps</literal>. To use encrypted LDAP connections using the <literal>StartTLS</literal> operation, use the normal URL scheme <literal>ldap</literal> and specify the <literal>ldaptls</literal> option in addition to <literal>ldapurl</literal>. URLスキームldapsは、ldapscheme=ldapsを使用するのと同じ、SSL上のLDAP接続をするLDAPS方式を選択します。 StartTLS操作による暗号化されたLDAP接続を使用するには、通常のURLスキームldapを使用し、ldapurlに加えldaptlsオプションを使用しなければなりません。

For non-anonymous binds, <literal>ldapbinddn</literal> and <literal>ldapbindpasswd</literal> must be specified as separate options. 非匿名バインド(non-anonymous bind)に対し、ldapbinddnおよびldapbindpasswdは個別のオプションとして指定されなければなりません。

LDAP URLs are currently only supported with <productname>OpenLDAP</productname>, not on Windows. LDAP URLは現在、OpenLDAPのみでサポートされており、Windowsではサポートされていません。

It is an error to mix configuration options for simple bind with options for search+bind. search+bindオプションと単純バインドに対するオプションの設定を混在させるのはエラーです。

When using search+bind mode, the search can be performed using a single attribute specified with <literal>ldapsearchattribute</literal>, or using a custom search filter specified with <literal>ldapsearchfilter</literal>. Specifying <literal>ldapsearchattribute=foo</literal> is equivalent to specifying <literal>ldapsearchfilter="(foo=$username)"</literal>. If neither option is specified the default is <literal>ldapsearchattribute=uid</literal>. search+bindモードを使用するときは、ldapsearchattributeで指定される単一の属性を使って、あるいはldapsearchfilterで指定されるカスタム検索フィルターを使って、検索を実行できます。 ldapsearchattribute=fooの指定は、ldapsearchfilter="(foo=$username)"と同等です。 どちらのオプションもない場合は、ldapsearchattribute=uidがデフォルトです。

If <productname>PostgreSQL</productname> was compiled with <productname>OpenLDAP</productname> as the LDAP client library, the <literal>ldapserver</literal> setting may be omitted. In that case, a list of host names and ports is looked up via <ulink url="https://tools.ietf.org/html/rfc2782">RFC 2782</ulink> DNS SRV records. The name <literal>_ldap._tcp.DOMAIN</literal> is looked up, where <literal>DOMAIN</literal> is extracted from <literal>ldapbasedn</literal>. PostgreSQLが、LDAPクライアントライブラリとしてOpenLDAPを使用するようにコンパイルされていた場合、ldapserverの設定は省略出来ます。 その場合、ホスト名とポート番号のリストは、RFC 2782 DNS SRVレコードを使用して検索されます。 _ldap._tcp.DOMAINという名前が検索され、ldapbasednからDOMAINが抽出されます。

Here is an example for a simple-bind LDAP configuration: 以下に単純バインドLDAP設定の例を示します。

host ... ldap ldapserver=ldap.example.net ldapprefix="cn=" ldapsuffix=", dc=example, dc=net"

When a connection to the database server as database user <literal>someuser</literal> is requested, PostgreSQL will attempt to bind to the LDAP server using the DN <literal>cn=someuser, dc=example, dc=net</literal> and the password provided by the client. If that connection succeeds, the database access is granted. データベースのユーザ、someuserからデータベースサーバに接続を要求された場合、PostgreSQLはDN cn=someuser, dc=example, dc=netおよびクライアントから提供されたパスワードを用いてLDAPサーバにバインドを試みます。 その接続が成功すればデータベースへのアクセスが認められます。

Here is an example for a search+bind configuration: 以下はsearch+bind設定の例です。

host ... ldap ldapserver=ldap.example.net ldapbasedn="dc=example, dc=net" ldapsearchattribute=uid

When a connection to the database server as database user <literal>someuser</literal> is requested, PostgreSQL will attempt to bind anonymously (since <literal>ldapbinddn</literal> was not specified) to the LDAP server, perform a search for <literal>(uid=someuser)</literal> under the specified base DN. If an entry is found, it will then attempt to bind using that found information and the password supplied by the client. If that second connection succeeds, the database access is granted. データベースユーザsomeuserとしてデータベースに接続するとき、PostgreSQLは(ldapbinddnが指定されていないので)匿名的にバインドを試み、指定されたベースDNの基で(uid=someuser)の検索を行います。あるエントリが見つかると、見つかった情報とクライアントから与えられたパスワードを用いて、その結果バインドを試みます。その二番目の接続が成功するとデータベースアクセスを認められます。

Here is the same search+bind configuration written as a URL: URLとして記述した同じsearch+bind設定の例です。

host ... ldap ldapurl="ldap://ldap.example.net/dc=example,dc=net?uid?sub"

Some other software that supports authentication against LDAP uses the same URL format, so it will be easier to share the configuration. LDAPに対し認証をサポートするいくつかの他のソフトウェアは同じURLフォーマットを使用します。 従って、設定をより簡易に共有できます。

Here is an example for a search+bind configuration that uses <literal>ldapsearchfilter</literal> instead of <literal>ldapsearchattribute</literal> to allow authentication by user ID or email address: ldapsearchattributeの代わりにldapsearchfilterを使用してユーザーIDまたは電子メールアドレスによる認証を可能にするsearch+bind設定の例です。

host ... ldap ldapserver=ldap.example.net ldapbasedn="dc=example, dc=net" ldapsearchfilter="(|(uid=$username)(mail=$username))"

Here is an example for a search+bind configuration that uses DNS SRV discovery to find the host name(s) and port(s) for the LDAP service for the domain name <literal>example.net</literal>: DNS SRV検出を使用してドメイン名example.netのLDAPサービスのホスト名とポート番号を検索する、search+bind設定の例です。

host ... ldap ldapbasedn="dc=example,dc=net"

ヒント

Since LDAP often uses commas and spaces to separate the different parts of a DN, it is often necessary to use double-quoted parameter values when configuring LDAP options, as shown in the examples. LDAPはDNの異なる構成要素を区切るために往々にしてコンマとスペースを使用します。 例で示されたように、LDAPオプションを設定する場合、二重引用符で括られたパラメータ値を使用することがしばしば必須となります。