Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
N
nexpie-grafana-theme
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Registry
Registry
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kornkitt Poolsup
nexpie-grafana-theme
Commits
85751d98
Unverified
Commit
85751d98
authored
Mar 06, 2019
by
Torkel Ödegaard
Committed by
GitHub
Mar 06, 2019
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #15803 from grafana/15643_fix
fix allow anonymous initial bind for ldap search
parents
2039278a
3b9f0e6e
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
93 additions
and
4 deletions
+93
-4
pkg/login/ldap.go
+12
-1
pkg/login/ldap_test.go
+81
-3
No files found.
pkg/login/ldap.go
View file @
85751d98
...
...
@@ -18,6 +18,7 @@ import (
type
ILdapConn
interface
{
Bind
(
username
,
password
string
)
error
UnauthenticatedBind
(
username
string
)
error
Search
(
*
ldap
.
SearchRequest
)
(
*
ldap
.
SearchResult
,
error
)
StartTLS
(
*
tls
.
Config
)
error
Close
()
...
...
@@ -259,7 +260,17 @@ func (a *ldapAuther) initialBind(username, userPassword string) error {
bindPath
=
fmt
.
Sprintf
(
a
.
server
.
BindDN
,
username
)
}
if
err
:=
a
.
conn
.
Bind
(
bindPath
,
userPassword
);
err
!=
nil
{
bindFn
:=
func
()
error
{
return
a
.
conn
.
Bind
(
bindPath
,
userPassword
)
}
if
userPassword
==
""
{
bindFn
=
func
()
error
{
return
a
.
conn
.
UnauthenticatedBind
(
bindPath
)
}
}
if
err
:=
bindFn
();
err
!=
nil
{
a
.
log
.
Info
(
"Initial bind failed"
,
"error"
,
err
)
if
ldapErr
,
ok
:=
err
.
(
*
ldap
.
Error
);
ok
{
...
...
pkg/login/ldap_test.go
View file @
85751d98
...
...
@@ -13,6 +13,70 @@ import (
)
func
TestLdapAuther
(
t
*
testing
.
T
)
{
Convey
(
"initialBind"
,
t
,
func
()
{
Convey
(
"Given bind dn and password configured"
,
func
()
{
conn
:=
&
mockLdapConn
{}
var
actualUsername
,
actualPassword
string
conn
.
bindProvider
=
func
(
username
,
password
string
)
error
{
actualUsername
=
username
actualPassword
=
password
return
nil
}
ldapAuther
:=
&
ldapAuther
{
conn
:
conn
,
server
:
&
LdapServerConf
{
BindDN
:
"cn=%s,o=users,dc=grafana,dc=org"
,
BindPassword
:
"bindpwd"
,
},
}
err
:=
ldapAuther
.
initialBind
(
"user"
,
"pwd"
)
So
(
err
,
ShouldBeNil
)
So
(
ldapAuther
.
requireSecondBind
,
ShouldBeTrue
)
So
(
actualUsername
,
ShouldEqual
,
"cn=user,o=users,dc=grafana,dc=org"
)
So
(
actualPassword
,
ShouldEqual
,
"bindpwd"
)
})
Convey
(
"Given bind dn configured"
,
func
()
{
conn
:=
&
mockLdapConn
{}
var
actualUsername
,
actualPassword
string
conn
.
bindProvider
=
func
(
username
,
password
string
)
error
{
actualUsername
=
username
actualPassword
=
password
return
nil
}
ldapAuther
:=
&
ldapAuther
{
conn
:
conn
,
server
:
&
LdapServerConf
{
BindDN
:
"cn=%s,o=users,dc=grafana,dc=org"
,
},
}
err
:=
ldapAuther
.
initialBind
(
"user"
,
"pwd"
)
So
(
err
,
ShouldBeNil
)
So
(
ldapAuther
.
requireSecondBind
,
ShouldBeFalse
)
So
(
actualUsername
,
ShouldEqual
,
"cn=user,o=users,dc=grafana,dc=org"
)
So
(
actualPassword
,
ShouldEqual
,
"pwd"
)
})
Convey
(
"Given empty bind dn and password"
,
func
()
{
conn
:=
&
mockLdapConn
{}
unauthenticatedBindWasCalled
:=
false
var
actualUsername
string
conn
.
unauthenticatedBindProvider
=
func
(
username
string
)
error
{
unauthenticatedBindWasCalled
=
true
actualUsername
=
username
return
nil
}
ldapAuther
:=
&
ldapAuther
{
conn
:
conn
,
server
:
&
LdapServerConf
{},
}
err
:=
ldapAuther
.
initialBind
(
"user"
,
"pwd"
)
So
(
err
,
ShouldBeNil
)
So
(
ldapAuther
.
requireSecondBind
,
ShouldBeTrue
)
So
(
unauthenticatedBindWasCalled
,
ShouldBeTrue
)
So
(
actualUsername
,
ShouldBeEmpty
)
})
})
Convey
(
"When translating ldap user to grafana user"
,
t
,
func
()
{
...
...
@@ -365,12 +429,26 @@ func TestLdapAuther(t *testing.T) {
}
type
mockLdapConn
struct
{
result
*
ldap
.
SearchResult
searchCalled
bool
searchAttributes
[]
string
result
*
ldap
.
SearchResult
searchCalled
bool
searchAttributes
[]
string
bindProvider
func
(
username
,
password
string
)
error
unauthenticatedBindProvider
func
(
username
string
)
error
}
func
(
c
*
mockLdapConn
)
Bind
(
username
,
password
string
)
error
{
if
c
.
bindProvider
!=
nil
{
return
c
.
bindProvider
(
username
,
password
)
}
return
nil
}
func
(
c
*
mockLdapConn
)
UnauthenticatedBind
(
username
string
)
error
{
if
c
.
unauthenticatedBindProvider
!=
nil
{
return
c
.
unauthenticatedBindProvider
(
username
)
}
return
nil
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment