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;
49pub mod definition;
50pub mod error;
51pub mod normalizer;
52mod syslog;
53pub mod wire;
54
55pub use definition::SourceDefinition;
56pub use error::DefinitionError;
57pub use normalizer::{DeadLetter, EventId, Issue, Normalized, Normalizer, Outcome, Stage};
58pub use wire::{Envelope, WireError};
59
60/// The Sysmon source definition shipped with this crate.
61pub const SYSMON: &str = include_str!("../sources/sysmon.yaml");
62
63/// The Falco source definition shipped with this crate.
64pub const FALCO: &str = include_str!("../sources/falco.yaml");
65
66/// The Microsoft Entra ID sign-in log definition shipped with this crate.
67pub const ENTRA: &str = include_str!("../sources/entra.yaml");
68
69/// The Linux audit log definition shipped with this crate.
70pub const AUDITD: &str = include_str!("../sources/auditd.yaml");
71
72/// The definition for Sysmon events as flat JSON lines, as NXLog-based
73/// pipelines and the OTRF Security Datasets write them.
74pub const SYSMON_FLAT: &str = include_str!("../sources/sysmon-flat.yaml");
75
76/// The Windows Security event log definition shipped with this crate:
77/// logons, Kerberos, process creation, account and group changes.
78pub const WINDOWS_SECURITY: &str = include_str!("../sources/windows-security.yaml");
79
80/// The definition for AWS `CloudTrail` shipped with this crate: console sign-ins
81/// and API calls.
82pub const CLOUDTRAIL: &str = include_str!("../sources/cloudtrail.yaml");
83
84/// The Okta System Log definition shipped with this crate: sign-ins,
85/// accounts, factors, groups, privileges, and every other event type.
86pub const OKTA: &str = include_str!("../sources/okta.yaml");
87
88/// The Microsoft 365 unified audit log definition shipped with this crate:
89/// Entra ID sign-ins, accounts, groups, roles, and every other operation of
90/// every workload.
91pub const M365: &str = include_str!("../sources/m365.yaml");
92
93/// The Zeek definition shipped with this crate: connections, DNS, HTTP,
94/// TLS, certificates, SMB files, DCE/RPC, Kerberos, RDP, and SSH.
95pub const ZEEK: &str = include_str!("../sources/zeek.yaml");
96
97/// Every definition shipped with this crate, by name.
98pub const BUILTIN: &[(&str, &str)] = &[
99 ("auditd", AUDITD),
100 ("cloudtrail", CLOUDTRAIL),
101 ("entra", ENTRA),
102 ("falco", FALCO),
103 ("m365", M365),
104 ("okta", OKTA),
105 ("sysmon-flat", SYSMON_FLAT),
106 ("sysmon", SYSMON),
107 ("windows-security", WINDOWS_SECURITY),
108 ("zeek", ZEEK),
109];
110
111/// The shipped definition named `name`, if there is one.
112pub fn builtin(name: &str) -> Option<&'static str> {
113 BUILTIN
114 .iter()
115 .find(|(builtin, _)| *builtin == name)
116 .map(|(_, text)| *text)
117}