Skip to main content

Administrative session risk observation

Added in 1.0.23

Risk observation records an explainable assessment of an administrative session. Chassis shows the result below the sessions in the personal profile and on an authorized account card. The feature observes activity and leaves the login decision to the existing authentication rules.

Connect GlobalConfig and Celery​

Install and configure Django-GC 1.1.5 or newer and Celery. Install django-celery-beat and add django_celery_beat to INSTALLED_APPS. Enable Chassis user-session and login-attempt tracking. Include django_chassis.tasks in Celery task discovery. Use the same Django settings and database for web, worker and scheduler, and the same broker for worker and beat.

Register the Chassis provider with a category ID available in this project.

from django_gc import ProviderDefinition

GLOBAL_CONFIG_PROVIDERS = [
ProviderDefinition(
provider='django_chassis.configuration.RiskConfigurationProvider',
category_ids={'observation': 30},
),
]

Apply migrations, install the configuration definitions, then initialize the recurring task.

python manage.py migrate
python manage.py initialize_global_configs
python manage.py initialize_risk_schedule

Launch the project's Celery worker and database-backed beat scheduler. The initialization command creates the minute schedule risks.observe_admin_sessions for risks.schedule_observations when it is missing. The initial schedule sends to the default queue. Configure the worker to consume that queue and any queue your Celery routes assign to risks.assess_session or to scheduler continuations. Running the command again preserves the operator's schedule settings. Set risk.is_enabled to true when ready to calculate assessments. Both scheduling and execution check the flag.

Interpret an assessment​

SignalDefault
New IP15 points if the address is absent from sessions of the same account in the 30 days before the assessed session began.
New client10 points if the stored browser and OS pair is absent in the same history.
Failed logins30 points after at least five recorded failures matching the account, login or email in the 15 minutes before assessment.
LevelsMedium starts at 25, high at 50, and critical at 75. The total is capped at 100.
FreshnessThe default assessment lifetime is 300 seconds. A policy change also makes a stored result stale.

Weights, thresholds, history duration, and assessment lifetime are editable in the provider's GlobalConfig category. The provider validates their ranges and requires the level thresholds to increase. Each triggered signal contributes its weight once. An unavailable IP or browser-and-OS signal yields an insufficient-data result without a numerical score.

RiskAssessment stores the session, interval, policy fingerprint and snapshot, optional score and level, and the signals that explain the result. The scheduler pages through active, unexpired UserSession records and enqueues risks.assess_session with a session UUID. The same registry can include sessions created by custom authentication surfaces. A repeated job with the same session, interval and policy reuses the persisted assessment. RiskProfileService.get_summary(actor=..., user=...) supplies the visible state. Accounts can read their own assessment. Seeing another account's assessment requires django_chassis.view_riskassessment and access to the account screen.

If a new session has no assessment yet, the card shows a waiting state. Expired results and results made under a different current policy are marked stale. If there is no active administrative session, the card reports that state.

Add a project risk signal​

Added in 1.0.23

Register a RiskSignalProvider in the ready() method of a Django application. Installed third-party Django apps can use the same API. Use a stable namespaced code, such as my_app.concurrent_session. Use a positive version and increment it when the signal's logic changes.

from django.apps import AppConfig
from django.utils.translation import gettext_lazy as _

from django_chassis.providers import RiskSignalProvider
from django_chassis.registries import RiskSignalRegistry


class MyAppConfig(AppConfig):
name = 'my_app'

def ready(self):
from my_app.risk import observe_concurrent_session

RiskSignalRegistry.register(RiskSignalProvider(
code='my_app.concurrent_session',
label=_('Concurrent administrative session'),
version=1,
weight_key='my_app.concurrent_session_weight',
handler=observe_concurrent_session
))

Declare the weight (an integer from 0 to 100) and any additional integer or boolean setting_keys in your application's GlobalConfig provider. Run initialize_global_configs after adding the declarations. The handler accepts RiskSignalContextDTO with the session, assessment time, and a read-only mapping of the declared settings. It returns RiskSignalObservationDTO with availability, whether the signal triggered, and an optional nonnegative count. Chassis applies the weight.

An unavailable source contributes zero points by default and appears as unavailable in the result. Use is_required=True if the assessment needs that source to produce a score. Handlers run outside the session write transaction. They must limit external I/O and read only the data needed for the assessment. Chassis records the result and the provider's version, required flag, and settings in the policy snapshot. Stored signs remain readable by code after a provider is removed.

See the training Admin and upgrade instructions.