Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
10 changes: 10 additions & 0 deletions changelog/unreleased/fix-idm-resetpw-service-users.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
Enhancement: Allow resetting IDM service user passwords

The `ocis idm resetpassword` command now supports a `--service-user`
flag to target service accounts (libregraph, idp, reva) which live in
`ou=sysusers` instead of `ou=users`. 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
14 changes: 11 additions & 3 deletions services/idm/pkg/command/resetpw.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ func ResetPassword(cfg *config.Config) *cli.Command {
Usage: "User name",
Value: "admin",
},
&cli.BoolFlag{
Comment thread
mmattel marked this conversation as resolved.
Outdated
Name: "service-user",
Usage: "Target a service user (ou=sysusers) instead of a regular user (ou=users)",
},
},
Before: func(_ *cli.Context) error {
return configlog.ReturnFatal(parser.ParseConfig(cfg))
Expand All @@ -43,12 +47,12 @@ func ResetPassword(cfg *config.Config) *cli.Command {
ctx, cancel := context.WithCancel(c.Context)

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

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, serviceUser bool) error {
servercfg := server.Config{
Logger: log.LogrusWrap(logger.Logger),
LDAPHandler: "boltdb",
Expand All @@ -57,7 +61,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 serviceUser {
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