Skip to main content

Module security_log

Module security_log 

Source
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 with record.
  • Logins the framework owns — the tenant admin POST /login and its JWT login — are recorded from the framework’s auth signals, connected by install. The signals carry no tenant, so the receiver takes it from rustango::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::new and the setters.
Filter
What the viewer filters by. Empty strings mean “any”.
LoginRequest
What a login handler needs from the request: the client address the throttle limits by, and the details a log row keeps.
SecurityEvent

Constants§

DEFAULT_RETENTION_DAYS
Rows older than this many days are pruned unless RCMS_SECURITY_LOG_RETENTION_DAYS says 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), or None when its set is unchanged.
describe_user_change
before → after in words (superuser: off → on; roles: none → Editor), or None when nothing that grants access changed.
install
Apply the RCMS_LOGIN_LOCKOUT_* policy and start recording the framework’s own logins. Idempotent; crate::ensure_seeded calls it at boot.
is_locked
true when any of names is locked out of tenant_slug right now.
list
One page of the rows matching filter, newest first.
prune
Delete rows older than days. Returns how many went.
record
Store entry in tenant_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 username in tenant_slug, as a successful sign-in would.