From 382d91b22b41b8553697eca520a1bf81b8abef29 Mon Sep 17 00:00:00 2001 From: Willy Kloucek Date: Mon, 16 May 2022 08:28:06 +0200 Subject: [PATCH 1/2] fix settings and idm admin user id configuration --- changelog/unreleased/fix-settings-idm-adminuserid.md | 9 +++++++++ extensions/idm/pkg/command/server.go | 2 +- extensions/idm/pkg/config/config.go | 1 + extensions/idm/pkg/config/defaults/defaultconfig.go | 4 ++++ extensions/settings/pkg/config/config.go | 2 ++ extensions/settings/pkg/config/defaults/defaultconfig.go | 4 ++++ extensions/settings/pkg/service/v0/settings.go | 2 +- extensions/settings/pkg/store/defaults/defaults.go | 2 +- 8 files changed, 23 insertions(+), 3 deletions(-) create mode 100644 changelog/unreleased/fix-settings-idm-adminuserid.md diff --git a/changelog/unreleased/fix-settings-idm-adminuserid.md b/changelog/unreleased/fix-settings-idm-adminuserid.md new file mode 100644 index 00000000000..2c0e14f2bab --- /dev/null +++ b/changelog/unreleased/fix-settings-idm-adminuserid.md @@ -0,0 +1,9 @@ +Bugfix: Fix the idm and settings extensions' admin user id configuration option + +We've fixed the admin user id configuration of the settings and idm extensions. +The have previously only been configurable via the oCIS shared configuration and +therefore have been undocumented for the extensions. This config option is now part +of both extensions' configuration and can now also be used when the extensions are +compiled standalone. + +https://github.com/owncloud/ocis/pull/3799 diff --git a/extensions/idm/pkg/command/server.go b/extensions/idm/pkg/command/server.go index 9bd47046c07..45f6e2d18fd 100644 --- a/extensions/idm/pkg/command/server.go +++ b/extensions/idm/pkg/command/server.go @@ -98,7 +98,7 @@ func bootstrap(logger log.Logger, cfg *config.Config, srvcfg server.Config) erro { Name: "admin", Password: cfg.ServiceUserPasswords.OcisAdmin, - ID: cfg.Commons.AdminUserID, + ID: cfg.AdminUserID, }, { Name: "libregraph", diff --git a/extensions/idm/pkg/config/config.go b/extensions/idm/pkg/config/config.go index b9734643825..6f0686fbbe7 100644 --- a/extensions/idm/pkg/config/config.go +++ b/extensions/idm/pkg/config/config.go @@ -20,6 +20,7 @@ type Config struct { CreateDemoUsers bool `yaml:"create_demo_users" env:"IDM_CREATE_DEMO_USERS;ACCOUNTS_DEMO_USERS_AND_GROUPS" desc:"Flag to enabe/disable the creation of the demo users"` ServiceUserPasswords ServiceUserPasswords `yaml:"service_user_passwords"` + AdminUserID string `yaml:"admin_user_id" env:"OCIS_ADMIN_USER_ID;IDM_ADMIN_USER_ID"` Context context.Context `yaml:"-"` } diff --git a/extensions/idm/pkg/config/defaults/defaultconfig.go b/extensions/idm/pkg/config/defaults/defaultconfig.go index 97d976c1a12..28386b95e2c 100644 --- a/extensions/idm/pkg/config/defaults/defaultconfig.go +++ b/extensions/idm/pkg/config/defaults/defaultconfig.go @@ -52,6 +52,10 @@ func EnsureDefaults(cfg *config.Config) { } else if cfg.Tracing == nil { cfg.Tracing = &config.Tracing{} } + + if cfg.AdminUserID == "" { + cfg.AdminUserID = cfg.Commons.AdminUserID + } } func Sanitize(cfg *config.Config) { diff --git a/extensions/settings/pkg/config/config.go b/extensions/settings/pkg/config/config.go index 5464c8897aa..ef0685a6da3 100644 --- a/extensions/settings/pkg/config/config.go +++ b/extensions/settings/pkg/config/config.go @@ -23,6 +23,8 @@ type Config struct { DataPath string `yaml:"data_path" env:"SETTINGS_DATA_PATH"` Metadata Metadata `yaml:"metadata_config"` + AdminUserID string `yaml:"admin_user_id" env:"OCIS_ADMIN_USER_ID;SETTINGS_ADMIN_USER_ID"` + Asset Asset `yaml:"asset"` TokenManager *TokenManager `yaml:"token_manager"` diff --git a/extensions/settings/pkg/config/defaults/defaultconfig.go b/extensions/settings/pkg/config/defaults/defaultconfig.go index 3010971fe48..58d2d1d7092 100644 --- a/extensions/settings/pkg/config/defaults/defaultconfig.go +++ b/extensions/settings/pkg/config/defaults/defaultconfig.go @@ -96,6 +96,10 @@ func EnsureDefaults(cfg *config.Config) { if cfg.Metadata.SystemUserID == "" && cfg.Commons != nil && cfg.Commons.SystemUserID != "" { cfg.Metadata.SystemUserID = cfg.Commons.SystemUserID } + + if cfg.AdminUserID == "" { + cfg.AdminUserID = cfg.Commons.AdminUserID + } } func Sanitize(cfg *config.Config) { diff --git a/extensions/settings/pkg/service/v0/settings.go b/extensions/settings/pkg/service/v0/settings.go index 35aa78ffa94..825fc47f5ed 100644 --- a/extensions/settings/pkg/service/v0/settings.go +++ b/extensions/settings/pkg/service/v0/settings.go @@ -539,7 +539,7 @@ func (g Service) defaultRoleAssignments() []*settingsmsg.UserRoleAssignment { AccountUuid: "058bff95-6708-4fe5-91e4-9ea3d377588b", // demo user "moss" RoleId: BundleUUIDRoleAdmin, }, { - AccountUuid: g.config.Commons.AdminUserID, + AccountUuid: g.config.AdminUserID, RoleId: BundleUUIDRoleAdmin, }, // default users with role "user" diff --git a/extensions/settings/pkg/store/defaults/defaults.go b/extensions/settings/pkg/store/defaults/defaults.go index c52b32a4326..e24c632550f 100644 --- a/extensions/settings/pkg/store/defaults/defaults.go +++ b/extensions/settings/pkg/store/defaults/defaults.go @@ -504,7 +504,7 @@ func DefaultRoleAssignments(cfg *config.Config) []*settingsmsg.UserRoleAssignmen AccountUuid: "058bff95-6708-4fe5-91e4-9ea3d377588b", // demo user "moss" RoleId: BundleUUIDRoleAdmin, }, { - AccountUuid: cfg.Commons.AdminUserID, + AccountUuid: cfg.AdminUserID, RoleId: BundleUUIDRoleAdmin, }, // default users with role "user" From 97220e63e604d130259d58687ba429dd0f63b88e Mon Sep 17 00:00:00 2001 From: Willy Kloucek Date: Mon, 16 May 2022 09:32:12 +0200 Subject: [PATCH 2/2] check if cfg.Commons is nil --- .bingo/Variables.mk | 2 +- extensions/idm/pkg/config/defaults/defaultconfig.go | 2 +- extensions/settings/pkg/config/defaults/defaultconfig.go | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.bingo/Variables.mk b/.bingo/Variables.mk index 01e058ce9b6..cd90d103da6 100644 --- a/.bingo/Variables.mk +++ b/.bingo/Variables.mk @@ -3,7 +3,7 @@ BINGO_DIR := $(dir $(lastword $(MAKEFILE_LIST))) GOPATH ?= $(shell go env GOPATH) GOBIN ?= $(firstword $(subst :, ,${GOPATH}))/bin -GO ?= $(shell command -v go) +GO ?= $(shell which go) # Below generated variables ensure that every time a tool under each variable is invoked, the correct version # will be used; reinstalling only if needed. diff --git a/extensions/idm/pkg/config/defaults/defaultconfig.go b/extensions/idm/pkg/config/defaults/defaultconfig.go index 28386b95e2c..99374a1f686 100644 --- a/extensions/idm/pkg/config/defaults/defaultconfig.go +++ b/extensions/idm/pkg/config/defaults/defaultconfig.go @@ -53,7 +53,7 @@ func EnsureDefaults(cfg *config.Config) { cfg.Tracing = &config.Tracing{} } - if cfg.AdminUserID == "" { + if cfg.AdminUserID == "" && cfg.Commons != nil { cfg.AdminUserID = cfg.Commons.AdminUserID } } diff --git a/extensions/settings/pkg/config/defaults/defaultconfig.go b/extensions/settings/pkg/config/defaults/defaultconfig.go index 58d2d1d7092..6bffa9819e3 100644 --- a/extensions/settings/pkg/config/defaults/defaultconfig.go +++ b/extensions/settings/pkg/config/defaults/defaultconfig.go @@ -97,7 +97,7 @@ func EnsureDefaults(cfg *config.Config) { cfg.Metadata.SystemUserID = cfg.Commons.SystemUserID } - if cfg.AdminUserID == "" { + if cfg.AdminUserID == "" && cfg.Commons != nil { cfg.AdminUserID = cfg.Commons.AdminUserID } }