mirror of
https://github.com/SecurityBrewery/catalyst.git
synced 2025-12-06 23:32:47 +01:00
Add admin user config (#36)
This commit is contained in:
17
auth.go
17
auth.go
@@ -32,6 +32,7 @@ type AuthConfig struct {
|
|||||||
OIDCClaimName string
|
OIDCClaimName string
|
||||||
AuthBlockNew bool
|
AuthBlockNew bool
|
||||||
AuthDefaultRoles []role.Role
|
AuthDefaultRoles []role.Role
|
||||||
|
AuthAdminUsers []string
|
||||||
|
|
||||||
provider *oidc.Provider
|
provider *oidc.Provider
|
||||||
}
|
}
|
||||||
@@ -267,16 +268,30 @@ func mapUserAndSettings(claims map[string]interface{}, config *AuthConfig) (*mod
|
|||||||
name = ""
|
name = ""
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var roles = role.Strings(config.AuthDefaultRoles)
|
||||||
|
if contains(config.AuthAdminUsers, username) {
|
||||||
|
roles = append(roles, role.Admin)
|
||||||
|
}
|
||||||
|
|
||||||
return &model.UserForm{
|
return &model.UserForm{
|
||||||
ID: username,
|
ID: username,
|
||||||
Blocked: config.AuthBlockNew,
|
Blocked: config.AuthBlockNew,
|
||||||
Roles: role.Strings(config.AuthDefaultRoles),
|
Roles: roles,
|
||||||
}, &model.UserData{
|
}, &model.UserData{
|
||||||
Email: &email,
|
Email: &email,
|
||||||
Name: &name,
|
Name: &name,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func contains(l []string, s string) bool {
|
||||||
|
for _, e := range l {
|
||||||
|
if e == s {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
func getString(m map[string]interface{}, key string) (string, error) {
|
func getString(m map[string]interface{}, key string) (string, error) {
|
||||||
if v, ok := m[key]; ok {
|
if v, ok := m[key]; ok {
|
||||||
if s, ok := v.(string); ok {
|
if s, ok := v.(string); ok {
|
||||||
|
|||||||
@@ -32,6 +32,7 @@ type CLI struct {
|
|||||||
OIDCClaimName string `env:"OIDC_CLAIM_NAME" default:"name" help:"name field in the OIDC claim"`
|
OIDCClaimName string `env:"OIDC_CLAIM_NAME" default:"name" help:"name field in the OIDC claim"`
|
||||||
AuthBlockNew bool `env:"AUTH_BLOCK_NEW" default:"true" help:"Block newly created users"`
|
AuthBlockNew bool `env:"AUTH_BLOCK_NEW" default:"true" help:"Block newly created users"`
|
||||||
AuthDefaultRoles []string `env:"AUTH_DEFAULT_ROLES" help:"Default roles for new users"`
|
AuthDefaultRoles []string `env:"AUTH_DEFAULT_ROLES" help:"Default roles for new users"`
|
||||||
|
AuthAdminUsers []string `env:"AUTH_ADMIN_USERS" help:"Username of admins"`
|
||||||
|
|
||||||
IndexPath string `env:"INDEX_PATH" default:"index.bleve" help:"Path for the bleve index"`
|
IndexPath string `env:"INDEX_PATH" default:"index.bleve" help:"Path for the bleve index"`
|
||||||
|
|
||||||
@@ -96,6 +97,7 @@ func MapConfig(cli CLI) (*catalyst.Config, error) {
|
|||||||
OIDCClaimName: cli.OIDCClaimName,
|
OIDCClaimName: cli.OIDCClaimName,
|
||||||
AuthBlockNew: cli.AuthBlockNew,
|
AuthBlockNew: cli.AuthBlockNew,
|
||||||
AuthDefaultRoles: roles,
|
AuthDefaultRoles: roles,
|
||||||
|
AuthAdminUsers: cli.AuthAdminUsers,
|
||||||
},
|
},
|
||||||
Bus: &bus.Config{Host: cli.EmitterIOHost, Key: cli.EmitterIORKey, APIUrl: cli.CatalystAddress + "/api"},
|
Bus: &bus.Config{Host: cli.EmitterIOHost, Key: cli.EmitterIORKey, APIUrl: cli.CatalystAddress + "/api"},
|
||||||
UISettings: &model.Settings{
|
UISettings: &model.Settings{
|
||||||
|
|||||||
Reference in New Issue
Block a user