5
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

nginxでldap認証を体験

Last updated at Posted at 2015-06-22

参考

今回利用するdockerイメージ

docker pull h3nrik/nginx-ldap
docker pull nickstenning/slapd

ホスト側での準備

sudo apt-get install ldap-utils
wget https://raw.githubusercontent.com/g17/nginx-ldap/master/config/sample.ldif
wget https://raw.githubusercontent.com/g17/nginx-ldap/master/config/basic/nginx.conf

LDAPサーバ

ldapという名前でコンテナ起動
docker run \
 -e LDAP_DOMAIN=example.com \
 -e LDAP_ORGANIZATION="Example Ltd." \
 -e LDAP_ROOTPASS=toor \
 --name ldap \
 -d \
 -p 389:389 nickstenning/slapd
  • pass: toor

LDAPサーバにアカウント登録

sample.ldifを使う
ldapadd \
 -v \
 -h localhost:389 \
 -c \
 -x \
 -D cn=admin,dc=example,dc=com \
 -W \
 -f sample.ldif
登録確認
ldapsearch  \
 -v \
 -h localhost:389 \
 -b 'ou=users,dc=example,dc=com' \
 -D 'cn=admin,dc=example,dc=com'  \
 -x \
 -W '(&(objectClass=person)(uid=test))'

nginx

  • ./nginx.conf のログ出力場所を修正
-   error_log /usr/local/nginx/logs/error.log;
-   access_log /usr/local/nginx/logs/access.log;
+   error_log /var/log/nginx/error.log debug;
+   access_log /var/log/nginx/access.log;

nginx起動

docker run \
 --name nginx \
 --link ldap:ldap \
 -d \
 -v `pwd`/nginx.conf:/etc/nginx/nginx.conf:ro \
 -p 80:80 h3nrik/nginx-ldap

webページの認証を確認

auth.png

  • test / t3st で nginxの認証が通ることを確認。
ログの見方
docker exec -i -t nginx less /var/log/nginx/error.log
  • shift-f でtailモード。

パスワードの変更

元ファイル(sample.ldif)抜粋
  dn: uid=test,ou=users,dc=example,dc=com
  objectclass: inetOrgPerson
  objectclass: person
  gn: Test
  sn: Person
  cn: Test Person
  uid: test
  userPassword: t3st
change_pass.ldif
  dn: uid=test,ou=users,dc=example,dc=com
- objectclass: inetOrgPerson
- objectclass: person
- gn: Test
- sn: Person
- cn: Test Person
- uid: test
+ changetype: modify
+ replace: userPassword
+ userPassword: t3st2
変更実施
ldapmodify -v -h localhost:389 -c -x -D cn=admin,dc=example,dc=com -W -f change_pass.ldif
  • test / t3st2 で nginxの認証が通ることを確認。

ユーザ(ken)の追加

add_ken.ldif
dn: uid=ken,ou=users,dc=example,dc=com
objectclass: inetOrgPerson
objectclass: person
gn: Test
sn: Person
cn: Test Person
uid: ken
userPassword: pass1
適用
ldapadd -v -h localhost:389 -c -x -D cn=admin,dc=example,dc=com -W -f add_ken.ldif

グループにユーザ(ken)追加

mod_member.ldif
dn: cn=docker,ou=groups,dc=example,dc=com
changetype: modify
add: member
member: uid=ken,ou=users,dc=example,dc=com
適用
ldapmodify -v -h localhost:389 -c -x -D cn=admin,dc=example,dc=com -W -f mod_member.ldif
  • ken / pass1 で nginxの認証が通ることを確認。

次は [sharaku/ldap Repository | Docker Hub Registry - Repositories of Docker Images](sharaku/ldap Repository | Docker Hub Registry - Repositories of Docker Images) を試してみる。

5
5
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
5
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?