feat(idm): add --service-user flag to resetpassword command (#12118)
* feat(idm): add --service-user flag to resetpassword command The DN was hardcoded to ou=users, making it impossible to reset passwords for service accounts (libregraph, idp, reva) which live under ou=sysusers. The new --service-user flag selects the correct OU. Fixes: #12106 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> Signed-off-by: Paul Faure <paul@faure.ca> * docs: update changelog with PR number Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> Signed-off-by: Paul Faure <paul@faure.ca> * refactor(idm): use --user-type flag instead of --service-user bool Replace the --service-user boolean flag with a --user-type string flag that accepts 'user' (default) or 'service'. This is more extensible if additional user types are added in the future. Addresses review feedback from mklos-kw. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> Signed-off-by: Paul Faure <paul@faure.ca> --------- Signed-off-by: Paul Faure <paul@faure.ca> Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
1 parent
cc9b170e4b
commit
1d9b6dd053
2 files changed
+29
-3
No files matched your search
@@ -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
|
||||
@@ -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))
|
||||
@@ -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",
|
||||
@@ -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")
|
||||
|
||||
Reference in new issue
Block a user