Skip to main content

goliath_normalize/
lib.rs

1//! Declarative source definitions that turn raw log records into OCSF events.
2//!
3//! A source definition says, in YAML, how a log source's bytes split into
4//! records, how a record decodes, which kind of record it is, and where each
5//! of its fields goes in OCSF. People who know a log source can write one
6//! without writing Rust. The model is `docs/adr/0007-source-and-parser-model.md`.
7//!
8//! Nothing a source sends is dropped. A record that cannot become an event is
9//! a [`DeadLetter`] with its raw bytes intact. A field whose value does not
10//! convert is kept as written under `unmapped` and reported as an [`Issue`],
11//! and the event still goes on to detection.
12//!
13//! Definitions shipped with this crate live in `sources/`, each with fixtures
14//! of raw records and the events they must produce.
15//!
16//! # Example
17//!
18//! ```
19//! use goliath_normalize::{Normalizer, Outcome, SYSMON};
20//!
21//! let sysmon = Normalizer::from_yaml(SYSMON)?;
22//! let raw = br##"{"Event": {
23//!     "System": {
24//!         "Provider": { "#attributes": { "Name": "Microsoft-Windows-Sysmon" } },
25//!         "EventID": 1,
26//!         "TimeCreated": { "#attributes": { "SystemTime": "2026-09-24T10:15:30.1234567Z" } },
27//!         "Computer": "WS-07"
28//!     },
29//!     "EventData": { "Image": "C:\\Windows\\notepad.exe", "ProcessId": "42", "RuleName": "-" }
30//! }}"##;
31//!
32//! sysmon.normalize(raw, |outcome| match outcome {
33//!     Outcome::Event(normalized) => {
34//!         assert_eq!(normalized.event["class_uid"], 1007);
35//!         assert_eq!(normalized.event["process"]["pid"], 42);
36//!         assert_eq!(normalized.event["time"], 1_790_244_930_123_i64);
37//!         // Nothing is dropped: fields the definition does not map are kept.
38//!         assert_eq!(normalized.event["unmapped"]["RuleName"], "-");
39//!     }
40//!     other => panic!("{other:?}"),
41//! });
42//! # Ok::<(), goliath_normalize::DefinitionError>(())
43//! ```
44
45// Tests assert on outcomes; a failed assertion should abort the test.
46#![cfg_attr(test, allow(clippy::expect_used, clippy::panic, clippy::unwrap_used))]
47
48mod auditd;
49mod csv;
50pub mod definition;
51pub mod error;
52pub mod normalizer;
53mod syslog;
54pub mod wire;
55
56pub use definition::SourceDefinition;
57pub use error::DefinitionError;
58pub use normalizer::{DeadLetter, EventId, Issue, Normalized, Normalizer, Outcome, Stage};
59pub use wire::{Envelope, WireError};
60
61/// The Sysmon source definition shipped with this crate.
62pub const SYSMON: &str = include_str!("../sources/sysmon.yaml");
63
64/// The Falco source definition shipped with this crate.
65pub const FALCO: &str = include_str!("../sources/falco.yaml");
66
67/// The Microsoft Entra ID sign-in log definition shipped with this crate.
68pub const ENTRA: &str = include_str!("../sources/entra.yaml");
69
70/// The Linux audit log definition shipped with this crate.
71pub const AUDITD: &str = include_str!("../sources/auditd.yaml");
72
73/// The definition for Sysmon events as flat JSON lines, as NXLog-based
74/// pipelines and the OTRF Security Datasets write them.
75pub const SYSMON_FLAT: &str = include_str!("../sources/sysmon-flat.yaml");
76
77/// The Windows Security event log definition shipped with this crate:
78/// logons, Kerberos, process creation, account and group changes.
79pub const WINDOWS_SECURITY: &str = include_str!("../sources/windows-security.yaml");
80
81/// The definition for AWS `CloudTrail` shipped with this crate: console sign-ins
82/// and API calls.
83pub const CLOUDTRAIL: &str = include_str!("../sources/cloudtrail.yaml");
84
85/// The Okta System Log definition shipped with this crate: sign-ins,
86/// accounts, factors, groups, privileges, and every other event type.
87pub const OKTA: &str = include_str!("../sources/okta.yaml");
88
89/// The Microsoft 365 unified audit log definition shipped with this crate:
90/// Entra ID sign-ins, accounts, groups, roles, and every other operation of
91/// every workload.
92pub const M365: &str = include_str!("../sources/m365.yaml");
93
94/// The Suricata EVE definition shipped with this crate: alerts as
95/// Detection Findings, and DNS, HTTP, TLS, flow, file, SMB, SSH, anomaly,
96/// and drop records.
97pub const SURICATA: &str = include_str!("../sources/suricata.yaml");
98
99/// The `PCAPdroid` definition shipped with this crate: the connections of an
100/// Android phone, each with the app that made it, as its CSV export.
101pub const PCAPDROID: &str = include_str!("../sources/pcapdroid.yaml");
102
103/// The Zeek definition shipped with this crate: connections, DNS, HTTP,
104/// TLS, certificates, SMB files, DCE/RPC, Kerberos, RDP, and SSH.
105pub const ZEEK: &str = include_str!("../sources/zeek.yaml");
106
107/// Every definition shipped with this crate, by name.
108pub const BUILTIN: &[(&str, &str)] = &[
109    ("auditd", AUDITD),
110    ("cloudtrail", CLOUDTRAIL),
111    ("entra", ENTRA),
112    ("falco", FALCO),
113    ("m365", M365),
114    ("okta", OKTA),
115    ("pcapdroid", PCAPDROID),
116    ("suricata", SURICATA),
117    ("sysmon-flat", SYSMON_FLAT),
118    ("sysmon", SYSMON),
119    ("windows-security", WINDOWS_SECURITY),
120    ("zeek", ZEEK),
121];
122
123/// The shipped definition named `name`, if there is one.
124pub fn builtin(name: &str) -> Option<&'static str> {
125    BUILTIN
126        .iter()
127        .find(|(builtin, _)| *builtin == name)
128        .map(|(_, text)| *text)
129}