2011-01-31 31 views
2

我有一個最初設置用於intranet訪問的apache服務器,所以我不必擔心太多關於鎖定的問題。mod_rewrite之前的Apache 2.x auth

後來,我需要打開它的互聯網,所以我把LDAP身份驗證指令在httpd.conf的部分,像這樣:

Order allow,deny 

AuthBasicProvider ldap 
AuthType Basic 
AuthzLDAPAuthoritative on 
AuthName "MyCompany Intranet" 
AuthLDAPURL "ldap://myldapserver.mydomain.com:389/CN=Users,DC=mydomain,DC=com?sAMAccountName?sub?(memberOf=CN=Everyone at MyCompany,OU=MyCompany Groups,DC=mydomain,DC=com)" NONE 
AuthLDAPBindDN "CN=Administrator,CN=Users,DC=mydomain,DC=com" 
AuthLDAPBindPassword "MyPassword" 

Require valid-user 

#Allow from all 
Allow from 192.168.1 
Allow from 10.254.0 

Satisfy any 

基本上,這使得它使本地用戶可能無法進入密碼,外部用戶必須通過ADS域進行身份驗證才能進入。

現在事情變得更加複雜。

我有一個應用程序,我通過將一個cgi變量添加到URL的末尾來區分用戶,所以我在我的Web目錄(/ var/www/html)的根目錄中設置了一個.htaccess文件作爲如下:

RewriteEngine on 
RewriteBase/
RewriteRule ^foo/(.*)$ some/really/long/url/$1?tenant_filter=2 [L] 
RewriteRule ^bar/(.*)$ some/really/long/url/$1?tenant_filter=1 [L] 

這工作真的很棒。客戶端輸入http://myserver.mydomain.com/foo/file.html,並且URL神奇地將它們指向http://myserver.mydomain.com/some/really/long/url/file.html?tenant_filter=2而他們看到的只是http://myserver.mydomain.com/foo/file.html。

這裏是哪裏出了問題的用武之地。

我想定義爲/ foo和/條虛擬目錄獨立認證參數。無論我嘗試什麼,身份驗證都會被上面的http.conf中的ldap設置覆蓋。我做錯了什麼,我能做些什麼來實現我的目標?它甚至有可能嗎?

+0

在添加這個配置文件的上下文中? – Ass3mbler 2011-01-31 20:23:34

回答

0

授權配置選項可以放在<位置>和<目錄>部分。但是:

<位置>指令不應該用於控制對文件系統位置的訪問。由於幾個不同的URL可能映射到相同的文件系統位置,因此可能會繞過此類訪問控制。

這似乎不是你的情況的問題,因爲這看起來完全是你正在尋找的行爲。

1

解決此問題的方法是在/ var/www/html中創建名爲foo和bar的目標目錄。驗證當時設定在/etc/httpd/conf.d目錄的目錄如下:

<Directory "/var/www/html/bar">  
    AuthBasicProvider ldap 
    AuthType Basic 
    AuthName "Bar Extranet" 
    AuthLDAPURL ldap://myldapserver.mydomain.com:3268/DC=mydomain,DC=com?sAMAccountName?sub?(objectClass=*) 
    AuthzLDAPAuthoritative on 

    AuthLDAPBindDN "CN=Administrator,CN=Users,DC=mydomain,DC=com" 
    AuthLDAPBindPassword "mypassword" 

    AuthLDAPGroupAttributeIsDN on 

    require ldap-group CN=Bar Kiosk,OU=mycompany Groups,DC=mydomain,DC=com 

    Allow from 192.168.1 
    Allow from 10.254.0 

    Satisfy any 
</Directory> 

的重寫的目標目錄設置爲接受來自任何富認證或下面條:

<Directory /var/www/html/some/really/long/directoryname> 
    AuthBasicProvider ldap 
    AuthType Basic 
    AuthName "mycompany Extranet" 
    AuthLDAPURL ldap://myldaphost.mydomain.com:3268/DC=mydomain,DC=com?sAMAccountName?sub?(objectClass=*) 
    AuthzLDAPAuthoritative on 

    AuthLDAPBindDN "CN=Administrator,CN=Users,DC=mydomain,DC=com" 
    AuthLDAPBindPassword "mypassword" 

    AuthLDAPGroupAttributeIsDN on 

    require ldap-group CN=Domain Users,CN=Users,DC=mydomain,DC=com 
    require ldap-group CN=BAR Kiosk,OU=mycompany Groups,CN=Users,DC=mydomain,DC=com 

    Allow from 192.168.1 
    Allow from 10.254.0 

    satisfy any 
</Directory> 

雖然這允許foo和bar訪問目標目錄,但足以滿足我的需要,因爲目標目錄被URL重寫代碼模糊處理。

我還更改了/ etc/httpd/conf/httpd中的代碼。爲URL的conf文件重寫,以防止環路:

RewriteEngine on 
RewriteBase/
RewriteCond %{REQUEST_URI} !^(.*)tenant_filter=1$ [OR] 
RewriteCond %{REQUEST_URI} !^(.*)tenant_filter=2$ 
RewriteRule ^foo/(.*)$ some/really/long/url/$1?tenant_filter=2 [L] 
RewriteRule ^bar/(.*)$ some/really/long/url/$1?tenant_filter=1 [L] 

最後,我的情況是由我該服務器上運行BlueDragon 7.1的Linux的事實複雜化。我在最初的文章中沒有提到它,但是BD並沒有意識到我在Apache配置中所做的一些更改,而沒有重新啓動。這個過程非常複雜。