Expand description
Sign-in security log and account lockout (#433).
Every password sign-in, lockout, sign-out, password reset and change
to who may do what (user flags, role memberships, role permissions)
lands a row in cms_security_event, per tenant, which superusers read
at /cms-admin/security-log.
Two kinds of login feed it:
- Logins the CMS owns — the member form (
/members/login), the headless API login,/cms-admin/logout, the password-reset screens and the user and role screens — record their rows directly withrecord. - Logins the framework owns — the tenant admin
POST /loginand its JWT login — are recorded from the framework’s auth signals, connected byinstall. The signals carry no tenant, so the receiver takes it fromrustango::tenant_log, which the framework’s request log fills (on unless[logging] access_log = false). Without it these events are not stored.
§Lockout
Every password login goes through the framework’s shared
rustango::login_throttle gate in the tenant scope, so the admin
form, the member form and the API login share one per-account lock
(keyed by the submitted name, so an unknown name locks exactly like a
real one and the lock is no account-enumeration oracle), plus per-IP
and per-tenant limits. The lock is time-bounded: an attacker can hold
an account locked only for RCMS_LOGIN_LOCKOUT_SECONDS after their
last burst, never for good.
The policy defaults to the framework’s (5 failures in an hour lock
the account for 15 minutes, or [auth] lockout_*). Set any of
RCMS_LOGIN_LOCKOUT_ATTEMPTS, RCMS_LOGIN_LOCKOUT_SECONDS,
RCMS_LOGIN_LOCKOUT_WINDOW_SECONDS to override it.
Attempts refused while an account is locked are not logged one by one — that would let an anonymous client grow the table without any limit — only the failure that locked it is.
Structs§
- Access
- What a user may do: the flags and roles a permission change compares.
- Entry
- One event to store. Build with
Entry::newand the setters. - Filter
- What the viewer filters by. Empty strings mean “any”.
- Login
Request - What a login handler needs from the request: the client address the throttle limits by, and the details a log row keeps.
- Security
Event
Constants§
- DEFAULT_
RETENTION_ DAYS - Rows older than this many days are pruned unless
RCMS_SECURITY_LOG_RETENTION_DAYSsays otherwise. - EVENTS
- Every event, in the order the viewer offers them as filters.
- EVENT_
LOCKOUT - A failure locked the account.
- EVENT_
LOGIN - A password sign-in succeeded.
- EVENT_
LOGIN_ FAILED - A password sign-in was refused (unknown name, wrong password, disabled account).
- EVENT_
LOGOUT - A session was ended.
- EVENT_
PASSWORD_ RESET - A password was changed through a reset link.
- EVENT_
PASSWORD_ RESET_ REQUESTED - A password-reset link was issued.
- EVENT_
PERMISSIONS_ CHANGED - A user’s superuser flag, active flag or roles, or a role’s permissions, were changed.
Functions§
- count
- How many rows match
filter. - describe_
new_ user - A new user’s access in words.
- describe_
role_ change - The codenames a role gained and lost (
role “Editor”: + cms_page.publish; − cms_page.delete), orNonewhen its set is unchanged. - describe_
user_ change before → afterin words (superuser: off → on; roles: none → Editor), orNonewhen nothing that grants access changed.- install
- Apply the
RCMS_LOGIN_LOCKOUT_*policy and start recording the framework’s own logins. Idempotent;crate::ensure_seededcalls it at boot. - is_
locked truewhen any ofnamesis locked out ofsiteright now.- list
- One page of the rows matching
filter, newest first. - prune
- Delete rows older than
days. Returns how many went. - record
- Store
entryintenant_slug’s log. Best-effort: a failed write is logged, never returned, so a broken log cannot break signing in. - unlock
- Clear the lock and the failure count of
usernameinsite, as a successful sign-in would.