1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
//! Layer 9 — Audit logging.
//!
//! Where Layer 8 ([`crate::monitor`]) reports **anomalies and
//! failures**, Layer 9 records **every operation** the vault performs.
//! Every successful access — register, read, rotate, unregister,
//! master-unlock attempt — produces an [`AuditEvent`] that the
//! configured [`AuditSink`] receives.
//!
//! The audit trail is the forensic complement to the monitor:
//! monitors tell you when something went wrong; audit logs tell you
//! what happened across the lifetime of the vault, in order.
//!
//! # Storage discipline
//!
//! Audit events are designed to be safe to ship to remote sinks
//! (centralized log aggregators, SIEM systems, compliance archives).
//! Every field is sanitized by trait contract:
//!
//! - **No key bytes** — the vault never passes raw key material to a
//! sink. Only the key's name appears.
//! - **No caller-supplied secrets** — the `note` field is
//! `Cow<'static, str>`; caller responsibility to keep it free of
//! key-equivalent values.
//!
//! # Default
//!
//! The default sink is [`NoAudit`] — events are constructed and
//! discarded. Zero allocations on the happy path (the event struct is
//! built on the stack and dropped immediately).
//!
//! Enable a real sink with [`KeyVaultBuilder::with_audit_sink`](crate::KeyVaultBuilder::with_audit_sink).
use Cow;
use String;
use fmt;
use Duration;
use ThreadId;
pub use NoAudit;
pub use LogAudit;
/// Discriminant of the operation an [`AuditEvent`] describes.
///
/// `#[non_exhaustive]` — new variants are additive.
/// Single record in the vault's audit trail.
///
/// Constructed by the vault on every operation; passed to the
/// configured [`AuditSink`]. All fields are non-secret and safe to ship
/// to log aggregators / SIEM systems.
///
/// `#[non_exhaustive]` — additional fields (caller identity, request
/// id correlation, etc.) may be added in minor releases.
/// Outbound channel for the vault's audit trail.
///
/// # Implementor contract
///
/// - **Non-blocking.** Sink calls must return promptly. Network / disk
/// work belongs on a background worker.
/// - **No panics.** A panicking sink implementation is a bug in the
/// implementation, not the vault.
/// - **No back-pressure into the vault.** If the sink is overloaded,
/// shed events internally — never block the caller.
/// - **`Send + Sync`.** Sinks are shared across threads.
// Blanket forwarding impl so callers can pass a pre-wrapped
// `Arc<dyn AuditSink>` to APIs that accept `impl AuditSink`.