From 670dfedf7c7496b0a0563f7318e2f0e70cf1c8d4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20Pablo=20Villaf=C3=A1=C3=B1ez?= Date: Tue, 14 Sep 2021 09:17:30 +0200 Subject: [PATCH 1/4] Add option to generate the demo users --- accounts/pkg/config/config.go | 7 ++++--- accounts/pkg/flagset/flagset.go | 6 ++++++ accounts/pkg/service/v0/service.go | 29 +++++++++++++++++++++++++---- 3 files changed, 35 insertions(+), 7 deletions(-) diff --git a/accounts/pkg/config/config.go b/accounts/pkg/config/config.go index 8863919429b..c63c289f7ea 100644 --- a/accounts/pkg/config/config.go +++ b/accounts/pkg/config/config.go @@ -42,9 +42,10 @@ type GRPC struct { // Server configures a server. type Server struct { - Version string - Name string - HashDifficulty int + Version string + Name string + HashDifficulty int + DemoUsersAndGroups bool } // Asset defines the available asset configuration. diff --git a/accounts/pkg/flagset/flagset.go b/accounts/pkg/flagset/flagset.go index be9cc3fc9af..b3a3ae0b40e 100644 --- a/accounts/pkg/flagset/flagset.go +++ b/accounts/pkg/flagset/flagset.go @@ -134,6 +134,12 @@ func ServerWithConfig(cfg *config.Config) []cli.Flag { EnvVars: []string{"ACCOUNTS_HASH_DIFFICULTY"}, Destination: &cfg.Server.HashDifficulty, }, + &cli.BoolFlag{ + Name: "demo-users-and-groups", + Usage: "Enable demo users and groups", + EnvVars: []string{"ACCOUNTS_DEMO_USERS_AND_GROUPS"}, + Destination: &cfg.Server.DemoUsersAndGroups, + }, &cli.StringFlag{ Name: "asset-path", Value: flags.OverrideDefaultString(cfg.Asset.Path, ""), diff --git a/accounts/pkg/service/v0/service.go b/accounts/pkg/service/v0/service.go index dae86a5d254..ff6059f143e 100644 --- a/accounts/pkg/service/v0/service.go +++ b/accounts/pkg/service/v0/service.go @@ -73,11 +73,11 @@ func New(opts ...Option) (s *Service, err error) { return nil, err } - if err = s.createDefaultAccounts(); err != nil { + if err = s.createDefaultAccounts(cfg.Server.DemoUsersAndGroups); err != nil { return nil, err } - if err = s.createDefaultGroups(); err != nil { + if err = s.createDefaultGroups(cfg.Server.DemoUsersAndGroups); err != nil { return nil, err } return @@ -152,7 +152,7 @@ func configFromSvc(cfg *config.Config) (*idxcfg.Config, error) { return c, nil } -func (s Service) createDefaultAccounts() (err error) { +func (s Service) createDefaultAccounts(withDemoAccounts bool) (err error) { accounts := []proto.Account{ { Id: "4c510ada-c86b-4815-8820-42cdf82c3d51", @@ -278,8 +278,19 @@ func (s Service) createDefaultAccounts() (err error) { }, }, } + + mustHaveAccounts := map[string]bool{ + "bc596f3c-c955-4328-80a0-60d018b4ad57": true, // Reva IOP + "820ba2a1-3f54-4538-80a4-2d73007e30bf": true, // Kopano IDP + "ddc2004c-0977-11eb-9d3f-a793888cd0f8": true, // admin + } + // this only deals with the metadata service. for i := range accounts { + if !withDemoAccounts && !mustHaveAccounts[accounts[i].Id] { + continue + } + a := &proto.Account{} err := s.repo.LoadAccount(context.Background(), accounts[i].Id, a) if !storage.IsNotFoundErr(err) { @@ -323,7 +334,7 @@ func (s Service) createDefaultAccounts() (err error) { return nil } -func (s Service) createDefaultGroups() (err error) { +func (s Service) createDefaultGroups(withDemoGroups bool) (err error) { groups := []proto.Group{ {Id: "34f38767-c937-4eb6-b847-1c175829a2a0", GidNumber: 15000, OnPremisesSamAccountName: "sysusers", DisplayName: "Technical users", Description: "A group for technical users. They should not show up in sharing dialogs.", Members: []*proto.Account{ {Id: "820ba2a1-3f54-4538-80a4-2d73007e30bf"}, // idp @@ -358,7 +369,17 @@ func (s Service) createDefaultGroups() (err error) { {Id: "932b4540-8d16-481e-8ef4-588e4b6b151c"}, // feynman }}, } + + mustHaveGroups := map[string]bool{ + "34f38767-c937-4eb6-b847-1c175829a2a0": true, // sysusers + "509a9dcd-bb37-4f4f-a01a-19dca27d9cfa": true, // users + } + for i := range groups { + if !withDemoGroups && !mustHaveGroups[groups[i].Id] { + continue + } + g := &proto.Group{} err := s.repo.LoadGroup(context.Background(), groups[i].Id, g) if !storage.IsNotFoundErr(err) { From de68fc32a35d5a6d95641dda50cb5d5f6a92b958 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20Pablo=20Villaf=C3=A1=C3=B1ez?= Date: Tue, 14 Sep 2021 09:27:20 +0200 Subject: [PATCH 2/4] Add changelog entry --- changelog/unreleased/skip-demo-users.md | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 changelog/unreleased/skip-demo-users.md diff --git a/changelog/unreleased/skip-demo-users.md b/changelog/unreleased/skip-demo-users.md new file mode 100644 index 00000000000..bd0790af44f --- /dev/null +++ b/changelog/unreleased/skip-demo-users.md @@ -0,0 +1,6 @@ +Enhancement: Demo users and groups won't be generated unless requested + +We've added a new environment variable to decide whether we should generate the demo users and groups or not. This environment variable is false by default, so the demo users and groups won't be generated by default. +There are still some users and groups automatically generated: for users: Reva IOP, Kopano IDP, admin; for groups: sysusers and users. + +https://github.com/owncloud/ocis/pull/2495 From 502e77b18515bd9c5c5d81f8d0d688091f1b6694 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20Pablo=20Villaf=C3=A1=C3=B1ez?= Date: Wed, 15 Sep 2021 17:45:55 +0200 Subject: [PATCH 3/4] Set true as default value --- accounts/pkg/flagset/flagset.go | 1 + 1 file changed, 1 insertion(+) diff --git a/accounts/pkg/flagset/flagset.go b/accounts/pkg/flagset/flagset.go index b3a3ae0b40e..4a7954f6626 100644 --- a/accounts/pkg/flagset/flagset.go +++ b/accounts/pkg/flagset/flagset.go @@ -136,6 +136,7 @@ func ServerWithConfig(cfg *config.Config) []cli.Flag { }, &cli.BoolFlag{ Name: "demo-users-and-groups", + Value: flags.OverrideDefaultBool(cfg.Server.DemoUsersAndGroups, true), Usage: "Enable demo users and groups", EnvVars: []string{"ACCOUNTS_DEMO_USERS_AND_GROUPS"}, Destination: &cfg.Server.DemoUsersAndGroups, From a680fc103931f96e21ff20f379b2ca00feb00458 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20Pablo=20Villaf=C3=A1=C3=B1ez?= Date: Thu, 16 Sep 2021 11:09:59 +0200 Subject: [PATCH 4/4] Adjust test configuration --- accounts/pkg/proto/v0/accounts.pb.micro_test.go | 1 + ocs/pkg/server/http/svc_test.go | 4 +++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/accounts/pkg/proto/v0/accounts.pb.micro_test.go b/accounts/pkg/proto/v0/accounts.pb.micro_test.go index 22328f2ce71..0f5cf724ed7 100644 --- a/accounts/pkg/proto/v0/accounts.pb.micro_test.go +++ b/accounts/pkg/proto/v0/accounts.pb.micro_test.go @@ -81,6 +81,7 @@ func init() { cfg := config.New() cfg.Repo.Disk.Path = dataPath + cfg.Server.DemoUsersAndGroups = true var hdlr *svc.Service var err error diff --git a/ocs/pkg/server/http/svc_test.go b/ocs/pkg/server/http/svc_test.go index 965edd3973a..7c46558f0ba 100644 --- a/ocs/pkg/server/http/svc_test.go +++ b/ocs/pkg/server/http/svc_test.go @@ -538,7 +538,9 @@ func init() { ) c := &accountsCfg.Config{ - Server: accountsCfg.Server{}, + Server: accountsCfg.Server{ + DemoUsersAndGroups: true, + }, Repo: accountsCfg.Repo{ Disk: accountsCfg.Disk{ Path: dataPath,