Skip to content

feat: add user subcommands for account recovery - #1095

Open
Shrinet82 wants to merge 1 commit into
gotify:masterfrom
Shrinet82:cli-user-recovery
Open

Shrinet82 wants to merge 1 commit into
gotify:masterfrom
Shrinet82:cli-user-recovery

Conversation

@Shrinet82

@Shrinet82 Shrinet82 commented Nov 23, 2026 •

Copy link
Copy Markdown

Fixes #1043

This adds the user subcommands that @jmattheis proposed in the issue, so a lost admin account can be recovered without access to the API:

gotify user create [--admin] <name> [password]
gotify user set-password <name> [password]
gotify user set-admin <name> true|false

If [password] is omitted, it is prompted for twice without echo. If stdin isn't a terminal, the command exits with an error instead of hanging. Passwords go through the same ValidateNewPassword/CreatePassword (with GOTIFY_PASSSTRENGTH) as the API. The commands load the config exactly like serve (env vars and env files), so they hit the same database.

Example, recovering the admin in Docker:

$ docker exec -it gotify ./gotify-app user set-password admin
Password:
Confirm password:
Updated password of user "admin"

Some notes:

  • I open the database with createDefaultUserIfNotExist=false, so running a command against an empty database doesn't also create admin:admin. It only makes the requested change.
  • set-admin <name> false currently follows the spec and doesn't stop you from demoting the last admin, while the API refuses that ("cannot delete last admin"). I can add the same check here if you'd prefer. You could always promote a user again with the CLI.
  • Usage errors exit with 2, other errors (user exists, user not found, password mismatch, ...) with 1.
  • This adds golang.org/x/term for the password prompt, at the version x/crypto already requires.

I tested on a clean Ubuntu 24.04 VM with Go 1.27.4:

  • make test-coverage and make check-go (golangci-lint v2.15.0)
  • SQLite end to end with the binary: started and stopped serve, ran create (argument and real terminal prompt), create --admin, set-password admin and set-admin alice true, then checked over the API that the old admin password returns 401, the new one 200, and alice is admin. Also checked all the error cases and their exit codes.
  • Docker: built the image from this branch with docker/Dockerfile and recovered the admin with docker exec -it gotify ./gotify-app user set-password admin.
  • Postgres 17 in a container: set-password, create and set-admin, then verified via the API.

Docs: gotify/website#110 describes how to reset a lost admin password with these commands.

Add `gotify user create [--admin] <name> [password]`,
`gotify user set-password <name> [password]` and
`gotify user set-admin <name> true|false`. They load the same config
as `gotify serve` and operate directly on the configured database,
so a lost admin account can be recovered without API access.

If the password is omitted, it is prompted for twice without echo.
If stdin is not a terminal, the command fails instead of hanging.
Passwords are validated and hashed like in the API.

The commands never create the default user, so on an empty database
only the requested change is made.

Fixes gotify#1043
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

Allow account recovery without access to an admin account

1 participant