20.10. LDAP 인증

이 인증 방법은 패스워드 검증 방법으로 LDAP를 사용할 때 외에는 password와 유사하게 작동된다. LDAP는 사용자 이름/패스워드 쌍을 검증할 때에만 사용된다. 따라서 LDAP를 인증에 사용하기 전에 사용자가 데이터베이스에 존재해야 한다.

LDAP 인증은 2가지 모드로 수행할 수 있다. 간단한 바인딩 모드라고 하는 첫 번째 방법은 서버가 prefix username suffix로 구성된 고유한 이름에 바인딩하는 것이다. 일반적으로 prefix 매개 변수는 Active Directory 환경에서 cn= 또는 DOMAIN\을 지정하는 데 사용된다. suffix는 비 Active Directory 환경의 나머지 부분을 지정할 때 사용된다.

검색+바인딩 모드라고 하는 두 번째 모드에서 서버는 ldapbinddnldapbindpasswd로 지정 및 고정된 사용자 이름과 패스워드를 사용하여 LDAP 디렉터리에 먼저 바인딩한 다음, 데이터베이스에 로그인하려는 사용자를 검색한다. 사용자 및 패스워드가 구성되지 않은 경우 익명 바인딩이 디렉터리에 시도된다. ldapbasedn의 서브 트리에서 검색이 수행되고 ldapsearchattribute에서 지정된 속성과 정확히 일치하는 것을 찾는다. 이 검색에서 사용자를 찾았으며, 서버는 연결을 끊고, 로그인이 올바른지 검증하기 위해 클라이언트에서 지정된 패스워드를 사용하여 이 사용자로 디렉터리에 다시 바인딩한다. 이 모드는 Apache mod_authnz_ldappam_ldap 같은 다른 소프트웨어의 LDAP 인증 스키마에서 사용되는 것과 동일하다. 이 방법은 사용자 개체가 디렉터리에 있는 곳에서 더 많은 유연성을 허용하지만 LDAP 서버에 대한 2개의 연결이 초래된다.

다음 구성 옵션이 양쪽 모드에 사용된다:

ldapserver

연결할 LDAP 서버의 이름 또는 IP 주소. 공백으로 구분된 서버를 여러 개 지정할 수 있다.

ldapport

연결할 LDAP 서버의 포트 번호. 포트가 지정되지 않으면 LDAP 라이브러리의 기본 포트 설정이 사용된다.

ldapscheme

Set to ldaps to use LDAPS. This is a non-standard way of using LDAP over SSL, supported by some LDAP server implementations. See also the ldaptls option for an alternative.

ldaptls

1로 설정하면 TLS 암호화를 사용하여 PostgreSQL과 LDAP 서버가 연결된다. This uses the StartTLS operation per RFC 4513. See also the ldapscheme option for an alternative.

Note that using ldapscheme or ldaptls 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.

다음 옵션은 간단 바인딩 모드에만 사용된다.

ldapprefix

간단 바인딩 인증 수행 시 DN 바인딩의 사용자 이름 앞에 추가하는 string.

ldapsuffix

간단 바인딩 인증 수행 시 DN 바인딩의 사용자 이름 뒤에 추가하는 string.

다음 옵션은 검색+바인딩 모드에만 사용된다.

ldapbasedn

검색+바인딩 인증 수행 시 사용자 검색을 시작하는 루트 DN.

ldapbinddn

검색+바인딩 인증 수행 시 검색 수행하기 위해 디렉터리에 바인딩하는 사용자 DN.

ldapbindpasswd

검색+바인딩 인증 수행 시 검색 수행하기 위해 디렉터리에 바인딩하는 사용자의 패스워드.

ldapsearchattribute

검색+바인딩 인증 수행 시 검색에서 사용자 이름에 대해 일치하는 속성. 속성이 지정되지 않으면 uid 속성이 사용된다.

ldapsearchfilter

The search filter to use when doing search+bind authentication. Occurrences of $username will be replaced with the user name. This allows for more flexible search filters than ldapsearchattribute.

ldapurl

RFC 4516 LDAP URL. 이것은 다른 LDAP 옵션 중 일부를 좀 더 간결한 표준 형식으로 작성하는 다른 방법이다. 기본값은 다음과 같다.

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

scopebase, one, sub 중 하나여야 하며, 일반적으로 후자이다. (The default is base, which is normally not useful in this application.) attribute can nominate a single attribute, in which case it is used as a value for ldapsearchattribute. If attribute is empty then filter can be used as a value for ldapsearchfilter.

The URL scheme ldaps chooses the LDAPS method for making LDAP connections over SSL, equivalent to using ldapscheme=ldaps. To use encrypted LDAP connections using the StartTLS operation, use the normal URL scheme ldap and specify the ldaptls option in addition to ldapurl.

For non-anonymous binds, ldapbinddn and ldapbindpasswd must be specified as separate options.

LDAP URL은 현재 Windows가 아니라 with OpenLDAP에서만 지원된다.

간단한 바인딩의 구성 옵션과 검색+바인딩의 옵션을 혼용하는 것은 에러이다.

When using search+bind mode, the search can be performed using a single attribute specified with ldapsearchattribute, or using a custom search filter specified with ldapsearchfilter. Specifying ldapsearchattribute=foo is equivalent to specifying ldapsearchfilter="(foo=$username)". If neither option is specified the default is ldapsearchattribute=uid.

If PostgreSQL was compiled with OpenLDAP as the LDAP client library, the ldapserver setting may be omitted. In that case, a list of host names and ports is looked up via RFC 2782 DNS SRV records. The name _ldap._tcp.DOMAIN is looked up, where DOMAIN is extracted from ldapbasedn.

간단한 바인딩 LDAP 구성의 예시는 다음과 같다.

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

데이터베이스 사용자 someuser로 데이터베이스 서버에 연결이 요청된 경우 PostgreSQL은 DN cn=someuser, dc=example, dc=net 및 클라이언트에서 제공된 패스워드를 사용하여 LDAP 서버에 바인딩을 시도한다. 해당 연결이 성공하면 데이터베이스 액세스가 허용된다.

검색+바인딩 구성의 예시는 다음과 같다.

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

데이터베이스 사용자 someuser로 데이터베이스 서버에 연결이 요청된 경우 PostgreSQL은 익명으로(ldapbinddn가 지정되지 않았으므로) LDAP 서버에 바인딩을 시도하고 지정된 베이스 DN 아래에서 (uid=someuser)에 대한 검색을 수행한다. 항목이 발견되면 발견된 정보와 클라이언트가 제공한 패스워드를 사용하여 바인딩을 시도한다. 해당 제2차 연결이 성공하면 데이터베이스 액세스가 허용된다.

URL로 작성한 동일한 검색+바인딩 구성은 다음과 같다.

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

LDAP에 대한 인증을 지원하는 일부 다른 소프트웨어는 동일한 URL 형식을 사용하므로 구성을 공유하기 쉬워진다.

Here is an example for a search+bind configuration that uses ldapsearchfilter instead of ldapsearchattribute to allow authentication by user ID or email address:

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 example.net:

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

작은 정보

LDAP는 주로 쉼표와 공백을 사용하여 DN의 서로 다른 부분을 구분하므로 예시에 표시된 대로 LDAP 옵션을 구성할 때 매개 변수를 큰따옴표로 둘러싸야 하는 경우가 있다.