Admin: Add support to configure default admin email (#54363)

This commit is contained in:
mhuangwm 2022-09-07 08:38:40 -04:00 committed by GitHub
parent 687b0b1726
commit 39102c6656
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 9 additions and 1 deletions

View File

@ -247,6 +247,9 @@ admin_user = admin
# default admin password, can be changed before first start of grafana, or in profile settings
admin_password = admin
# default admin email, created on startup
admin_email = admin@localhost
# used for signing
secret_key = SW2YcwTIb9zpOOhoPsMm

View File

@ -247,6 +247,9 @@
# default admin password, can be changed before first start of grafana, or in profile settings
;admin_password = admin
# default admin email, created on startup
;admin_email = admin@localhost
# used for signing
;secret_key = SW2YcwTIb9zpOOhoPsMm

View File

@ -208,7 +208,7 @@ func (ss *SQLStore) ensureMainOrgAndAdminUser() error {
ss.log.Debug("Creating default admin user")
if _, err := ss.createUser(ctx, sess, user.CreateUserCommand{
Login: ss.Cfg.AdminUser,
Email: ss.Cfg.AdminUser + "@localhost",
Email: ss.Cfg.AdminEmail,
Password: ss.Cfg.AdminPassword,
IsAdmin: true,
}); err != nil {

View File

@ -293,6 +293,7 @@ type Cfg struct {
BasicAuthEnabled bool
AdminUser string
AdminPassword string
AdminEmail string
// AWS Plugin Auth
AWSAllowedAuthProviders []string
@ -1254,6 +1255,7 @@ func readSecuritySettings(iniFile *ini.File, cfg *Cfg) error {
cfg.DisableInitAdminCreation = security.Key("disable_initial_admin_creation").MustBool(false)
cfg.AdminUser = valueAsString(security, "admin_user", "")
cfg.AdminPassword = valueAsString(security, "admin_password", "")
cfg.AdminEmail = valueAsString(security, "admin_email", fmt.Sprintf("%s@localhost", cfg.AdminUser))
return nil
}