Skip to content

Commit d3b0905

Browse files
ericpptorkelo
authored andcommitted
Added allow_sign_up setting to auth.ldap to be able to disable automatic user creation for LDAP logins (grafana#6191)
1 parent 7e6595a commit d3b0905

File tree

4 files changed

+10
-3
lines changed

4 files changed

+10
-3
lines changed

conf/defaults.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,7 @@ auto_sign_up = true
267267
[auth.ldap]
268268
enabled = false
269269
config_file = /etc/grafana/ldap.toml
270+
allow_sign_up = true
270271

271272
#################################### SMTP / Emailing #####################
272273
[smtp]

conf/sample.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,7 @@
252252
[auth.ldap]
253253
;enabled = false
254254
;config_file = /etc/grafana/ldap.toml
255+
;allow_sign_up = true
255256

256257
#################################### SMTP / Emailing ##########################
257258
[smtp]

pkg/login/ldap.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
"github.com/grafana/grafana/pkg/bus"
1414
"github.com/grafana/grafana/pkg/log"
1515
m "github.com/grafana/grafana/pkg/models"
16+
"github.com/grafana/grafana/pkg/setting"
1617
)
1718

1819
type ldapAuther struct {
@@ -132,8 +133,10 @@ func (a *ldapAuther) getGrafanaUserFor(ldapUser *ldapUserInfo) (*m.User, error)
132133
// get user from grafana db
133134
userQuery := m.GetUserByLoginQuery{LoginOrEmail: ldapUser.Username}
134135
if err := bus.Dispatch(&userQuery); err != nil {
135-
if err == m.ErrUserNotFound {
136+
if err == m.ErrUserNotFound && setting.LdapAllowSignup {
136137
return a.createGrafanaUser(ldapUser)
138+
} else if err == m.ErrUserNotFound {
139+
return nil, ErrInvalidCredentials
137140
} else {
138141
return nil, err
139142
}

pkg/setting/setting.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,8 +134,9 @@ var (
134134
GoogleTagManagerId string
135135

136136
// LDAP
137-
LdapEnabled bool
138-
LdapConfigFile string
137+
LdapEnabled bool
138+
LdapConfigFile string
139+
LdapAllowSignup bool = true
139140

140141
// SMTP email settings
141142
Smtp SmtpSettings
@@ -551,6 +552,7 @@ func NewConfigContext(args *CommandLineArgs) error {
551552
ldapSec := Cfg.Section("auth.ldap")
552553
LdapEnabled = ldapSec.Key("enabled").MustBool(false)
553554
LdapConfigFile = ldapSec.Key("config_file").String()
555+
LdapAllowSignup = ldapSec.Key("allow_sign_up").MustBool(true)
554556

555557
alerting := Cfg.Section("alerting")
556558
AlertingEnabled = alerting.Key("enabled").MustBool(false)

0 commit comments

Comments
 (0)