Skip to main content

openmoat_proxy/
audit.rs

1//! One record per connection decision.
2//!
3//! As with `moat guard`, the record is part of the decision: a connection that
4//! cannot be recorded is not made. The CLI records into the moat audit log;
5//! this crate stays free of storage.
6
7use openmoat_core::Decision;
8
9/// One connection decision.
10#[derive(Debug, Clone, Copy)]
11pub struct Connection<'a> {
12    /// The session whose credential the request carried (ADR-027). `None` for
13    /// a proxy without sessions, and for a request refused for its credential;
14    /// the recorder then uses its own session.
15    pub session: Option<&'a str>,
16    /// Request method (`CONNECT`, `GET`, …); `None` when the head was unreadable.
17    pub method: Option<&'a str>,
18    /// Destination host and port; `None` when the head was unreadable.
19    pub destination: Option<(&'a str, u16)>,
20    /// The verdict and the rules behind it.
21    pub decision: &'a Decision,
22    /// Time from accepting the connection to this decision, in microseconds.
23    pub latency_us: u64,
24}
25
26/// Where connection decisions go. An error refuses the connection.
27pub trait Recorder: Send + Sync {
28    /// Record one decision.
29    fn record(&self, connection: &Connection<'_>) -> Result<(), RecordError>;
30
31    /// Told when [`record`](Self::record) failed. The connection is refused
32    /// either way; this is where the failure is reported, somewhere other than
33    /// the audit log that just failed. The default does nothing.
34    fn unrecorded(&self, error: &RecordError) {
35        let _ = error;
36    }
37}
38
39/// A decision could not be recorded.
40#[derive(Debug, thiserror::Error)]
41#[error("audit log unavailable: {0}")]
42pub struct RecordError(pub String);