Skip to main content

Crate ash_log

Crate ash_log 

Source
Expand description

§ash-log

Security audit logging for Rust applications.

Provides structured audit logging for security events including authentication, authorization, method invocations, and policy violations.

For logs that must resist deliberate modification, enable the hmac-chain feature and use HmacChainIntegrity. The default ChecksumIntegrity uses an unkeyed hash and detects only accidental corruption.

Features: append-only logs, integrity verification, pluggable backends.

§Quick start

use ash_log::*;
use std::sync::Arc;

let backend = Arc::new(StdoutAuditBackend);
let integrity = SequenceIntegrity::new();

let mut event = AuditEvent::builder()
    .event_type(AuditEventType::AuthenticationAttempt)
    .principal("alice@example.com")
    .result(AuditResult::Success)
    .build();

integrity.add_integrity(&mut event);
backend.log_audit(&event);

Modules§

ocsf
OCSF (Open Cybersecurity Schema Framework) 1.8.0 support for ash-log.

Macros§

ash_audit
Emit a security event — the tier that is never filtered.
ash_debug
Emit a Debug diagnostic.
ash_diagnostic
Emit a diagnostic record at an explicit severity.
ash_error
Emit an Error diagnostic.
ash_info
Emit an Info diagnostic.
ash_logger
Build a Logger from named parts.
ash_trace
Emit a Trace diagnostic.
ash_warn
Emit a Warning diagnostic.

Structs§

AshLogLayer
A tracing_subscriber layer that writes every event it sees to a Logger as a diagnostic record.
AsyncBackend
Writes events on a dedicated thread.
AsyncBackendBuilder
Builder for AsyncBackend.
AuditEvent
A security audit event representing a significant action or decision
AuditEventBuilder
Builder for creating audit events
BufferedAuditBackend
Buffers events in memory, writing them to an inner backend only when the buffer fills or flush is called.
ChecksumIntegrity
Adds checksum of event fields to detect tampering
CombinedIntegrity
Combines multiple integrity mechanisms
CountingErrorSink
Counts failures and lost events without storing them.
Directive
One module=level rule.
EventClock
An HlcTimestamp as it is stored on an event.
FileBackend
Appends audit events to a file as JSON lines.
FileBackendBuilder
Builder for FileBackend.
FilterDirectives
A parsed set of per-module thresholds.
FnErrorSink
Calls a closure for each failure.
FnRedactor
Redacts whatever a closure objects to.
HlcClock
A thread-safe Hybrid Logical Clock.
HlcTimestamp
A Hybrid Logical Clock timestamp.
HmacChainIntegrity
Tamper-evident integrity using a keyed HMAC-SHA256 hash chain.
IgnoreErrors
Discards failures. The default, preserving the behaviour of backends that predate this trait.
KeyRedactor
Redacts values whose key matches a denylist, case-insensitively.
LiveFilter
A filter that can be replaced while the logger is running.
Logger
Writes audit events, applying a two-tier admission policy before any integrity metadata is attached.
LoggerBuilder
Builder for Logger.
MultiAuditBackend
Writes audit events to multiple backends simultaneously
NoIntegrity
No integrity checking
NoRedaction
Redacts nothing. The default, so redaction is opt-in.
NoopAuditBackend
Discards all audit events (testing only)
ParseSeverityError
Returned when a string does not name an AuditSeverity.
Provenance
Where an event was emitted from.
RotationPolicy
When to start a new file.
Scope
Builds a set of scope fields.
ScopeFields
Fields bound by a scope, and whatever its parent bound.
ScopeGuard
Restores the previous scope when dropped.
SequenceIntegrity
Adds monotonically increasing sequence numbers to detect gaps or duplicates
StderrAuditBackend
Writes audit events to stderr as JSON lines
StderrErrorSink
Writes failures to stderr.
StdoutAuditBackend
Writes audit events to stdout as JSON lines
WriteError
A write that did not reach its destination.

Enums§

AuditEventType
Types of recorded events.
AuditResult
Result of an audited action
AuditSeverity
Severity level of an audit event, ordered from least to most severe.
ChainError
Why a chain failed to verify.
HlcError
Errors that can be returned by HlcClock operations.
OverflowPolicy
What to do when the queue is full.
RotationError
Why a key rotation was refused.

Constants§

CHAIN_INDEX_FIELD
Metadata key holding the event’s position in the chain.
KEY_ID_FIELD
Metadata field naming the key an entry was signed with.
MAC_FIELD
Metadata key holding the chained HMAC of an event.
REDACTED
What replaces a redacted value.
WRITER_FIELD
Metadata field naming the writer that produced an entry.

Traits§

AuditBackend
Audit log backend trait. Synchronous writes ensure events persist before execution continues.
AuditIntegrity
Audit integrity verification trait
ErrorSink
Receives write failures reported by a backend.
Redactor
Decides which fields are secret.

Functions§

log_auth_event
Log authentication/authorization events.
log_security_violation
Log security policy violations (rate limits, banned IPs, etc.).