错误=" Ldap搜索匹配多个条目,请查看您的过滤器设置"与Grafana LDAP

时间:2017-05-26 13:16:14

标签: ldap openldap grafana rhel6

我正在使用Grafana 4.2.0。我正在尝试在应用程序中集成LDAP功能。我在LDAP中创建了一个用户ldapuser1,但是当我尝试使用此用户名登录Grafana时,我收到错误为"错误=" Ldap搜索匹配多个条目,请查看您的过滤器设置&# 34;"

来自grafana.log的错误消息如下:

t=2017-05-26T05:59:28-0700 lvl=eror msg="Error while trying to authenticate user" logger=context userId=0 orgId=0 uname= error="Ldap search matched more than one entry, please review your filter setting"
t=2017-05-26T05:59:28-0700 lvl=eror msg="Request Completed" logger=context userId=0 orgId=0 uname= method=POST path=/login status=500 remote_addr=127.0.0.1 time_ms=68ns size=53

请在下面找到ldap.toml文件供您参考

# To troubleshoot and get more log info enable ldap debug logging in grafana.ini
# [log]
verbose_logging = true

# filters = ldap:debug

[[servers]]
# Ldap server host (specify multiple hosts space separated)
host = "127.0.0.1"
# Default port is 389 or 636 if use_ssl = true
port = 389
# Set to true if ldap server supports TLS
use_ssl = false
# Set to true if connect ldap server with STARTTLS pattern (create connection in insecure, then upgrade to secure connection with TLS)
start_tls = false
# set to true if you want to skip ssl cert validation
ssl_skip_verify = false
# set to the path to your root CA certificate or leave unset to use system defaults
# root_ca_cert = /path/to/certificate.crt

# Search user bind dn
bind_dn = "dc=cloudera,dc=com"
# Search user bind password
bind_password = 'cloudera'

# User search filter, for example "(cn=%s)" or "(sAMAccountName=%s)" or "(uid=%s)"
search_filter = "(uid=%s)"

# An array of base dns to search through
search_base_dns = ["dc=cloudera,dc=com"]

# In POSIX LDAP schemas, without memberOf attribute a secondary query must be made for groups.
# This is done by enabling group_search_filter below. You must also set member_of= "cn"
# in [servers.attributes] below.

# Users with nested/recursive group membership and an LDAP server that supports LDAP_MATCHING_RULE_IN_CHAIN
# can set group_search_filter, group_search_filter_user_attribute, group_search_base_dns and member_of
# below in such a way that the user's recursive group membership is considered.
#
# Nested Groups + Active Directory (AD) Example:
#
#   AD groups store the Distinguished Names (DNs) of members, so your filter must
#   recursively search your groups for the authenticating user's DN. For example:
#
#     group_search_filter = "(member:1.2.840.113556.1.4.1941:=%s)"
#     group_search_filter_user_attribute = "distinguishedName"
#     group_search_base_dns = ["ou=groups,dc=grafana,dc=org"]
#
#     [servers.attributes]
#     member_of = "distinguishedName"

## Group search filter, to retrieve the groups of which the user is a member (only set if memberOf attribute is not available)
# group_search_filter = "(&(objectClass=posixGroup)(memberUid=%s))"
## Group search filter user attribute defines what user attribute gets substituted for %s in group_search_filter.
## Defaults to the value of username in [server.attributes]
## Valid options are any of your values in [servers.attributes]
## If you are using nested groups you probably want to set this and member_of in
## [servers.attributes] to "distinguishedName"
# group_search_filter_user_attribute = "distinguishedName"
## An array of the base DNs to search through for groups. Typically uses ou=groups
# group_search_base_dns = ["ou=groups,dc=grafana,dc=org"]

# Specify names of the ldap attributes your ldap uses
[servers.attributes]
name = "ldapuser1"
surname = "ldapuser1"
username = "ldapuser1"
#member_of = "People"
email =  "ldapuser1@cloudera.com"

# Map ldap groups to grafana org roles
[[servers.group_mappings]]
group_dn = "cn=admins,dc=grafana,dc=org"
org_role = "Admin"
# The Grafana organization database id, optional, if left out the default org (id 1) will be used
# org_id = 1

[[servers.group_mappings]]
group_dn = "cn=users,dc=grafana,dc=org"
org_role = "Editor"

[[servers.group_mappings]]
# If you want to match all (or no ldap groups) then you can use wildcard
group_dn = "*"
org_role = "Viewer"

请在下面找到LDAP搜索命令的结果

ldapsearch -x -b "dc=cloudera,dc=com" | less

# extended LDIF
#
# LDAPv3
# base <dc=cloudera,dc=com> with scope subtree
# filter: (objectclass=*)
# requesting: ALL
#

# cloudera.com
dn: dc=cloudera,dc=com
dc: cloudera
objectClass: top
objectClass: domain
objectClass: domainRelatedObject
associatedDomain: cloudera.com

# Hosts, cloudera.com
dn: ou=Hosts,dc=cloudera,dc=com
ou: Hosts
objectClass: top
objectClass: organizationalUnit
objectClass: domainRelatedObject
associatedDomain: cloudera.com

# Rpc, cloudera.com
dn: ou=Rpc,dc=cloudera,dc=com
ou: Rpc
objectClass: top
objectClass: organizationalUnit
objectClass: domainRelatedObject
associatedDomain: cloudera.com

# Services, cloudera.com
dn: ou=Services,dc=cloudera,dc=com
ou: Services
objectClass: top
objectClass: organizationalUnit
objectClass: domainRelatedObject
associatedDomain: cloudera.com

# netgroup.byuser, cloudera.com
dn: nisMapName=netgroup.byuser,dc=cloudera,dc=com
nisMapName: netgroup.byuser
objectClass: top
objectClass: nisMap
objectClass: domainRelatedObject
associatedDomain: cloudera.com

# Mounts, cloudera.com
dn: ou=Mounts,dc=cloudera,dc=com
ou: Mounts
objectClass: top
objectClass: organizationalUnit
associatedDomain: cloudera.com

# Networks, cloudera.com
dn: ou=Networks,dc=cloudera,dc=com
ou: Networks
objectClass: top
objectClass: organizationalUnit
objectClass: domainRelatedObject
associatedDomain: cloudera.com

# People, cloudera.com
dn: ou=People,dc=cloudera,dc=com
ou: People
objectClass: top
objectClass: organizationalUnit
objectClass: domainRelatedObject
associatedDomain: cloudera.com

# Groups, cloudera.com
dn: ou=Groups,dc=cloudera,dc=com
ou: Groups
objectClass: top
objectClass: organizationalUnit
objectClass: domainRelatedObject
associatedDomain: cloudera.com

# Netgroup, cloudera.com
dn: ou=Netgroup,dc=cloudera,dc=com
ou: Netgroup
objectClass: top
objectClass: organizationalUnit
objectClass: domainRelatedObject
associatedDomain: cloudera.com

# Protocols, cloudera.com
dn: ou=Protocols,dc=cloudera,dc=com
ou: Protocols
objectClass: top
objectClass: organizationalUnit
objectClass: domainRelatedObject
associatedDomain: cloudera.com

# Aliases, cloudera.com
dn: ou=Aliases,dc=cloudera,dc=com
ou: Aliases
objectClass: top
objectClass: organizationalUnit
objectClass: domainRelatedObject
associatedDomain: cloudera.com

# netgroup.byhost, cloudera.com
dn: nisMapName=netgroup.byhost,dc=cloudera,dc=com
nisMapName: netgroup.byhost
objectClass: top
objectClass: nisMap
objectClass: domainRelatedObject
associatedDomain: cloudera.com

# ldapuser1, People, cloudera.com
dn: uid=ldapuser1,ou=People,dc=cloudera,dc=com
uid: ldapuser1
cn: ldapuser1
sn: ldapuser1
mail: ldapuser1@cloudera.com
objectClass: person
objectClass: organizationalPerson
objectClass: inetOrgPerson
objectClass: posixAccount
objectClass: top
objectClass: shadowAccount
userPassword:: e2NyeXB0fSQ2JHUxVTE3SnR4JEN1a05HeEZXYmIyOG9NckRyRkpJeEQuR3ZjYmd
 jWXd2WFlrMGtTRE1YZW9zOEZVSVE3dUdYdkxsS3E3aTd5MnVIS1lpSnEzZnU5N0paWmE0SWlZNUcx
shadowLastChange: 17309
shadowMin: 0
shadowMax: 99999
shadowWarning: 7
loginShell: /bin/bash
uidNumber: 502
gidNumber: 504
homeDirectory: /home/guests/ldapuser1

# ldapuser2, People, cloudera.com
dn: uid=ldapuser2,ou=People,dc=cloudera,dc=com
uid: ldapuser2
cn: ldapuser2
sn: ldapuser2
mail: ldapuser2@cloudera.com
objectClass: person
objectClass: organizationalPerson
objectClass: inetOrgPerson
objectClass: posixAccount
objectClass: top
objectClass: shadowAccount
userPassword:: e2NyeXB0fSQ2JFplS3VyRllaJG9VSmVGNktTRThiQWZWem1rVk8wMGNGUjQyUWt
 oT0ZuZVpVc1IzUG51c0R2eXZubXJEN3dDU2tPOC9sb2dIeHRSSGxZVVp3dTlIZXpEd3QxVHhKRjAw
shadowLastChange: 17309
shadowMin: 0
shadowMax: 99999
shadowWarning: 7
loginShell: /bin/bash
uidNumber: 503
gidNumber: 505
homeDirectory: /home/guests/ldapuser2

# ldapuser1, Groups, cloudera.com
dn: cn=ldapuser1,ou=Groups,dc=cloudera,dc=com
objectClass: posixGroup
objectClass: top
cn: ldapuser1
userPassword:: e2NyeXB0fXg=
gidNumber: 504

# ldapuser2, Groups, cloudera.com
dn: cn=ldapuser2,ou=Groups,dc=cloudera,dc=com
objectClass: posixGroup
objectClass: top
cn: ldapuser2
userPassword:: e2NyeXB0fXg=
gidNumber: 505

# search result
search: 2
result: 0 Success

# numResponses: 18
# numEntries: 17 

我正在使用本地OpenLDAP服务器。我无法找出问题的根本原因。我是LDAP新手并且是第一次配置它。

2 个答案:

答案 0 :(得分:0)

您分别有两个ldapuser1和ldapuser2条目(每个用户一个用户和一个组)。当您在cn = ldapuser1上搜索时,openldap无法区分这两个条目,即使它们具有不同的dns。您需要搜索所有条目中唯一的内容。

我看到两个选项:

1)搜索唯一属性,例如uid。这将找到uid = ldapuser1,ou = People,dc = cloudera,dc = com但不是cn = ldapuser1,ou = Groups,dc = cloudera,dc = com,因为该组没有uid。

2)将搜索过滤器更改为仅包括用户,例如。 (及(objectClass的=为inetOrgPerson)(CN =%S))

答案 1 :(得分:0)

第一个问题似乎是您的Grafana LDAP配置。让我们自上而下地浏览您的TOML文件。

绑定请求用于启动LDAP服务器的身份验证。对于简单绑定,我们需要用户的可分辨名称(dn)和密码。由于您希望允许用户显示用户标识符(uid)而不是可分辨名称,因此Grafana必须通过搜索目录将uid映射到dn。 bind-dn是指Grafana将用于检索身份验证用户的可分辨名称(dn)的用户帐户。这绝对不是命名上下文dc=cloudera,dc=com,而是现有的用户条目。

部分servers.attributes允许您将Grafana内部名称映射到实际的LDAP属性类型名称。即使您没有将givenName添加到您的用户条目,我建议您遵循映射,但是:

name = givenName
surname = sn
username = uid
email = mail

组映射用于用户授权。每个group_dn必须引用目录中的现有用户组。一个小组的成员被分配了某个预定义的Grafana角色。您的样本组有点无用,因为它们会遗漏任何成员属性。

另外,请务必将您的group_dn(...,dc = grafana,dc = org)调整为您的LDAP上下文(dc = cloudera,dc = com)。