mirror of
https://github.com/HKUDS/DeepTutor.git
synced 2026-12-02 04:20:04 +08:00
The identity store had two bugs that combined into a lockout for deployments whose admin comes from auth.json rather than /register. load_users() returned the bootstrap admin only when the store was empty, so writing the first real account dropped it and the operator's login started returning 401. save_user() then decided first-admin promotion from load_users() called with no env arguments, an env-blind view, so with an empty store the first account an admin created from /admin/users was silently promoted to admin even though that endpoint documents role="user". Together: create one student account, the student is the only admin, the operator is locked out. load_users() now merges the bootstrap admin whenever it is configured; a stored record with the same username still wins, so the account can be adopted into the store. The merge stays in memory because no write path passes the env arguments, so a rotation of auth.json is never shadowed by a stale persisted hash. save_user() counts a configured bootstrap admin as an existing account, except when saving that same username, which is an adoption and keeps the admin role. The genuinely-empty deployment is unchanged: with no bootstrap credentials the first /register user is still promoted. A username configured with an empty hash cannot authenticate and so does not count, which matters because that is the shipped default. Fixes #849