Settings: Remove global variables for auth settings (#63795)

* Setting: Remove global DisableLoginForm and add it to cfg

* Setting: Remove unused BasicAuthEnabled global

* Setting: Remove global OAuthAutoLogin and use from cfg

* Setting: Remove global AnonymousEnabled

* Setting: Remove global values for AuthProxy settings
This commit is contained in:
Karl Persson
2023-02-27 15:28:49 +01:00
committed by GitHub
parent a41e9b2dc7
commit 8484d0c4ef
9 changed files with 34 additions and 47 deletions
+15 -28
View File
@@ -97,28 +97,17 @@ var (
VerifyEmailEnabled bool
LoginHint string
PasswordHint string
DisableLoginForm bool
DisableSignoutMenu bool
SignoutRedirectUrl string
ExternalUserMngLinkUrl string
ExternalUserMngLinkName string
ExternalUserMngInfo string
OAuthAutoLogin bool
ViewersCanEdit bool
// HTTP auth
SigV4AuthEnabled bool
AzureAuthEnabled bool
AnonymousEnabled bool
// Auth proxy settings
AuthProxyEnabled bool
AuthProxyHeaderProperty string
// Basic Auth
BasicAuthEnabled bool
// Global setting objects.
Raw *ini.File
@@ -154,12 +143,6 @@ var (
ImageUploadProvider string
)
// AddChangePasswordLink returns if login form is disabled or not since
// the same intention can be used to hide both features.
func AddChangePasswordLink() bool {
return !DisableLoginForm
}
// TODO move all global vars to this struct
type Cfg struct {
Raw *ini.File
@@ -286,6 +269,7 @@ type Cfg struct {
DisableLogin bool
AdminEmail string
DisableSyncLock bool
DisableLoginForm bool
// AWS Plugin Auth
AWSAllowedAuthProviders []string
@@ -307,6 +291,7 @@ type Cfg struct {
AuthProxySyncTTL int
// OAuth
OAuthAutoLogin bool
OAuthCookieMaxAge int
// JWT Auth
@@ -518,6 +503,12 @@ type Cfg struct {
CustomResponseHeaders map[string]string
}
// AddChangePasswordLink returns if login form is disabled or not since
// the same intention can be used to hide both features.
func (cfg *Cfg) AddChangePasswordLink() bool {
return !cfg.DisableLoginForm
}
type CommandLineArgs struct {
Config string
HomePath string
@@ -1439,12 +1430,12 @@ func readAuthSettings(iniFile *ini.File, cfg *Cfg) (err error) {
// Debug setting unlocking frontend auth sync lock. Users will still be reset on their next login.
cfg.DisableSyncLock = auth.Key("disable_sync_lock").MustBool(false)
DisableLoginForm = auth.Key("disable_login_form").MustBool(false)
cfg.DisableLoginForm = auth.Key("disable_login_form").MustBool(false)
DisableSignoutMenu = auth.Key("disable_signout_menu").MustBool(false)
// Deprecated
OAuthAutoLogin = auth.Key("oauth_auto_login").MustBool(false)
if OAuthAutoLogin {
cfg.OAuthAutoLogin = auth.Key("oauth_auto_login").MustBool(false)
if cfg.OAuthAutoLogin {
cfg.Logger.Warn("[Deprecated] The oauth_auto_login configuration setting is deprecated. Please use auto_login inside auth provider section instead.")
}
@@ -1481,16 +1472,14 @@ func readAuthSettings(iniFile *ini.File, cfg *Cfg) (err error) {
readAuthOktaSettings(iniFile, cfg)
// anonymous access
AnonymousEnabled = iniFile.Section("auth.anonymous").Key("enabled").MustBool(false)
cfg.AnonymousEnabled = AnonymousEnabled
cfg.AnonymousEnabled = iniFile.Section("auth.anonymous").Key("enabled").MustBool(false)
cfg.AnonymousOrgName = valueAsString(iniFile.Section("auth.anonymous"), "org_name", "")
cfg.AnonymousOrgRole = valueAsString(iniFile.Section("auth.anonymous"), "org_role", "")
cfg.AnonymousHideVersion = iniFile.Section("auth.anonymous").Key("hide_version").MustBool(false)
// basic auth
authBasic := iniFile.Section("auth.basic")
BasicAuthEnabled = authBasic.Key("enabled").MustBool(true)
cfg.BasicAuthEnabled = BasicAuthEnabled
cfg.BasicAuthEnabled = authBasic.Key("enabled").MustBool(true)
// JWT auth
authJWT := iniFile.Section("auth.jwt")
@@ -1511,12 +1500,10 @@ func readAuthSettings(iniFile *ini.File, cfg *Cfg) (err error) {
cfg.JWTAuthSkipOrgRoleSync = authJWT.Key("skip_org_role_sync").MustBool(false)
authProxy := iniFile.Section("auth.proxy")
AuthProxyEnabled = authProxy.Key("enabled").MustBool(false)
cfg.AuthProxyEnabled = AuthProxyEnabled
cfg.AuthProxyEnabled = authProxy.Key("enabled").MustBool(false)
cfg.AuthProxyHeaderName = valueAsString(authProxy, "header_name", "")
AuthProxyHeaderProperty = valueAsString(authProxy, "header_property", "")
cfg.AuthProxyHeaderProperty = AuthProxyHeaderProperty
cfg.AuthProxyHeaderProperty = valueAsString(authProxy, "header_property", "")
cfg.AuthProxyAutoSignUp = authProxy.Key("auto_sign_up").MustBool(true)
cfg.AuthProxyEnableLoginToken = authProxy.Key("enable_login_token").MustBool(false)