automatic API access for default admin (#357)
Some checks failed
Chart / lint-test (push) Has been cancelled
Chart / publish (push) Has been cancelled
Docker / Build and Push (push) Has been cancelled
github-pages / deploy (push) Has been cancelled
Docker / release (push) Has been cancelled

This commit is contained in:
Christoph Haas
2025-02-07 22:42:48 +01:00
parent c33eaba1c0
commit e983a7b8f3
5 changed files with 112 additions and 96 deletions

View File

@@ -127,7 +127,7 @@ func (a *App) createDefaultUser(ctx context.Context) error {
}
now := time.Now()
admin, err := a.CreateUser(ctx, &domain.User{
defaultAdmin := &domain.User{
BaseModel: domain.BaseModel{
CreatedBy: domain.CtxSystemAdminId,
UpdatedBy: domain.CtxSystemAdminId,
@@ -150,7 +150,16 @@ func (a *App) createDefaultUser(ctx context.Context) error {
Locked: nil,
LockedReason: "",
LinkedPeerCount: 0,
})
}
if a.Config.Core.AdminApiToken != "" {
if len(a.Config.Core.AdminApiToken) < 18 {
logrus.Warnf("[SECURITY WARNING] admin API token is too short, should be at least 18 characters long")
}
defaultAdmin.ApiToken = a.Config.Core.AdminApiToken
defaultAdmin.ApiTokenCreated = &now
}
admin, err := a.CreateUser(ctx, defaultAdmin)
if err != nil {
return err
}

View File

@@ -16,6 +16,7 @@ type Config struct {
// AdminUser defines the default administrator account that will be created
AdminUser string `yaml:"admin_user"`
AdminPassword string `yaml:"admin_password"`
AdminApiToken string `yaml:"admin_api_token"` // if set, the API access is enabled automatically
EditableKeys bool `yaml:"editable_keys"`
CreateDefaultPeer bool `yaml:"create_default_peer"`
@@ -94,6 +95,7 @@ func defaultConfig() *Config {
cfg.Core.AdminUser = "admin@wgportal.local"
cfg.Core.AdminPassword = "wgportal"
cfg.Core.AdminApiToken = "" // by default, the API access is disabled
cfg.Core.ImportExisting = true
cfg.Core.RestoreState = true
cfg.Core.CreateDefaultPeer = false