LoginSignup
30
31

More than 5 years have passed since last update.

Nginx で Basic 認証に LDAP を使う

Posted at

nginx (openresty) で Basic 認証に LDAP を使うためには nginx-auth-ldap を追加で組み込む必要があります。

clone した directory を configure の --add-module で指定して build します。

curl -O http://openresty.org/download/ngx_openresty-1.4.3.9.tar.gz
tar xvf ngx_openresty-1.4.3.9.tar.gz
git clone https://github.com/kvspb/nginx-auth-ldap.git
cd ngx_openresty-1.4.3.9
./configure \
  --prefix=/some/where/openresty-1.4.3.9 \
  --with-luajit \
  ... \
  --add-module=../nginx-auth-ldap
make
sudo make install
nginx.conf
http {
    ldap_server ldap-sales-group {
        url ldap://ldap.example.com:1389/dc=example,dc=com?uid?sub?(objectClass=person);
        group_attribute uniqueMember;
        group_attribute_is_dn on;
        require group cn=Sales,ou=Groups,dc=example,dc=com;
    }
    ldap_server ldap-hr-group {
        url ldap://ldap.example.com:1389/dc=example,dc=com?uid?sub?(objectClass=person);
        group_attribute uniqueMember;
        group_attribute_is_dn on;
        require group cn=HR,ou=Groups,dc=example,dc=com;
    }
    ldap_server ldap-anyone {
        url ldap://ldap.example.com:1389/dc=example,dc=com?uid?sub?(objectClass=person);
        require valid_user;
    }
    server {
        listen 80;
        server_name localhost;
        location / {
            auth_ldap "test1"
            auth_ldap_servers ldap-anyone;
        }
        location /sales/ {
            auth_ldap "test2"
            auth_ldap_servers ldap-sales-group;
        }
        location /hr/ {
            auth_ldap "test3"
            auth_ldap_servers ldap-hr-group;
        }
    }
}

LDAP サーバーは OpenDJ で試しています。

ActiveDirectory の場合は uid ではなく sAMAccountName になります。
binddn, binddn_password も必要かもしれません。

30
31
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
30
31