Skip to content

Commit 1b8b6f9

Browse files
committed
Case sensitive login fix
If the backend Keystone is case-insensitive (perhaps using AD for authentication) then we could end up with several users in Grafana, one for each combination of upper & lowercase chars in the username. This fix always uses the username returned in the Keystone response as the username for Grafana, regardless of the case used in the login screen.
1 parent 66316d7 commit 1b8b6f9

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

pkg/api/keystone/keystone_requests.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,7 @@ func authenticate(data *Auth_data, b []byte) error {
220220
data.Expiration = auth_response.Token.Expires_at
221221
data.Roles = auth_response.Token.Roles
222222
data.DomainId = auth_response.Token.User.Domain.Id
223+
data.Username = auth_response.Token.User.Name
223224

224225
return nil
225226
}

pkg/login/keystone.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ func (a *keystoneAuther) login(query *LoginUserQuery) error {
3737

3838
log.Trace("perform initial authentication")
3939
// perform initial authentication
40-
if err := a.authenticate(query.Username, query.Password); err != nil {
40+
if err := a.authenticate(query); err != nil {
4141
return err
4242
}
4343

@@ -56,19 +56,20 @@ func (a *keystoneAuther) login(query *LoginUserQuery) error {
5656

5757
}
5858

59-
func (a *keystoneAuther) authenticate(username, password string) error {
60-
user, _ := keystone.UserDomain(username)
59+
func (a *keystoneAuther) authenticate(query *LoginUserQuery) error {
60+
user, _ := keystone.UserDomain(query.Username)
6161
auth := keystone.Auth_data{
6262
Server: a.server,
6363
Username: user,
64-
Password: password,
64+
Password: query.Password,
6565
Domain: a.domainname,
6666
}
6767
if err := keystone.AuthenticateUnscoped(&auth); err != nil {
6868
return err
6969
}
7070
a.token = auth.Token
7171
a.domainId = auth.DomainId
72+
query.Username = auth.Username // in case the actual username is a different case
7273
return nil
7374
}
7475

0 commit comments

Comments
 (0)