allow disabling local admin user (#515)
Some checks failed
Docker / Build and Push (push) Has been cancelled
Docker / release (push) Has been cancelled
github-pages / deploy (push) Has been cancelled

This commit is contained in:
Victor LEFEBVRE
2025-09-08 10:39:10 +02:00
committed by GitHub
parent d311313cb4
commit b61d84ec4f
2 changed files with 11 additions and 5 deletions

View File

@@ -52,9 +52,13 @@ func Initialize(
// Switch to admin user context // Switch to admin user context
startupContext = domain.SetUserInfo(startupContext, domain.SystemAdminContextUserInfo()) startupContext = domain.SetUserInfo(startupContext, domain.SystemAdminContextUserInfo())
if !cfg.Core.AdminUserDisabled {
if err := a.createDefaultUser(startupContext); err != nil { if err := a.createDefaultUser(startupContext); err != nil {
return fmt.Errorf("failed to create default user: %w", err) return fmt.Errorf("failed to create default user: %w", err)
} }
} else {
slog.Info("Local Admin user disabled!")
}
if err := a.importNewInterfaces(startupContext); err != nil { if err := a.importNewInterfaces(startupContext); err != nil {
return fmt.Errorf("failed to import new interfaces: %w", err) return fmt.Errorf("failed to import new interfaces: %w", err)

View File

@@ -14,6 +14,7 @@ import (
type Config struct { type Config struct {
Core struct { Core struct {
// AdminUser defines the default administrator account that will be created // AdminUser defines the default administrator account that will be created
AdminUserDisabled bool `yaml:"disable_admin_user"`
AdminUser string `yaml:"admin_user"` AdminUser string `yaml:"admin_user"`
AdminPassword string `yaml:"admin_password"` AdminPassword string `yaml:"admin_password"`
AdminApiToken string `yaml:"admin_api_token"` // if set, the API access is enabled automatically AdminApiToken string `yaml:"admin_api_token"` // if set, the API access is enabled automatically
@@ -113,6 +114,7 @@ func (c *Config) LogStartupValues() {
func defaultConfig() *Config { func defaultConfig() *Config {
cfg := &Config{} cfg := &Config{}
cfg.Core.AdminUserDisabled = false
cfg.Core.AdminUser = "admin@wgportal.local" cfg.Core.AdminUser = "admin@wgportal.local"
cfg.Core.AdminPassword = "wgportal-default" cfg.Core.AdminPassword = "wgportal-default"
cfg.Core.AdminApiToken = "" // by default, the API access is disabled cfg.Core.AdminApiToken = "" // by default, the API access is disabled