feat(auth): suspicious-login notify-and-approve gate for password login (PMS-658) #451
Loading…
Reference in a new issue
No description provided.
Delete branch "feat/PMS-658-suspicious-login-approval"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Implements PMS-658.
Adds a suspicious-login notify-and-approve gate to mokosh-server's password login. When enabled and a login clears password/MFA but looks suspicious, the session and tokens are withheld: a single-use 6-digit code is emailed and the client completes the login by re-POSTing
/auth/loginwithapproval_code(mirrors the existingmfa_requiredre-POST). It never locks the account, and normal logins are untouched.Design decisions (from the issue discussion)
login_location_decisionsignal, needsIP2LOCATION_DB_PATH) OR a new device (a client-supplieddevice_id, hashed intouser_login_devices; fail-open when absent, so it degrades to country-only). The first-ever country/device is baseline, not flagged, mirroring PMS-657.LOGIN_APPROVAL_ENABLED, default OFF - the gate can withhold a login, so it is opt-in per deployment for a staged rollout (PMS-289 lesson). Off = unchanged PMS-657 alert-only behaviour.Scope (v1) and findings
device_id; it needs a dedicated completion endpoint (follow-up). Portal login and an IP signal are also follow-ups.Changes
090_login_approvals(pending challenge: hashed single-use code, expiry, attempt cap) and091_user_login_devices(known devices, hasheddevice_id), both with the explicit FORCE'dtenant_isolationRLS policy.LoginResponse.approval_required;LoginRequest.approval_code+device_id.AuthService: the gate runs after password/MFA and before session/token mint -assess_login(country + device decision),issue_login_approval(store hashed code + email),verify_login_approval(match / attempt-cap / consume),record_login_success(record country + device on a cleared login).with_login_approvalbuilder +LOGIN_APPROVAL_ENABLEDwired throughmain.rs/create_api_router.send_login_approval_codedefaultMailermethod (mirrorssend_new_login_location).Tests
Postgres integration (
tests/login_approval.rs, device signal, no geoip needed): a new-device login returnsapproval_requiredwith no tokens, a wrong code is rejected, the emailed code completes the login and records the device, and a known device is not re-flagged; plus a gate-disabled pass-through pinning the default-off behaviour.Follow-ups
device_id, and handleapproval_requiredwith an inline code field (mirrors the MFA field).Acceptance criteria