LDAP認証が突然通らなくなる

Apache 2.4
mod_ldap
mod_authnz_ldap
mod_dav_svn
mod_authz_svn
OpenLDAP 2.4.40
docker


SVNサーバーを立て、LDAPで認証をしている。
普段は問題なく認証できているが、たまに突然認証が通らなくなることがある。
通らなくなったときは何回か認証を試すか、しばらく時間を置くか、SVNサーバーかLDAPサーバーを再起動すると認証が通るようになる。


認証が通らないときのApache側のログはこんな感じ。

[Tue Feb 14 05:22:26.513073 2017] [authz_core:debug] [pid 8] mod_authz_core.c(809): [client 172.18.0.7:36152] AH01626: authorization result of Require valid-user : denied (no authenticated user yet)
[Tue Feb 14 05:22:26.513113 2017] [authz_core:debug] [pid 8] mod_authz_core.c(809): [client 172.18.0.7:36152] AH01626: authorization result of : denied (no authenticated user yet)
[Tue Feb 14 05:22:26.513548 2017] [authz_core:debug] [pid 8] mod_authz_core.c(809): [client 172.18.0.7:36152] AH01626: authorization result of Require valid-user : denied (no authenticated user yet)
[Tue Feb 14 05:22:26.513566 2017] [authz_core:debug] [pid 8] mod_authz_core.c(809): [client 172.18.0.7:36152] AH01626: authorization result of : denied (no authenticated user yet)
[Tue Feb 14 05:22:26.513577 2017] [authnz_ldap:debug] [pid 8] mod_authnz_ldap.c(501): [client 172.18.0.7:36152] AH01691: auth_ldap authenticate: using URL ldap://ldap:389/ou=People,dc=example,dc=org?cn
[Tue Feb 14 05:22:26.514094 2017] [authnz_ldap:debug] [pid 8] mod_authnz_ldap.c(539): [client 172.18.0.7:36152] AH01694: auth_ldap authenticate: user xxxxxx authentication failed; URI /svn/XXXXXX/trunk [ldap_search_ext_s() for user failed][No such object] (not authoritative)
[Tue Feb 14 05:22:26.514113 2017] [auth_basic:error] [pid 8] [client 172.18.0.7:36152] AH01618: user xxxxxx not found: /svn/XXXXXX/trunk

OpenLDAP側はこんな感じ。

58a640c6 conn=1000 fd=17 ACCEPT from IP=172.18.0.5:40588 (IP=0.0.0.0:389)
58a640c6 conn=1000 op=0 BIND dn="cn=admin,dc=example,dc=org" method=128
58a640c6 conn=1000 op=0 BIND dn="cn=admin,dc=example,dc=org" mech=SIMPLE ssf=0
58a640c6 conn=1000 op=0 RESULT tag=97 err=0 text=
58a640c6 conn=1000 op=1 SRCH base="ou=People,dc=example,dc=org" scope=2 deref=3 filter="(&(objectClass=*)(cn=xxxxxx))"
58a640c6 conn=1000 op=1 SRCH attr=cn
58a640c6 <= bdb_equality_candidates: (cn) not indexed
58a640c6 conn=1000 op=1 SEARCH RESULT tag=101 err=0 nentries=1 text=
58a640c6 conn=1000 op=2 BIND anonymous mech=implicit ssf=0
58a640c6 conn=1000 op=2 BIND dn="cn=xxxxxx,ou=People,dc=example,dc=org" method=128
58a640c6 conn=1000 op=2 BIND dn="cn=xxxxxx,ou=People,dc=example,dc=org" mech=SIMPLE ssf=0
58a640c6 conn=1000 op=2 RESULT tag=97 err=0 text=
58a640c6 conn=1000 op=3 SRCH base="ou=People,dc=example,dc=org" scope=2 deref=3 filter="(&(objectClass=*)(cn=xxxxxx))"
58a640c6 conn=1000 op=3 SRCH attr=cn
58a640c6 conn=1000 op=3 SEARCH RESULT tag=101 err=32 nentries=0 text=


1回目のアクセスがop=0〜op=2で、これは認証が成功する。
2回目のアクセスがop=3で、ここで認証が通らなくなる。
この間、コネクションが切られずに使いまわされている。
(この環境にはRedmineとかphpLDAPadminとかもいて、このLDAPサーバーを使うようにしているが、こいつらはコネクションを切る)
それになぜかop=2でバインドし直している。
mod_authnz_ldapの"The Authorization Phase"とかAuthLDAPInitialBindAsUserとかAuthLDAPCompareAsUserあたりの内容が関係ありそうだが、よくはわからない。
ともかく、dn="cn=xxxxxx,ou=People,dc=example,dc=org"はbase="ou=People,dc=example,dc=org"にアクセスする権限がなくてこうなってしまうのであろう。


こんなとっくの昔に枯れていそうな構成でバグが残っているのは不自然だから、自分の設定に何か問題があるのだろうけど、よくはわからない。


    DAV svn
    SVNParentPath /svn
    AuthType Basic
    AuthBasicProvider ldap
    AuthLDAPBindAuthoritative off
    AuthLDAPURL ldap://ldap:389/ou=People,dc=example,dc=org?cn
    AuthLDAPBindDN "cn=admin,dc=example,dc=org"
    AuthLDAPBindPassword "admin"
    AuthName "Auth for XXXXXX"
    Require valid-user


さしあたってはコネクションを切るようにすれば良いだろう。
の外側に下記を追加する。

LDAPConnectionPoolTTL 0