LoginSignup
6
8

More than 5 years have passed since last update.

VagrantでOpenLDAPサーバ・クライアント環境構築

Last updated at Posted at 2015-11-08

目的

Vagrantを使って仮想マシンを2つ作成し,一方をLDAPサーバ,他方をLDAPクライアントに設定します.
LDAPクライアントに,LDAPアカウントでログインできることを確認します.

環境

  • PC: Macbook Pro Mid2012
  • OS: MacOSX El Capitan(10.11)

参考にさせて頂いた記事

CentOS 6.5 で OpenLDAP(http://qiita.com/T_Tsan/items/3d76b9b03792e4e9ce1d)
CentOS6 OpenLDAPの設定(http://www.unix-power.net/linux/openldap.html)
Vagrant セットアップ (Mac)(http://qiita.com/inouet/items/b36638adc2b5772db457)

1. 仮想マシン作成

1.1 インストール

以下を参考にVirtual Box, Vagrantのインストールを行います.また,CentOS6.5の仮想マシンを2つ作成します.
http://qiita.com/inouet/items/b36638adc2b5772db457

1.2. ネットワーク設定

1.1 で作成した仮想マシンに対して,Vagrantfileを編集しipを設定します.設定後に仮想マシンを再起動します.

Vagrantfile
config.vm.network "private_network", ip: "ここにipを記述"

ipは2台の仮想マシンで競合しなければ何でも良いですが,ここでは以下のように設定します.

  • 仮想マシン1 (LDAPサーバ)    : 192.168.100.51
  • 仮想マシン2 (LDAPクライアント) : 192.168.100.52

2. LDAPサーバ環境構築

2.1 インストール

LDAPサーバ(192.168.100.51)にログインし,必要なパッケージをインストールします.

$ sudo yum install openldap openldap-servers openldap-clients

インストール完了後,以下のパッケージが入っていればOKです.

$ yum list installed openldap
Installed Packages
openldap-clients.x86_64     2.4.40-6.el6_7      @updates
openldap-devel.x86_64       2.4.40-6.el6_7      @updates
openldap-servers.x86_64     2.4.40-6.el6_7      @updates
openldap-servers-sql.x86_64     2.4.40-6.el6_7      @updates

2.2 LDAPサーバ設定

CentOS6のOpenLDAPでは設定ファイルが/etc/openldap/slapd.d/以下に置かれますが,直接の編集は推奨されていません.slapd.confを記述し,slaptestコマンドを用いて変換します.

初期設定を削除します.

$ rm -rf /etc/openldap/slapd.d/*
$ rm -rf /var/lib/ldap/*

設定ファイルのテンプレートをコピーします.

$ cp /usr/share/openldap-servers/slapd.conf.obsolete /etc/openldap/slapd.conf
$ cp -a /usr/share/openldap-servers/DB_CONFIG.example /var/lib/ldap/DB_CONFIG
$ chown ldap:ldap /var/lib/ldap/DB_CONFIG

slapd.confの編集を行います.ベースDNはkakistan.localとしていますが,適宜変更してください.

/etc/openldap/slapd.conf
include     /etc/openldap/schema/corba.schema
include     /etc/openldap/schema/core.schema
include     /etc/openldap/schema/cosine.schema
include     /etc/openldap/schema/duaconf.schema
include     /etc/openldap/schema/dyngroup.schema
include     /etc/openldap/schema/inetorgperson.schema
include     /etc/openldap/schema/java.schema
include     /etc/openldap/schema/misc.schema
include     /etc/openldap/schema/nis.schema
include     /etc/openldap/schema/openldap.schema
include     /etc/openldap/schema/ppolicy.schema
include     /etc/openldap/schema/collective.schema

allow bind_v2

pidfile     /var/run/openldap/slapd.pid
argsfile    /var/run/openldap/slapd.args

access to attrs=userPassword
    by self write
    by dn="cn=Manager,dc=kakistan,dc=local" write
    by anonymous auth
    by * none

access to *
    by self write
    by dn="cn=Manager,dc=kakistan,dc=local" write
    by * read

database config
access to *
    by dn.exact="gidNumber=0+uidNumber=0,cn=peercred,cn=external,cn=auth" manage
    by * none

database monitor
access to *
    by dn.exact="gidNumber=0+uidNumber=0,cn=peercred,cn=external,cn=auth" read
        by dn.exact="cn=Manager,dc=kakistan,dc=local" read
        by * none


database    bdb
suffix      "dc=kakistan,dc=local"
checkpoint  1024 15
rootdn      "cn=Manager,dc=kakistan,dc=local"
rootpw      {SSHA}tlxwdWEFBrxyhsg+jdndQ+J7wLh2nd9h

directory   /var/lib/ldap

index objectClass                       eq,pres
index ou,cn,mail,surname,givenname      eq,pres,sub
index uidNumber,gidNumber,loginShell    eq,pres
index uid,memberUid                     eq,pres,sub
index nisMapName,nisMapEntry            eq,pres,sub

パスワードはslappasswdコマンドを使って作成します.コマンド実行結果を/etc/openldap/slapd.confのrootpw行に貼り付けます.

$ slappasswd -s passwd
{SSHA}tlxwdWEFBrxyhsg+jdndQ+J7wLh2nd9h

2.3 初期データの作成

初期状態のLDAPサーバには,ディレクトリ構造やユーザ・グループ情報が登録されていません.これらはldifという形式で記述し,ldapaddコマンドを使ってサーバに登録します.以下では/etc/openldap/ldif以下に作成していますが,場所はどこでも構いません.

$ mkdir /etc/openldap/ldif
$ vi /etc/openldap/ldif/base.ldif
/etc/openldap/ldif/base.ldif
# ドメイン
dn: dc=kakistan,dc=local
objectClass: dcObject
objectClass: organization
dc: kakistan
o: kakistan.local

# 管理者
dn: cn=Manager,dc=kakistan,dc=local
objectClass: organizationalRole
cn: Manager

# サンプルグループ
dn: cn=adminstrators,ou=Group,dc=kakistan,dc=local
objectClass: posixGroup
objectClass: top
cn: administrators
gidNumber: 1000

編集完了後,ldapaddコマンドを使ってデータを登録します.パスワード入力を求められるので,2.2でslappasswdコマンドの引数に入力したパスワードを入力します.

$ ldapadd -x -D "cn=Manager,dc=kakistan,dc=local" -W -f /etc/openldap/ldif/base.ldif

次に,ログインに使用するユーザアカウントを登録します.

$ mkdir /etc/openldap/ldif
$ vi /etc/openldap/ldif/base.ldif
/etc/openldap/ldif/admin.ldif
objectClass: account
objectClass: posixAccount
cn: admin user
uid: admin
userPassword: {SSHA}sujd7eVKitH9Sp1uBXK5INTATbCanNk2
uidNumber: 1000
gidNumber: 1000
loginShell: /bin/bash
homeDirectory: /home/admin
$ ldapadd -x -D "cn=Manager,dc=kakistan,dc=local" -W -f /etc/openldap/ldif/admin.ldif

これでLDAPクライアントからLDAPユーザでログインを行う為の,サーバ側の準備は完了です.

3. LDAPクライアント環境構築

3.1 インストール・設定

LDAPクライアント(192.168.100.52)にログインし,に必要なパッケージをインストールします.

$ sudo yum install authconfig nss-pam-ldapd openldap-clients

LDAPログインを許可する設定を行います.

$ sudo authconfig-tui

最初の画面では,LDAPを使用,LDAP認証を使用にチェックを入れます.次の画面では,以下の設定を入れます.

  • [ ] TLSを使用
  • サーバ:ldap://192.168.100.51
  • ベースDN:dc=kakistan,dc=local

4. LDAPアカウントでログイン

vagrantユーザでLDAPクライアント(192.168.100.52)にログインし,admin(LDAPアカウント)に切り替えます.

$ su - admin
パスワード:
su: warning: cannot change directory to /home/admin: そのようなファイルやディレクトリはありません
-bash-4.1$  whoami
admin

以上のようになれば成功です.warningが出ているのはホームディレクトリが存在しないことによるものですが,authconfigの設定で回避できます.

$ authconfig --enablemkhomedir --update
6
8
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
6
8