Openldap基於digest-md5方式的SASL認證配置


1. openldap編譯

如果需要openldap支持SASL認證,需要在編譯時加上–enable-spasswd選項
安裝完cyrus-sasl,openssl(可選),BDB包后執行:

注:
/usr/local/lib為 libsasl2.so.2所在目錄
/usr/local/BerkeleyDB.4.8/lib為 libdb-4.8.so所在目錄
/lib/i386-linux-gnu/為 libssl.so.1.0.0所在目錄

安裝完畢后

輸出:

可以看到默認已經提供DIGEST-MD5方式 的SASL機制。

2. slapd.conf配置

配置輸出:

2.1 用戶密碼相關配置

參考http://www.openldap.org/doc/admin24/sasl.html#DIGEST-MD5
This section describes the use of the SASL DIGEST-MD5 mechanism using secrets stored either in the directory itself or in Cyrus SASL’s own database.
這里提到了兩種管理用戶密碼的方式
a.對於第一種:
To use secrets stored in sasldb, simply add users with the saslpasswd2 command:

The passwords for such users must be managed with the saslpasswd2 command.
b.對於第二種:
To use secrets stored in the LDAP directory, place plaintext passwords in the userPassword attribute. It will be necessary to add an option to slapd.conf to make sure that passwords set using the LDAP Password Modify Operation are stored in plaintext:

Passwords stored in this way can be managed either with ldappasswd(1) or by simply modifying the userPassword attribute. Regardless of where the passwords are stored, a mapping will be needed from authentication request DN to user’s DN.
在 這里,我采用了第二種。根據文檔說明,這種方式的密碼是存在userPassword屬性中的,因此每個需要進行認證的用戶都必須有一個 userPassword屬性。並且通過在slapd.conf文件中通過指定password-hash {CLEARTEXT}來確保密碼存儲為明文的文本格式。
由於每個認證用戶都必須有一個userPassword屬性,因此對應的條目必須具有一個含有userPassword 屬性的objectclass,我采用 simpleSecurityObject這個objectclass,這是一個輔助objectclass(區別於structual objectclass),僅包含一個必要屬性userPassword.
參見core.schema:

因此可以將管理員用戶的ldif數據文件配置為:
manager.ldif:

2.2 認證ID與實際條目映射

參考http://www.openldap.org/doc/admin24/sasl.html#Mapping%20Authentication%20Identities
The DIGEST-MD5 mechanism produces authentication IDs of the form:

If the default realm is used,the realm name is omitted from the ID, giving:

對於我們的例子,配置管理員認證ID為:

認證ID與實際的LDAP條目之間有兩種映射方式:direct mapping和search-based mappings.
Where possible, direct mapping of the authentication request DN to the user’s DN is generally recommended. Aside from avoiding the expense of searching for the user’s DN, it allows mapping to DNs which refer to entries not held by this server.
基於以上原因,采用direct mapping方式。
The LDAP administrator will need to tell the slapd server how to map an authentication request DN to a user’s authentication DN. This is done by adding one or more authz-regexp directives to the slapd.conf(5) file. This directive takes two arguments:

Suppose the authentication request DN is written as:

and the user’s actual LDAP entry is:

then the following authz-regexp directive in slapd.conf(5) would provide for direct mapping.

對於我們的例子則是:

依據正則表達式的語法,([^,]*)匹配直到遇到逗號之前的字符,$1反向引用([^,]*)中的內容。

3 導入管理員用戶信息

采 用這種方式時認證用戶包括管理員的密碼都是存儲在ldap目錄中的,也就是說,管理員本身的信息也是需要導入的,而在這種方式下rootdn的配置不滿足 suffix的要求,不能設置rootpw選項,也就不能綁定管理員用戶使用ldapadd命令進行管理員信息導入了,那管理員本身的信息如何導入呢?可 以通過以下命令:

4 數據操作

開啟openldap服務器

導入ldif數據文件,添加數據

manager:管理員用戶的DN為AstAccountName=manager,ou=accounts,dc=com,根據映射關系,對應的uid就是這里的AstAccountName屬性的值manager。
grandstream:對應userPassword屬性的值,即管理員密碼。
gs_phonebook.ldif:要導入的ldif數據文件。
查詢數據

刪除數據

或遞歸刪除


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM