Skip to main content
Pre-release

This release is a pre-release and may not be stable for production use.

django-sec-audit-enforcement

The enforcement layer for django-sec-audit. It turns the detection brain in sec-audit-rules into action: it holds block state (temp blocks in Redis, permanent blocks in Postgres with a Redis read-through cache), applies a matched rule's RuleAction as a block, checks incoming requests against active blocks before the view runs, and emits every enforcement decision as OTel JSONL on the existing sec_audit.audit logger.

Status: alpha. Master switch is off by default — installing the package is inert until SEC_AUDIT_ENFORCEMENT['enabled'] is set.

Design

  • Temp blocks → Redis only (self-expiring TTL keys). Permanent blocks → Postgres (durable, auditable) + a Redis read-through cache carrying a long refresh TTL (never a no-TTL key, which managed Redis can silently evict).
  • One scope vocabulary (ip/user/session/route) shared with detection, via the sec-audit-rules ScopeRegistry. The ip scope is resolved through django-sec-audit's trusted-proxy config — never a raw X-Forwarded-For.
  • Fail-open by default, per-path fail-closed opt-in.
  • No feedback loop: emitted audit.enforcement.* events are skipped by the rule engine.

Documentation

Full docs live in docs/:

  • Getting started — install, INSTALLED_APPS/MIDDLEWARE, migrate, enable, verify
  • Configuration — every SEC_AUDIT_ENFORCEMENT key + rule_actions/block_rules
  • Architecture — the ingress/egress paths, the tiered store, fail modes
  • Custom rules — write and register your own Rule
  • Enforcement events — the four audit.enforcement.* events
  • Operations — deploy tiers, system checks, the PermanentBlock model, revocation

Custom rules

The built-in rules (brute_force_login, login_throttle, repeated_client_error, and resource_enumeration — alert-only, and active only when a history store such as Redis is configured) can be extended with your own. Subclass sec_audit.rules.Rule, then register it via SEC_AUDIT_ENFORCEMENT['rules'] (appended to the built-ins):

SEC_AUDIT_ENFORCEMENT = {
    'enabled': True,
    'rules': ['myapp.security.rules.GeoVelocityRule'],
    # observe-only until you map the rule's name to an action:
    'rule_actions': {'geo_velocity': {'action': 'temp_block', 'scopes': ['ip']}},
}

A custom rule observes (detect + log, no block) until it has a rule_actions entry, and runs on the egress path unless it sets safe_for_enforcement = True. See the full Custom rules guide.

Metadata

Release files for django-sec-audit-enforcement 0.1.0a2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for django-sec-audit-enforcement 0.1.0a2
File Size Uploaded Provenance Actions
django_sec_audit_enforcement-0.1.0a2.tar.gz 52.9 kB Without provenance Details for django_sec_audit_enforcement-0.1.0a2.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for django-sec-audit-enforcement 0.1.0a2
File Interpreter ABI Platform Actions
django_sec_audit_enforcement-0.1.0a2-py3-none-any.whl Python 3 none any Details for django_sec_audit_enforcement-0.1.0a2-py3-none-any.whl

Total release size: 89.7 kB

Release files / django_sec_audit_enforcement-0.1.0a2.tar.gz

Download URL django_sec_audit_enforcement-0.1.0a2.tar.gz
Size 52.9 kB
Tags Source
SHA-256 checksum
How to use checksums
b23a2b390b7dbbd0c7912841e96dc2f33f9ede860c6eaf3f87c154cadfc436ba
BLAKE2b-256 checksum
How to use checksums
0e335d0c8cde29ee109dc819622babaa191d4fa628b04a7e001189baceba2f58
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.2

Release files / django_sec_audit_enforcement-0.1.0a2-py3-none-any.whl

Download URL django_sec_audit_enforcement-0.1.0a2-py3-none-any.whl
Size 36.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
852fecf2b61925ee2d0dbbee3d60e6bda9a9bb16c72d5c7ffab1db51076130a9
BLAKE2b-256 checksum
How to use checksums
424fff310eacd4b495f1524acb507a0f6c8eb9e2d8588c66abd6c592bb0a7b04
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.2

Security for django-sec-audit-enforcement 0.1.0a2

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page