feat: admin login security (history, lockout, unlock) and own password change #19

Merged
ngqile merged 13 commits from add-admin-login-security into main 2026-11-30 07:01:02 +00:00
Owner

OpenSpec change add-admin-login-security. Design: docs/superpowers/specs/2026-11-30-admin-login-security-design.md.

What

  • Login history: new service-system.login_audit table records every admin sign-in success, failure and locked attempt, plus sign-outs, unlocks and own password changes, with the browser IP and user agent.
  • Lockout: 5 failed sign-ins within 15 minutes lock the username, even when the right password is then given, until the failures age out or an admin unlocks it. Unknown usernames are counted too, so a lock does not reveal which accounts exist. It is enforced in mobile-api's admin login, which is the only way in. The check fails open if services-system is down.
  • Change my password: a new item in the header user menu. A wrong current password counts as a failed sign-in.
  • Login security screen (/login-security, module BO_LOGIN_SECURITY, ungranted by default) with three tabs:
    • History, filterable;
    • Locked accounts, with an Unlock button;
    • Settings, for the lockout limits and the admin password rules.
  • The login page shows a clear message when the account is locked.

SQL (DBA, after the release package)

openspec/changes/add-admin-login-security/sql/ (archive path listed in docs/deployment.md section 3):

  • 01-login-audit.sql creates the table. It is DDL, so run it with a user allowed to create tables.
  • 02-lockout-settings.sql adds ADMIN_LOGIN_MAX_ATTEMPT = 5 and sets the block period to 15 minutes.
  • 03-login-security-module.sql adds the module row.
  • 99-rollback.sql undoes all three.

The local seed mirrors these files.

Verification

  • Tests (fresh run): gateway 16, services-system 107, mobile-api 552, portal 1233. tsc and lint report 0 errors, and next build succeeds.
  • Review: every task passed an Opus review gate, and a whole-branch Opus review returned READY. Its hardening findings were applied: limits on the settings, the same username key for the lock check and the history, the username collation, and the module icon.
  • Live checks on the local stack (real gateway and MySQL):
    • a username locks after 5 failures, and the login page shows the locked message;
    • the locked list shows it, and Unlock (with confirmation) clears it;
    • History filtering and paging work;
    • invalid settings are refused with plain messages;
    • an admin without the module gets 403 and "Not authorised";
    • change-password shows the error for a wrong current password, and a success message otherwise;
    • history rows carry the browser user agent;
    • the pages work at 360px width.
  • Playwright: run against the portal dev server on the local stack. Screenshots were checked by hand.

Follow-ups (not in this PR)

  • A services-auth outage counts as failed sign-ins, so a user who retries during one can get locked.
  • Narrow the existing /blockLoginPeriod/** gateway bypass to its read endpoints.

🤖 Generated with Claude Code

https://claude.ai/code/session_01EFUzfj5akPxyikzGc2iAHM

OpenSpec change `add-admin-login-security`. Design: `docs/superpowers/specs/2026-11-30-admin-login-security-design.md`. ## What - **Login history**: new `service-system`.`login_audit` table records every admin sign-in success, failure and locked attempt, plus sign-outs, unlocks and own password changes, with the browser IP and user agent. - **Lockout**: 5 failed sign-ins within 15 minutes lock the username, even when the right password is then given, until the failures age out or an admin unlocks it. Unknown usernames are counted too, so a lock does not reveal which accounts exist. It is enforced in mobile-api's admin login, which is the only way in. The check fails open if services-system is down. - **Change my password**: a new item in the header user menu. A wrong current password counts as a failed sign-in. - **Login security screen** (`/login-security`, module `BO_LOGIN_SECURITY`, ungranted by default) with three tabs: - History, filterable; - Locked accounts, with an Unlock button; - Settings, for the lockout limits and the admin password rules. - The login page shows a clear message when the account is locked. ## SQL (DBA, after the release package) `openspec/changes/add-admin-login-security/sql/` (archive path listed in `docs/deployment.md` section 3): - `01-login-audit.sql` creates the table. It is DDL, so run it with a user allowed to create tables. - `02-lockout-settings.sql` adds `ADMIN_LOGIN_MAX_ATTEMPT` = 5 and sets the block period to 15 minutes. - `03-login-security-module.sql` adds the module row. - `99-rollback.sql` undoes all three. The local seed mirrors these files. ## Verification - **Tests** (fresh run): gateway 16, services-system 107, mobile-api 552, portal 1233. `tsc` and lint report 0 errors, and `next build` succeeds. - **Review**: every task passed an Opus review gate, and a whole-branch Opus review returned READY. Its hardening findings were applied: limits on the settings, the same username key for the lock check and the history, the username collation, and the module icon. - **Live checks on the local stack** (real gateway and MySQL): - a username locks after 5 failures, and the login page shows the locked message; - the locked list shows it, and Unlock (with confirmation) clears it; - History filtering and paging work; - invalid settings are refused with plain messages; - an admin without the module gets 403 and "Not authorised"; - change-password shows the error for a wrong current password, and a success message otherwise; - history rows carry the browser user agent; - the pages work at 360px width. - **Playwright**: run against the portal dev server on the local stack. Screenshots were checked by hand. ## Follow-ups (not in this PR) - A services-auth outage counts as failed sign-ins, so a user who retries during one can get locked. - Narrow the existing `/blockLoginPeriod/**` gateway bypass to its read endpoints. 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01EFUzfj5akPxyikzGc2iAHM
ngqile added 13 commits 2026-11-30 07:00:59 +00:00
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EFUzfj5akPxyikzGc2iAHM
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EFUzfj5akPxyikzGc2iAHM
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EFUzfj5akPxyikzGc2iAHM
LoginSecurityService derives the admin lock from login_audit and the
ADMIN_LOGIN_BLOCK settings; /loginSecurity exposes lock check, record,
history, locked list, unlock, lockout settings and password rules. The
gateway routes /loginSecurity/** and lets the lock check and record
through without a user token for the sign-in path.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EFUzfj5akPxyikzGc2iAHM
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EFUzfj5akPxyikzGc2iAHM
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EFUzfj5akPxyikzGc2iAHM
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EFUzfj5akPxyikzGc2iAHM
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EFUzfj5akPxyikzGc2iAHM
mobile-api now records the browser user agent the portal forwards as
X-Client-User-Agent instead of the portal server's own.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EFUzfj5akPxyikzGc2iAHM
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EFUzfj5akPxyikzGc2iAHM
Found in the browser check: change-password history rows had no browser
or IP, settings errors named internal fields, and the dialog's new
password field read just "Password".

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EFUzfj5akPxyikzGc2iAHM
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EFUzfj5akPxyikzGc2iAHM
Settings get upper limits (a huge period made every lock check fail
open), the lock check uses the same 191-character key the history
stores, login_audit.username compares like user.username, and the
module gets its own icon. Docs and design notes follow.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EFUzfj5akPxyikzGc2iAHM
ngqile merged commit 256ad936f8 into main 2026-11-30 07:01:02 +00:00
Sign in to join this conversation.
No Reviewers
No labels
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: ngqile/co-lite#19