Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions changelog/unreleased/fix-idm-resetpw-service-users.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
Enhancement: Allow resetting IDM service user passwords

The `ocis idm resetpassword` command now supports a `--user-type` flag
to select the account type: `user` (default, ou=users) or `service`
(ou=sysusers). This allows resetting passwords for service accounts
(libregraph, idp, reva) which live in `ou=sysusers`. Previously, the
DN was hardcoded to `ou=users`, making it impossible to reset service
user passwords via the CLI.

https://github.com/owncloud/ocis/pull/12118
https://github.com/owncloud/ocis/issues/12106
21 changes: 18 additions & 3 deletions services/idm/pkg/command/resetpw.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ func ResetPassword(cfg *config.Config) *cli.Command {
Usage: "User name",
Value: "admin",
},
&cli.StringFlag{
Name: "user-type",
Usage: "Type of user account: 'user' (ou=users) or 'service' (ou=sysusers)",
Value: "user",
},
},
Before: func(_ *cli.Context) error {
return configlog.ReturnFatal(parser.ParseConfig(cfg))
Expand All @@ -43,12 +48,18 @@ func ResetPassword(cfg *config.Config) *cli.Command {
ctx, cancel := context.WithCancel(c.Context)

defer cancel()
return resetPassword(ctx, logger, cfg, c.String("user-name"))

userType := c.String("user-type")
if userType != "user" && userType != "service" {
return fmt.Errorf("invalid --user-type %q: must be 'user' or 'service'", userType)
}

return resetPassword(ctx, logger, cfg, c.String("user-name"), userType)
},
}
}

func resetPassword(_ context.Context, logger log.Logger, cfg *config.Config, userName string) error {
func resetPassword(_ context.Context, logger log.Logger, cfg *config.Config, userName string, userType string) error {
servercfg := server.Config{
Logger: log.LogrusWrap(logger.Logger),
LDAPHandler: "boltdb",
Expand All @@ -57,7 +68,11 @@ func resetPassword(_ context.Context, logger log.Logger, cfg *config.Config, use
BoltDBFile: cfg.IDM.DatabasePath,
}

userDN := fmt.Sprintf("uid=%s,ou=users,%s", userName, servercfg.LDAPBaseDN)
ou := "users"
if userType == "service" {
ou = "sysusers"
}
userDN := fmt.Sprintf("uid=%s,ou=%s,%s", userName, ou, servercfg.LDAPBaseDN)
fmt.Printf("Resetting password for user '%s'.\n", userDN)
if _, err := os.Stat(servercfg.BoltDBFile); errors.Is(err, os.ErrNotExist) {
fmt.Fprintf(os.Stderr, "IDM database does not exist.\n")
Expand Down