將 OpenLDAP 設定為 Active Directory 代理

將 OpenLDAP 設定為 Active Directory 代理

我們嘗試設定一個 Active Directory 伺服器來進行公司範圍的身份驗證。

一些需要針對 AD 進行驗證的伺服器位於 DMZ 中,因此我們考慮使用 LDAP 伺服器作為代理,這樣 DMZ 中只有 1 台伺服器必須連接到 AD 伺服器所在的 LAN )。

透過一些Google搜索,配置 slapd 沒有問題(請參閱下面的 slapd.conf),並且在使用 ldapsearch 工具時它似乎可以工作,因此我們嘗試在 apache2 htaccess 中使用它來透過 LDAP 代理對使用者進行身份驗證。

問題來了:我們發現 AD 中的使用者名稱儲存在屬性「sAMAccountName」中,因此我們在 .htaccess 中配置了它(見下文),但登入不起作用。

在系統日誌中,我們發現 ldapsearch 的過濾器不是(應該是)'(&(objectClass=*)(sAMAccountName=authtest01))' 但 '(&(objectClass=*)(?=未定義))' 我們發現這是 slapd 的方式來表示該屬性不存在或該屬性的值在語法上是錯誤的。

我們想到了一個缺失的模式並找到了微軟架構(以及其中的 .std / .ext )並嘗試將它們包含在 slapd.conf 中。這是行不通的。我們發現沒有可用的架構,因此我們只是挑選了有關 sAMAccountName 的部分並建立了我們包含的 microsoft.minimal.schema(見下文)。現在我們在系統日誌中獲得更精確的日誌:

Jun 16 13:32:04 breauthsrv01 slapd[21229]: get_ava: illegal value for attributeType sAMAccountName
Jun 16 13:32:04 breauthsrv01 slapd[21229]: conn=0 op=1 SRCH base="ou=xxx,dc=int,dc=xxx,dc=de" scope=2 deref=3 filter="(&(objectClass=\*)(?sAMAccountName=authtest01))"
Jun 16 13:32:04 breauthsrv01 slapd[21229]: conn=0 op=1 SRCH attr=sAMAccountName
Jun 16 13:32:04 breauthsrv01 slapd[21229]: conn=0 op=1 SEARCH RESULT tag=101 err=0 nentries=0 text=

不過,透過 LDAP 直接使用我們的 Apache htaccess 與 AD 是可行的。有人有工作設定嗎?感謝您提前提供的任何幫助:

slapd.conf:

allow bind_v2
include         /etc/ldap/schema/core.schema
...
include         /etc/ldap/schema/microsoft.minimal.schema
...
backend         ldap
database        ldap

suffix "ou=xxx,dc=int,dc=xxx,dc=de"
uri "ldap://80.156.177.161:389"
acl-bind bindmethod=simple binddn="CN=authtest01,ou=GPO-Test,ou=xxx,dc=int,dc=xxx,dc=de" credentials=xxxxx

.htaccess:

AuthBasicProvider ldap
AuthType basic
AuthName "AuthTest"
AuthLDAPURL "ldap://breauthsrv01.xxx.de:389/OU=xxx,DC=int,DC=xxx,DC=de?sAMAccountName?sub"
AuthzLDAPAuthoritative On
AuthLDAPGroupAttribute member
AuthLDAPBindDN  CN=authtest02,OU=GPO-Test,OU=xxx,DC=int,DC=xxx,DC=de
AuthLDAPBindPassword test123
Require valid-user

微軟.最小.架構:

attributetype ( 1.2.840.113556.1.4.221
      NAME 'sAMAccountName'
      SYNTAX '1.3.6.1.4.1.1466.115.121.1.15'
      SINGLE-VALUE )

答案1

您需要將映射新增至 slapd.conf 檔案:

moduleload rwm
...
overlay rwm
rwm-map attribute uid sAMAccountName
rwm-map objectClass posixGroup group 
rwm-map objectClass posixAccount person
rwm-map objectClass memberUid member

然後你可以搜尋uid屬性而不是sAMA帳戶名.htaccess 檔案中的屬性:

AuthLDAPURL "ldap://breauthsrv01.xxx.de:389/OU=xxx,DC=int,DC=xxx,DC=de?uid?sub"

答案2

您看到此錯誤訊息:

get_ava:attributeType sAMAccountName 的值非法

這是由於您對sAMAccountName屬性的定義microsoft.minimal.schema缺少匹配規則造成的。簡單來說,OpenLDAP 的模式定義允許您指定允許哪種類型的搜尋(存在、精確匹配、子字串匹配等),而這個定義沒有。

嘗試這個:

 attributetype ( 1.2.840.113556.1.4.221
   NAME 'sAMAccountName'
   EQUALITY caseIgnoreMatch
   SYNTAX '1.3.6.1.4.1.1466.115.121.1.15'
   SINGLE-VALUE )

答案3

喬納森的回答為我指明了正確的方向,讓我克服了以下問題:

additional info: sAMAccountName: attribute type undefined

問題。但我意識到您需要將此屬性定義為一個人的條目的合法值,並且您需要為每個人提供允許具有該屬性的objectClass。就像您可以賦予 inetOrgPerson 的所有屬性一樣。

我的 microsoft.minimal.schema 檔案現在是:

attributetype ( 1.2.840.113556.1.4.221
          NAME 'sAMAccountName'
          SYNTAX '1.3.6.1.4.1.1466.115.121.1.15'
          SINGLE-VALUE )

attributetype ( 1.2.840.113556.1.4.146
          NAME 'objectSid'
          SYNTAX '1.3.6.1.4.1.1466.115.121.1.40'
          SINGLE-VALUE )

objectclass ( 1.2.840.113556.1.5.6
        NAME 'securityPrincipal'
        SUP top
        AUXILIARY
        MUST (objectSid $ sAMAccountName )
        MAY () )

 #            MAY (nTSecurityDescriptor $ securityIdentifier $ supplementalCredentials $
 #                rid $ sAMAccountType $ sIDHistory $ altSecurityIdentities $ tokenGroups $
 #                    tokenGroupsNoGCAcceptable $ accountNameHistory  $
 #                                              tokenGroupsGlobalAndUniversal))

我將 MS 可選屬性替換為任何內容,因此我不必定義它們。

使用者條目範例如下:

dn: uid=user2,ou=example,dc=aa,dc=ad,dc=example,dc=gov                                                                          
uid: user2                                                                                                              
sAMAccountName: user2                                                                                                   
objectSid: user2                                                                                                        
cn: User Two                                                                                                            
displayName: User Two                                                                                                   
givenName: User2                                                                                                        
sn: One                                                                                                                 
objectClass: inetOrgPerson                                                                                              
objectClass: securityPrincipal                                                                                          
mail: [email protected]                                                                                                 
 # password from slappasswd is 'user2'                                                                                   
userPassword: {SSHA}sjB5fmIIPTrUUammtmonP+6DdC93+P4L    

相關內容