今回はOpenLDAPにおけるアクセス管理についてお話ししたいと思います。コンピュータの世界でファイルやDBにアクセス権という概念が存在するように、
/etc/
- あるユーザは他のユーザのuserPassword属性を得ることはできない。
他ユーザのエントリを変更することもできない。 - ただし自分のエントリであれば自由に参照、
変更することができる
これ以外の例として、
- 特定のIPアドレスからであれば読み書き可能、
それ以外からはリードオンリー - mail属性が登録されているユーザからであれば読み取り可能、
それ以外からは参照不可能
slapd.confとACL
アクセスコントロールはおなじみのslapd.
access to <what> [ by <who> <access> [ <control> ] ]+
まずは単純な設定を見てみましょう。
access to dn.subtree="ou=People,dc=example,dc=com"
by * read
この設定は、ou=People,dc=example,dc=com
以下のサブツリーに対して、
access to dn.subtree="ou=People,dc=example,dc=com" by * read
と設定することも可能です。
先ほどのwhatフィールドに設定できる項目は、
whoフィールドについては、
accessフィールドでは読み込みや書き込みなどの実際の挙動を設定します。具体的にはnone, disclose, auth, compare, search, read, writeという設定を行うことができますので、
none | なし |
disclose | なし |
auth | 認証の許可 |
compare | 比較の許可 |
search | 検索の許可 |
read | 読み込みの許可 |
write | 読み書きの許可 |
ちなみに、
最後に、
access to dn.subtree="dc=example,dc=com"
by * none
by peername.ip=127.0.0.1 write
という設定の場合、
access to dn.subtree="dc=example,dc=com"
by * none continue
by peername.ip=127.0.0.1 write
という設定を行っておけば、
ちなみに、
access to dn.subtree="dc=example,dc=com"
by peername.ip=127.0.0.1 write
by * none
という設定を行っておけば、
access to dn.subtree="dc=example,dc=com"
by * none
access to dn.subtree="dc=example,dc=com"
by * read
という設定が存在した場合、
access to dn.subtree="dc=example,dc=com"
by * none break
access to dn.subtree="dc=example,dc=com"
by * read
という設定の場合、
実践: ACL設定
再びUNIXアカウントの例ですが、
access to dn.subtree="ou=People,dc=example,dc=com"
by dn.exact="cn=useradmin,ou=People,dc=example,dc=com" write
by * read
by anonymous auth
ACLとuserPassword属性
冒頭で説明しましたように、
# userPassword属性に対する設定
access to dn.subtree="ou=People,dc=example,dc=com" attrs=userPassword
by dn.exact="cn=useradmin,ou=People,dc=example,dc=com" write
by self write
by anonymous auth
# それ以外に対する設定
access to dn.subtree="ou=People,dc=example,dc=com"
by dn.exact="cn=useradmin,ou=People,dc=example,dc=com" write
by * read
by anonymous auth
さて、ou=People,dc=example,dc=com
というツリー以下で設定を行ってきましたが、ou=Group,dc=example,dc=com
というツリーの下に保存されるはずです。従ってこのツリーにもACL設定を行わなければなりません。
# ou=People: userPassword属性に対する設定
access to dn.subtree="ou=People,dc=example,dc=com" attrs=userPassword
by dn.exact="cn=useradmin,ou=People,dc=example,dc=com" write
by self write
by anonymous auth
# ou=People: それ以外に対する設定
access to dn.subtree="ou=People,dc=example,dc=com"
by dn.exact="cn=useradmin,ou=People,dc=example,dc=com" write
by * read
by anonymous auth
# ou=Group: userPassword属性に対する設定
access to dn.subtree="ou=Group,dc=example,dc=com" attrs=userPassword
by dn.exact="cn=useradmin,ou=People,dc=example,dc=com" write
by self write
by anonymous auth
# ou=Group: それ以外に対する設定
access to dn.subtree="ou=Group,dc=example,dc=com"
by dn.exact="cn=useradmin,ou=People,dc=example,dc=com" write
by * read
by anonymous auth
このように、
# userPassword属性に対する設定
access to dn.regex="ou=(People|Group),dc=example,dc=com$" attrs=userPassword
by dn.exact="cn=useradmin,ou=People,dc=example,dc=com" write
by self write
by anonymous auth
# それ以外に対する設定
access to dn.regex="ou=(People|Group),dc=example,dc=com$"
by dn.exact="cn=useradmin,ou=People,dc=example,dc=com" write
by * read
by anonymous auth
このように、
もう一歩進んだ正規表現ルール
次のように、
cn=suzuki, ou=People, o=Sales, dc=example, dc=com
cn=useradmin, ou=People, o=Sales, dc=example, dc=com
cn=tanaka, ou=People, o=Support, dc=example, dc=com
cn=useradmin, ou=People, o=Support, dc=example, dc=com
この場合の正規表現を用いたACLは次のようになります。$1を使って正規表現の後方参照を使っているところがミソです。つまり、
o=任意の文字列A,dc=example,dc=com
以下のツリーを変更可能なのは
cn=useradmin,ou=People,o=任意の文字列A,dc=example,dc=comという設定を実現することができるのです。
# userPassword
access to dn.regex="o=([^,]+),dc=example,dc=com$" attrs=userPassword
by dn.regex="cn=useradmin,ou=People,o=$1,dc=example,dc=com" write
by self write
by anonymous auth
# others
access to dn.regex="o=([^,]+),dc=example,dc=com$"
by dn.regex="cn=useradmin,ou=People,o=$1,dc=example,dc=com" write
by * read
by anonymous auth
まとめ
単にディレクトリサービスを提供するのは簡単ですが、
例えば、