ブログ

LDAPサーバを利用した社内サーバ管理(第1回)

2008年08月07日(木)11:19|天方

サーバの台数が増えるとアカウント管理も楽じゃない

最近、社内で管理しているサーバの台数が結構増えてきました。

ハードウェアの数はそこそこなのですが、仮想マシンを利用するようになってから、サーバを簡単に増やせるようになったというのが主な理由です。Webシステムの開発に利用する環境なので、システム毎に環境を作っていると、アカウント管理などが煩雑になってきてしまいます。

そこで、開発サーバについてはLDAPを使った統合認証を利用しています。

LDAPを利用すると、Linuxユーザアカウント、Samba、Web認証(参考:apache2.2でLDAP認証を使う)、メールなどのアカウント情報を一元管理することができ、アカウント管理の手間を減らすことが可能です。

マシンの台数が10台以上あり、それぞれのマシンを同じ組織内の複数のユーザが利用する場合などに有用です。

では、Gentoo LinuxでのOpenLDAPの導入とLinuxアカウントの統合認証を設定する手順を御紹介したいと思います。

第1回では、まず、統合認証用のサーバへのOpenLDAPのインストールを扱いたいと思います。

OpenLDAPのインストール

rootでログインし、以下のコマンドでOpenLDAPをインストールします。

dev1 ~ # emerge -uvD openldap

OpenLDAPの設定ファイルの作成

次にLDAPサーバの管理者パスワードを生成します。

dev1 ~ # dev1 ~ # slappasswd -h {SSHA} -s パスワード文字列 {SSHA}}xxxxxxxxxxxxxxxxxxxxxxxxxxxx

のように出力されるので、出力結果を記録しておきます。

そして、インストールしたサーバの設定ファイルを編集します。

編集結果は下記のようになります。日本語のコメントは実際には記述していません。 dev1 ~ # cat /etc/openldap/slapd.conf   include /etc/openldap/schema/core.schema include /etc/openldap/schema/cosine.schema include /etc/openldap/schema/inetorgperson.schema include /etc/openldap/schema/nis.schema include /etc/openldap/schema/local.schema   pidfile /var/run/openldap/slapd.pid argsfile /var/run/openldap/slapd.args   database ldbm   # ドメイン example.com 内の情報をこのLDAPサーバで管理する場合の基本となるDN suffix "dc=example,dc=com" # 管理者のDN rootdn "cn=Manager,dc=example,dc=com"   # 管理者のパスワードを記述 rootpw {SSHA}xxxxxxxxxxxxxxxxxxxxxxxxxxxx   directory /var/lib/openldap-data password-hash {SSHA}   # LDAPサーバのインデックスを設定 # eq 等価、pres 存在に関するインデックスを設定する index uidNumber,gidNumber,memberUid,host,cn,objectClass eq index uniqueMember pres index uid eq,pres   # アクセス制限 # userPasswordという属性は、管理者か本人が書き込むことができる。 # それ以外の人はAUTH(認証)にのみuserPasswordを利用できる access to attrs=userPassword by dn="cn=Manager,dc=example,dc=com" write by self write by anonymous auth by * none   # 上記の情報以外は、管理者のみ書き込むことができ、それ以外は読み込みのみ # この設定をしないと、誰でも好き勝手にアカウントを追加したりできてしまう。 # (rootも上書きできちゃいます - -;) access to * by dn="cn=Manager,dc=example,dc=com" write by * read

OpenLDAPの起動

そしておもむろにLDAPサーバを立ち上げます。

dev1 ~ # /etc/init.d/slapd start

OpenLDAPのDNツリーの定義

さて起動を行ったら、次にLDAPのツリー構造を定義します。

LDAPではツールを使ってツリー構造を定義することもありますが、今回はldif形式のテキストファイルでツリー構造を定義し、サーバに登録します。

まず、今回の基本となる構造は下記の通りです。

dn: でツリー構造の位置が指定されています。

dn: cn=Manager,dc=example,dc=comであれば、cn=Managerが葉、dc=exapmeが幹、dc=comが根です。 dev1 ~ # cat example.com.ldif   dn: dc=example,dc=com objectclass: dcObject objectclass: organization dc: example o: example   dn: cn=Manager,dc=example,dc=com objectclass: organizationalRole cn: Manager   dn: ou=Users,dc=example,dc=com objectclass: organizationalUnit ou: Users   dn: ou=Groups,dc=example,dc=com objectclass: organizationalUnit ou: Groups 上記の設定では、cn=Manager,dc=example,dc=comとou=Groups,dc=example,dc=comというノードを作り、ユーザ情報とグループ情報を追加できる構造を定義しています。

次に一人のユーザnishinosonoのグループ情報とユーザ情報の設定をldifで作成します。このファイルはユーザ分だけ作成しておく必要があります。 dev1 ~ # cat nishinosono.ldif   dn: cn=nishinosono,ou=Groups,dc=example,dc=com gidNumber: 2000 userPassword:: e01ENX14 memberUid: nishinosono objectClass: posixGroup objectClass: top cn: nishinosono   dn: uid=nishinosono,ou=Users,dc=example,dc=com objectClass: account objectClass: posixAccount objectClass: top objectClass: shadowAccount cn: nishinosono uid: nishinosono uidNumber: 2000 gidNumber: 2000 homeDirectory: /home/nishinosono gecos: nishinosono loginShell: /bin/zsh userPassword: yyyyyyyyyyyyyy userPassword: のyyyyyyyyyyyyyyの部分には以下のコマンドの結果を記述しておきます。

dev ~ # slappasswd -h {SSHA} -s nishinosonoのパスワード文字列

LDAPへのldifの登録と確認

次にldapaddコマンドでldifをLDAPサーバに追加します。パスワードが聞かれるので、LDAPの管理者のパスワードを入力ます。

dev1 ~ # ldapadd -x -D "cn=Manager,dc=example,dc=com" -W -f example.com.ldif dev1 ~ # ldapadd -x -D "cn=Manager,dc=example,dc=com" -W -f nishinosono.ldif

次にldapsearchコマンドで正しく登録されているかを確認します。パスワードが聞かれるので、LDAPの管理者のパスワードを入力ます。

dev1 ~ # ldapsearch -x -D "cn=Manager,dc=example,dc=com" -LLL -b "uid=nishinosono,ou=users,dc=example,dc=com" -W dev1 ~ # ldapsearch -x -D "cn=Manager,dc=example,dc=com" -LLL -b "cn=nishinosono,ou=groups,dc=example,dc=com" -W これで、LDAPサーバへのアカウント追加までが完了です。

次回

次回は、LDAPをLinuxのユーザアカウントの認証に使う場合の設定を扱いたいと思います。

この記事に関するお問い合わせはこちら

ページの先頭へ