Classes
Section titled “Classes”AuditAdminContributor
Section titled “AuditAdminContributor”Admin panel contributor for audit log management.
Registered via oridecon.admin.contributors entry point.
Provides audit log search, filter, export, and verification status.
Dependencies are resolved from the container in on_admin_boot.
Resolve audit dependencies from the DI container.
| Parameter | Type | Description |
|---|---|---|
| `container` | ContainerResolverProtocol | None | The DI container resolver. |
Return the navigation items for this contributor.
Return the management page definitions for this contributor.
Search audit entries by query filters.
| Parameter | Type | Description |
|---|---|---|
| `query` | AuditQuery | Filter criteria. |
| Type | Description |
|---|---|
| list[AuditEntry] | Matching audit entries, newest-first. |
Export filtered audit entries as JSON or CSV.
| Parameter | Type | Description |
|---|---|---|
| `query` | AuditQuery | Filter criteria. |
| `format` | str | ``"json"`` or ``"csv"``. |
| Type | Description |
|---|---|
| bytes | Encoded bytes of the export. |
Return latest verification results.
| Type | Description |
|---|---|
| dict[str, Any] | Dict with ``verified`` bool and ``mismatches`` count. |
AuditBundleProvider
Section titled “AuditBundleProvider”Composite provider that wires the full Oridecon audit stack.
Composes AuditCoreProvider, AuditRetentionProvider, AuditVerifierProvider, AuditSchedulingProvider, and optionally AuditAdminProvider.
| Parameter | Type | Description |
|---|---|---|
| `config` | Audit configuration. When ``None``, the orchestrator injects the typed ``audit`` yaml section after construction and sub-providers are composed in register. | |
| `enable_admin` | Whether to register the admin panel contributor. |
Delegate registration to all sub-providers.
Late config binding: the orchestrator injects the typed audit
section (via config_key) after construction and before this
call. If configure() ran with no explicit config, compose now so
the automatic path behaves identically to the explicit one.
Delegate boot to all sub-providers.
Shutdown in reverse registration order.
AuditConfig
Section titled “AuditConfig”Configuration for the audit subsystem.
Attributes:
store_backend: Backend type — "sql" or "memory".
table_name: SQL table name for the unified audit store.
hmac_key: HMAC key for checksum computation (bytes).
retention_policy: Retention rules; defaults to 365 days.
verification_schedule: Cron expression for scheduled verification.
verification_batch_size: Entries to verify per verification run.
enable_admin: Whether to register the AuditAdminContributor.
AuditLogger
Section titled “AuditLogger”Core audit logger implementing AuditLoggerProtocol.
Fire-tolerant: log() catches all exceptions and emits a warning.
Audit failure must never block the operation that triggered it.
| Parameter | Type | Description |
|---|---|---|
| `store` | Underlying storage backend (AuditStoreProtocol). | |
| `retention` | Optional retention policy for computing entry expiry. |
Record an audit entry. Never raises.
| Parameter | Type | Description |
|---|---|---|
| `entry` | AuditEntry | The audit event to persist. |
Query entries matching filters. Returns empty list on error.
| Parameter | Type | Description |
|---|---|---|
| `query` | AuditQuery | Filter criteria encapsulated in an AuditQuery object. |
| Type | Description |
|---|---|
| list[AuditEntry] | List of matching entries, newest-first. |
AuditModule
Section titled “AuditModule”Oridecon audit module.
Global like EventsModule/QueueModule so any consumer module
(e.g. an app’s infrastructure provider) can resolve audit protocols
without declaring explicit imports.
Registers the full audit stack including store, logger, retention, verification, and optional admin panel contributor.
Usage
app = Application()app.use(AuditModule.configure( hmac_key=b"secret", retention_days=365,))app = Application()app.use(AuditModule.configure( hmac_key=b"secret", retention_days=365,))Or with an explicit AuditConfig section
app.use(AuditModule.configure(config=AuditConfig(store_backend="memory")))app.use(AuditModule.configure(config=AuditConfig(store_backend="memory")))Configure the audit module.
| Parameter | Type | Description |
|---|---|---|
| `config` | AuditConfig | None | Explicit AuditConfig section. When provided it wins over the keyword shortcuts below. |
| `hmac_key` | bytes | None | HMAC key for checksum computation. |
| `store_backend` | str | None | ``"sql"`` or ``"memory"``. |
| `table_name` | str | None | SQL table name. |
| `retention_days` | int | None | Default retention in days. |
| `enable_admin` | bool | Register admin contributor. **overrides: Additional AuditConfig fields. |
| Type | Description |
|---|---|
| DynamicModule | DynamicModule ready for ``app.use()``. |
Note
Called with no arguments, the module passes None through so
the orchestrator injects the typed audit yaml section before
registration (framework defaults apply when no section exists).
AuditPurger
Section titled “AuditPurger”Purges expired audit entries and emits a meta-audit log on each run.
| Parameter | Type | Description |
|---|---|---|
| `store` | The underlying store to purge entries from. | |
| `retention` | Retention policy to evaluate entries. | |
| `audit_logger` | Optional audit logger for meta-audit events. |
Evaluate all entries and purge those past expiry.
| Parameter | Type | Description |
|---|---|---|
| `dry_run` | bool | When True, only count entries that would be purged without deleting anything. Defaults to False. |
| Type | Description |
|---|---|
| int | Number of entries purged (or that would be purged in dry-run). |
AuditVerifier
Section titled “AuditVerifier”Tamper detection via HMAC-SHA256 checksum verification.
Implements AuditVerifierProtocol. Entries are verified by recomputing
the HMAC over the canonical persisted row (entry_to_row) and
comparing against the checksum the store read back. Entries written
before checksums existed carry no stored checksum and are reported
honestly as unverifiable (no_checksum_present) — never silently
clean, never falsely tampered.
| Parameter | Type | Description |
|---|---|---|
| `store` | Audit store backend (any AuditStoreProtocol implementation). | |
| `config` | Audit configuration containing the HMAC key. |
Verify checksums for the most recent entries.
| Parameter | Type | Description |
|---|---|---|
| `limit` | int | Number of recent entries to verify. |
| Type | Description |
|---|---|
| list[AuditMismatch] | List of AuditMismatch objects (empty = all verified or not applicable). |
Verify checksum for a single entry.
Recomputed the HMAC over the canonical persisted row and compares it against the stored checksum. Older entries may carry v1 checksums while new entries carry v2; both are accepted. Entries with no stored checksum are reported as unverifiable.
| Parameter | Type | Description |
|---|---|---|
| `entry` | AuditEntry | The audit entry to verify. |
| Type | Description |
|---|---|
| AuditMismatch | None | None when the entry verifies clean; an AuditMismatch whose reason is ``checksum_mismatch`` when tampered or ``no_checksum_present`` when the entry carries no stored checksum and cannot be verified. |
InMemoryAuditStore
Section titled “InMemoryAuditStore”In-memory audit store implementing AuditStoreProtocol.
Uses a bounded deque. Thread-safe for single-event-loop async usage.
| Parameter | Type | Description |
|---|---|---|
| `max_entries` | Maximum capacity. Oldest entries dropped when full. |
Persist a single audit entry.
Retrieve entries matching filters, newest-first.
Return count of entries matching filters.
Delete entries whose stored expiry precedes or equals cutoff.
Mirrors the SQL store: only entries stamped with the
__expires_at metadata key are candidates for deletion.
Clear all entries (test helper).
PolicyBasedRetention
Section titled “PolicyBasedRetention”Evaluates retention policies to determine entry expiry.
Implements RetentionPolicyProtocol.
| Parameter | Type | Description |
|---|---|---|
| `policy` | Retention policy configuration. |
Determine retention decision based on severity and source.
| Parameter | Type | Description |
|---|---|---|
| `entry` | AuditEntry | The audit entry to evaluate. |
| Type | Description |
|---|---|
| RetentionDecision | RetentionDecision.RETAIN if indefinite, RETAIN_UNTIL otherwise. |
Return expiry datetime for an entry, or None for indefinite retention.
| Parameter | Type | Description |
|---|---|---|
| `entry` | AuditEntry | The audit entry to evaluate. |
| Type | Description |
|---|---|
| datetime | None | UTC expiry datetime, or None. |
Functions
Section titled “Functions”audited
Section titled “audited”Mark an async function for automatic audit logging.
Attaches audit metadata that an audit middleware or interceptor can
read to automatically log an AuditEntry on successful execution.
| Parameter | Type | Description |
|---|---|---|
| `action` | str | Dot-notation action identifier (e.g. ``"user.update"``). |
| `resource_type` | str | Kind of affected resource (e.g. ``"User"``). |
| `severity` | str | Default severity level for the audit entry. |
| Type | Description |
|---|---|
| Callable[[F], F] | Decorator that attaches audit metadata to the function. |
Example
@audited("user.update", resource_type="User", severity="medium")async def update_user(self, user_id: str, data: dict) -> User: ...@audited("user.update", resource_type="User", severity="medium")async def update_user(self, user_id: str, data: dict) -> User: ...compute_audit_checksum
Section titled “compute_audit_checksum”Compute HMAC-SHA256 hex digest for audit entry data.
Includes entry_schema_version in the canonical form so the verifier
knows which fields were expected at write time.
| Parameter | Type | Description |
|---|---|---|
| `entry_data` | dict[str, Any] | Dictionary of audit entry fields. |
| `key` | bytes | HMAC secret key bytes. |
| `schema_version` | int | Schema version to embed (default 2). Existing entries use 1; new entries use 2. |
| Type | Description |
|---|---|
| str | Hex-encoded HMAC-SHA256 digest. |
verify_audit_checksum
Section titled “verify_audit_checksum”Verify expected checksum matches computed checksum using constant-time comparison.
When schema_version is None, the version is extracted from
entry_data (defaults to 1 if absent) so old entries verify
against v1 checksums and new entries verify against v2.
| Parameter | Type | Description |
|---|---|---|
| `entry_data` | dict[str, Any] | Dictionary of audit entry fields. |
| `key` | bytes | HMAC secret key bytes. |
| `expected` | str | Previously stored checksum hex string. |
| `schema_version` | int | None | Explicit schema version override. When ``None``, extracted from entry_data or defaults to 1. |
| Type | Description |
|---|---|
| bool | True if checksum matches, False if tampered. |