goliath_rule/lib.rs
1//! Detection rules resolved to OCSF paths.
2//!
3//! A rule language such as Sigma names fields the way a log source names them.
4//! Goliath evaluates OCSF events, so every rule is resolved once, at load time,
5//! into a form that refers only to OCSF paths. The streaming match engine and
6//! the `ClickHouse` backend both consume that form and never the original, which
7//! is what keeps them from disagreeing about what a rule means. The decision is
8//! `docs/adr/0012-sigma-field-mapping.md`.
9//!
10//! This crate holds the pieces every execution path shares: paths into an
11//! event, the case folding that defines case insensitive comparison, and the
12//! field mappings that translate a rule language's field names into paths.
13//!
14//! # Example
15//!
16//! ```
17//! use goliath_rule::{FieldPath, MappingSet, sigma};
18//!
19//! let rule = goliath_sigma::parse_rule(
20//! r"
21//! title: Notepad opens a script
22//! logsource: { category: process_creation, product: windows }
23//! detection:
24//! selection:
25//! Image|endswith: '\notepad.exe'
26//! CommandLine|contains: '.ps1'
27//! condition: selection
28//! ",
29//! )?;
30//! let mappings = MappingSet::from_yaml(goliath_rule::SIGMA_WINDOWS)?;
31//! let resolved = sigma::resolve(&rule, &mappings)?;
32//!
33//! // Sigma's `Image` became OCSF paths, and the log source became a class.
34//! let text = serde_json::to_string(&resolved)?;
35//! assert!(text.contains("process.file.path"));
36//! assert!(resolved.class.contains_key(&FieldPath::parse("class_uid")?));
37//! # Ok::<(), Box<dyn std::error::Error>>(())
38//! ```
39
40// Tests assert on outcomes; a failed assertion should abort the test.
41#![cfg_attr(test, allow(clippy::expect_used, clippy::panic, clippy::unwrap_used))]
42
43pub mod error;
44pub mod fold;
45pub mod mapping;
46pub mod path;
47pub mod resolved;
48pub mod sigma;
49
50pub use error::{MappingError, NetworkError, PathError, ResolveError};
51pub use fold::{fold, fold_into};
52
53/// The mapping set for Sigma's Windows log sources shipped with this crate,
54/// ready for [`MappingSet::from_yaml`].
55pub const SIGMA_WINDOWS: &str = include_str!("../mappings/sigma-windows.yaml");
56
57/// The mapping set for Sigma's AWS log sources shipped with this crate,
58/// ready for [`MappingSet::from_yaml`].
59pub const SIGMA_AWS: &str = include_str!("../mappings/sigma-aws.yaml");
60
61/// The mapping set for Sigma's Okta log source shipped with this crate,
62/// ready for [`MappingSet::from_yaml`].
63pub const SIGMA_OKTA: &str = include_str!("../mappings/sigma-okta.yaml");
64
65/// The mapping set for Sigma's Microsoft 365 log sources shipped with this
66/// crate, ready for [`MappingSet::from_yaml`].
67pub const SIGMA_M365: &str = include_str!("../mappings/sigma-m365.yaml");
68
69/// The mapping set for Sigma's Zeek log sources shipped with this crate,
70/// ready for [`MappingSet::from_yaml`].
71pub const SIGMA_ZEEK: &str = include_str!("../mappings/sigma-zeek.yaml");
72pub use mapping::{ClassValue, LogSourceSelector, MappingSet, SourceMapping};
73pub use path::FieldPath;
74pub use resolved::{
75 Comparison, Expr, MappingVersion, Network, Number, Predicate, ResolvedRule, StringTest, Test,
76};