0
votes

I am using Grafana 4.2.0. I am trying to integrate LDAP functionality in the application. I have a user ldapuser1 created in LDAP but when I try to login to Grafana using this username, I am getting the error as "error="Ldap search matched more than one entry, please review your filter setting""

The error message from grafana.log follows :

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

Please find below the ldap.toml file for your reference

# 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 =  "[email protected]"

# 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"

Please also find below the result from LDAP Search command as well

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: [email protected]
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: [email protected]
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 

I am using local OpenLDAP server. I am not able to figure out the root cause of the issue. I am new to LDAP and configuring it for the first time.

2

2 Answers

0
votes

You have two ldapuser1 and ldapuser2 entries respectively (one user and one group for each). When you search on cn=ldapuser1, there is no way for openldap to distinguish between the two entries, even though they have different dns. You need to search on something that is unique among all entries.

I see two options:

1) Search on a unique attribute, like uid. This will find uid=ldapuser1,ou=People,dc=cloudera,dc=com but not cn=ldapuser1,ou=Groups,dc=cloudera,dc=com because the group doesn't have a uid.

2) Change the search filter to only include Users, eg. (&(objectClass=inetOrgPerson)(cn=%s))

0
votes

The first problem seems to be your Grafana LDAP configuration. Let's walk through your TOML file top-down.

A Bind request is used to initiate authentication by an LDAP server. For a Simple Bind we need the distinguished name (dn) of a user and a password. Since you want to allow users to present a user identifier (uid) instead of the distinguished name, Grafana must map the uid to a dn by searching the directory. bind-dn refers to a user account Grafana will use to retrieve the distinguished name (dn) of an authenticating user. This is definitely not the Naming Context dc=cloudera,dc=com but an existing user entry.

Section servers.attributes allows you to map Grafana internal names to actual LDAP attributetype names. I suggest following mappings even though you didn't add givenName to your user entries, yet:

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

The group mappings are for user authorization. Each group_dnmust refer to an existing user group in the directory. Members of a group are asssigned a certain predefined Grafana role. Your sample groups are kind of useless, since they miss any member attribute.

Also, make sure to adjust your group_dn's (...,dc=grafana,dc=org) to your LDAP context (dc=cloudera,dc=com).