Karaf w / LDAP Auth

时间:2017-07-31 22:13:59

标签: authentication ldap apache-karaf jaas

我正在尝试设置karaf(4.0.9)以通过ldap / active目录对用户进行身份验证/授权。

我已根据https://karaf.apache.org/manual/latest/#_available_realm_and_login_modules将以下ldap-module.xml复制到deploy目录:

<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
  xmlns:jaas="http://karaf.apache.org/xmlns/jaas/v1.0.0"
  xmlns:ext="http://aries.apache.org/blueprint/xmlns/blueprint-ext/v1.0.0">

  <jaas:config name="karaf" rank="1">
    <jaas:module className="org.apache.karaf.jaas.modules.ldap.LDAPLoginModule" flags="sufficient">
      initialContextFactory=com.sun.jndi.ldap.LdapCtxFactory
      connection.username=cn=ldapsearch,cn=users,dc=eng,dc=net
      connection.password=****
      connection.protocol=
      connection.url=ldap://server:389
      user.base.dn=dc=eng,dc=net
      user.filter=(samaccountname=%u)
      user.search.subtree=true
      user.debug=true
      role.base.dn=dc=eng,dc=net
      role.name.attribute=cn
      role.filter=(member=%fqdn)
      role.search.subtree=true
      role.mapping=jtAdmins=admin,user,operator
      authentication=simple
      debug=true
    </jaas:module>
  </jaas:config>

</blueprint>

我看到日志,我可以在领域看到LDAP登录,所以我确信配置至少被使用

karaf@root(jaas)> jaas:realm-list
Index | Realm Name | Login Module Class Name
-----------------------------------------------------------------------
1     | karaf      | org.apache.karaf.jaas.modules.ldap.LDAPLoginModule

当我尝试ssh时,我得到以下日志(截断),我可以看到鲨鱼LDAP通信:

2017-07-31 16:50:39,229 | DEBUG | 8]-nio2-thread-9 | LDAPLoginModule                  | 35 - org.apache.karaf.jaas.modules - 4.0.9 | Get the user DN.
2017-07-31 16:50:39,238 | DEBUG | 8]-nio2-thread-9 | LDAPLoginModule                  | 35 - org.apache.karaf.jaas.modules - 4.0.9 | Looking for the user in LDAP with 
2017-07-31 16:50:39,238 | DEBUG | 8]-nio2-thread-9 | LDAPLoginModule                  | 35 - org.apache.karaf.jaas.modules - 4.0.9 |   base DN: dc=eng,dc=net
2017-07-31 16:50:39,238 | DEBUG | 8]-nio2-thread-9 | LDAPLoginModule                  | 35 - org.apache.karaf.jaas.modules - 4.0.9 |   filter: (samaccountname=jtAdmin)
2017-07-31 16:50:39,244 | DEBUG | 8]-nio2-thread-9 | LDAPLoginModule                  | 35 - org.apache.karaf.jaas.modules - 4.0.9 | Found the user DN.
2017-07-31 16:50:39,245 | DEBUG | 8]-nio2-thread-9 | LDAPLoginModule                  | 35 - org.apache.karaf.jaas.modules - 4.0.9 | Bind user (authentication).
2017-07-31 16:50:39,245 | DEBUG | 8]-nio2-thread-9 | LDAPLoginModule                  | 35 - org.apache.karaf.jaas.modules - 4.0.9 | Set the security principal for CN=jtAdmin,CN=Users,dc=eng,dc=net
2017-07-31 16:50:39,245 | DEBUG | 8]-nio2-thread-9 | LDAPLoginModule                  | 35 - org.apache.karaf.jaas.modules - 4.0.9 | Binding the user.
2017-07-31 16:50:39,254 | DEBUG | 8]-nio2-thread-9 | LDAPLoginModule                  | 35 - org.apache.karaf.jaas.modules - 4.0.9 | User jtAdmin successfully bound.
2017-07-31 16:50:39,256 | DEBUG | 8]-nio2-thread-9 | LDAPLoginModule                  | 35 - org.apache.karaf.jaas.modules - 4.0.9 | Looking for the user roles in LDAP with 
2017-07-31 16:50:39,256 | DEBUG | 8]-nio2-thread-9 | LDAPLoginModule                  | 35 - org.apache.karaf.jaas.modules - 4.0.9 |   base DN: dc=eng,dc=net
2017-07-31 16:50:39,256 | DEBUG | 8]-nio2-thread-9 | LDAPLoginModule                  | 35 - org.apache.karaf.jaas.modules - 4.0.9 |   filter: (member=CN=jtAdmin,CN=Users,DC=eng,DC=net)
2017-07-31 16:50:39,359 | DEBUG | 8]-nio2-thread-9 | LDAPLoginModule                  | 35 - org.apache.karaf.jaas.modules - 4.0.9 | User jtAdmin is a member of role Domain Computers
2017-07-31 16:50:39,359 | DEBUG | 8]-nio2-thread-9 | LDAPLoginModule                  | 35 - org.apache.karaf.jaas.modules - 4.0.9 | Parse role mapping jtAdmin=admin,user,operator
2017-07-31 16:50:39,359 | DEBUG | 8]-nio2-thread-9 | LDAPLoginModule                  | 35 - org.apache.karaf.jaas.modules - 4.0.9 | Parse role mapping jtAdmin=admin,user,operator
2017-07-31 16:50:39,359 | DEBUG | 8]-nio2-thread-9 | LDAPLoginModule                  | 35 - org.apache.karaf.jaas.modules - 4.0.9 | User jtAdmin is a member of role Domain Controllers

...

2017-07-31 16:50:39,364 | DEBUG | 8]-nio2-thread-9 | LDAPLoginModule                  | 35 - org.apache.karaf.jaas.modules - 4.0.9 | Parse role mapping jtAdmins=admin,user,operator
2017-07-31 16:50:39,364 | DEBUG | 8]-nio2-thread-9 | LDAPLoginModule                  | 35 - org.apache.karaf.jaas.modules - 4.0.9 | Parse role mapping jtAdmins=admin,user,operator
2017-07-31 16:50:39,364 | DEBUG | 8]-nio2-thread-9 | LDAPLoginModule                  | 35 - org.apache.karaf.jaas.modules - 4.0.9 | LDAP role jtAdmins is mapped to Karaf role admin
2017-07-31 16:50:39,364 | DEBUG | 8]-nio2-thread-9 | LDAPLoginModule                  | 35 - org.apache.karaf.jaas.modules - 4.0.9 | LDAP role jtAdmins is mapped to Karaf role user
2017-07-31 16:50:39,365 | DEBUG | 8]-nio2-thread-9 | LDAPLoginModule                  | 35 - org.apache.karaf.jaas.modules - 4.0.9 | LDAP role jtAdmins is mapped to Karaf role operator

我可以看到LDAP授权我的用户,但似乎我没有登录权限。我认为role.mapping会处理将我的LDAP / AD成员映射到Karaf角色,但这似乎不允许我访问。 Web控制台也尝试允许访问,但最终失败。

我缺少哪些配置来映射LDAP / AD用户角色以为我的用户启用ssh karaf / console?我需要另一个登录模块吗?我怎么能动态地这样做(不在ldap-module.xml包中使用硬编码的role.mapping)?

理想情况下,我也希望能够同时为ldap OR本地用户提供访问权限,但我意识到这可能是不可能的。

1 个答案:

答案 0 :(得分:0)

幸运的是,我设法追查根本原因。感谢karaf IRC频道上的人们让我大声思考。

最终,我认为根本原因是这个例外:

javax.naming.PartialResultException: Unprocessed Continuation Reference(s); remaining name ...

我实际上只在webconsole处理程序中看到此异常,而不是在ssh / shell处理程序中(但ssh也不起作用,所以......)

异常来自LDAPCache.java(namingEnumeration.hasMore(),〜第259行),最终来自

at com.sun.jndi.ldap.LdapCtx.processReturnCode(LdapCtx.java:2914)
    at com.sun.jndi.ldap.LdapCtx.processReturnCode(LdapCtx.java:2888)

此异常传播给调用者。由于我不能很好地改变JVM,我正在借用一个建议/解决方案,将ignore选项添加到ignorePartialNameResult中。我不太明白为什么会有部分名称结果,但我看到一条评论暗示错误是由于role.base.dn与user.base.dn处于同一级别,这在我的情况下是正确的。捕获异常并返回现有的roleList后,我能够成功登录w / ldap用户。