pub struct AuditEvent {Show 14 fields
pub timestamp: SystemTime,
pub event_type: AuditEventType,
pub correlation_id: Option<String>,
pub remote_addr: Option<SocketAddr>,
pub principal: Option<String>,
pub method: Option<String>,
pub result: AuditResult,
pub severity: AuditSeverity,
pub metadata: HashMap<String, Value>,
pub params: Option<Value>,
pub error: Option<String>,
pub message: Option<String>,
pub provenance: Provenance,
pub hlc: Option<EventClock>,
}Expand description
A security audit event representing a significant action or decision
Fields§
§timestamp: SystemTimePrecise timestamp with nanosecond precision
event_type: AuditEventTypeType of audit event
correlation_id: Option<String>Unique correlation ID spanning the request chain
remote_addr: Option<SocketAddr>Remote address of the client
principal: Option<String>Principal identifier (user ID, API key, certificate DN, etc.)
method: Option<String>Method or action being performed
result: AuditResultResult of the action
severity: AuditSeverityEvent severity level
metadata: HashMap<String, Value>Additional context and metadata
params: Option<Value>Request parameters (sanitized)
error: Option<String>Error message if result is Failure or Denied
message: Option<String>Human-readable message.
Primarily carried by AuditEventType::Diagnostic records. It is part
of the canonical form, so it is covered by any integrity mechanism.
provenance: ProvenanceWhere the event was emitted from.
Part of the canonical form, so provenance is covered by any integrity mechanism: it can be proved, not merely recorded.
hlc: Option<EventClock>Monotonic causal timestamp, when the logger was given a clock.
timestamp comes from the system clock and can move
backwards; this cannot. It is part of the canonical form, so the causal
ordering is covered by the integrity mechanism. Absent unless the hlc
feature is enabled and a clock is configured, and skipped when absent,
so events written without it canonicalize exactly as before.
Implementations§
Source§impl AuditEvent
impl AuditEvent
Sourcepub fn diagnostic<S: Into<String>>(message: S) -> AuditEventBuilder
pub fn diagnostic<S: Into<String>>(message: S) -> AuditEventBuilder
Start building a diagnostic log record.
Pre-sets AuditEventType::Diagnostic,
AuditResult::NotApplicable, and the message, so a message-shaped log
line does not have to invent a security classification it does not have.
The default severity is AuditSeverity::Info; set an explicit level
with severity.
Diagnostic records are subject to level filtering, unlike every other event type.
let event = AuditEvent::diagnostic("cache warm complete")
.severity(AuditSeverity::Debug)
.build();
assert_eq!(event.event_type, AuditEventType::Diagnostic);
assert!(!event.event_type.is_security_relevant());
assert_eq!(event.message.as_deref(), Some("cache warm complete"));Sourcepub fn builder() -> AuditEventBuilder
pub fn builder() -> AuditEventBuilder
Create a new audit event builder
Sourcepub fn add_metadata<K: Into<String>, V: Into<Value>>(
&mut self,
key: K,
value: V,
)
pub fn add_metadata<K: Into<String>, V: Into<Value>>( &mut self, key: K, value: V, )
Add a metadata entry
Sourcepub fn with_correlation_id(self, correlation_id: Option<String>) -> Self
pub fn with_correlation_id(self, correlation_id: Option<String>) -> Self
Set the correlation ID from a request
Sourcepub fn with_principal<S: Into<String>>(self, principal: S) -> Self
pub fn with_principal<S: Into<String>>(self, principal: S) -> Self
Set the principal from connection context
Sourcepub fn with_remote_addr(self, addr: SocketAddr) -> Self
pub fn with_remote_addr(self, addr: SocketAddr) -> Self
Set the remote address