Expand description
The dynamic-rules carrier: the reference DynamicRules wire model
and its manager-side logic (handlers/_dynamic_rule_*.py +
_dynamic_rules.py).
The carrier holds the wire model, the last-known snapshot envelope, the update gating, the event matcher, and the config application. Sources, piece by piece:
- the model:
_dynamic_rules.pyDynamicRules(the same field set the guard-agent wire model carries; the defaults land verbatim -ttl = 300,ip_ban_duration = 3600,emergency_mode = false); - the snapshot envelope:
dump_last_known_rules_snapshot/load_last_known_rules_snapshot(theschema_versionguard rejects unsupported versions at load); - the gating:
DynamicRuleManager._should_update_rules(a new rule id always updates; a same-id rule only when its version advances),_has_rule_expired/_reject_if_already_expired; - the correlation:
DynamicRuleManager.match_event(the IP, country, and event-type arms the enricher reads); - the application:
DynamicRuleApplicationMixinlandings on the unified config - uppercased country sets, the global/window/endpoint rate tiers, theVALID_CLOUD_PROVIDERS-validated cloud set (theAWS:!regionscoping survives verbatim), the ReDoS-validated user agent list (rejected patterns surface in the outcome), the feature toggles, and the emergency-mode activation with the halved auto-ban threshold (max(1, threshold / 2)).
The module is pure: the bans, unbans, and pattern additions come back
in the AppliedDynamicRules outcome for the caller’s stateful
seams (the ban manager, the pattern store), while the config-mutating
half lands directly on the SecurityConfig the caller owns.
Structs§
- Applied
Dynamic Rules - What applying one rule produced.
- Dynamic
Rules - The reference
DynamicRuleswire model, field for field (the same shape the guard-agent models carry). - Last
Known Rules Snapshot - The reference snapshot envelope (
LastKnownRulesSnapshot): the schema version beside the mirrored rules. - Snapshot
Error - A snapshot load failure (the version guard and the JSON decode).
Constants§
- LAST_
KNOWN_ RULES_ SNAPSHOT_ SCHEMA_ VERSION LAST_KNOWN_RULES_SNAPSHOT_SCHEMA_VERSION(the envelope guard).
Functions§
- apply_
to_ config - The config-mutating half of
_apply_rules+DynamicRuleApplicationMixin. - apply_
to_ config_ with_ validation_ cache apply_to_configwith the optional disk-backed validation cache.- dump_
last_ known_ rules_ snapshot dump_last_known_rules_snapshot: the versioned JSON envelope.- expired_
identity _reject_if_already_expired’s de-duplication key: the same expired rule logs its warning once.- has_
expired _has_rule_expired: pastexpires_atatnow(an absent expiry never expires).- load_
last_ known_ rules_ snapshot load_last_known_rules_snapshot: the version-guarded decode.- matches_
event match_event: the enrichment correlation.- should_
update _should_update_rules: the first rule always updates; a same-id rule only when its version advances (a stale replay never re-applies).