Skip to main content

openmoat_core/
lib.rs

1//! `openmoat-core`: the trusted decision core of OpenMoat.
2//!
3//! This crate is **pure**: it performs no I/O and makes no OS calls. Callers
4//! (the CLI, host adapters) read files, resolve the environment and pass
5//! everything in. That keeps the security-relevant logic small, testable and
6//! portable (it also builds for `wasm32`).
7//!
8//! Pipeline: an [`Action`] is classified into [`AtomicAction`]s, each atomic
9//! action is evaluated `deny → allow → ask → defaults` by a [`CompiledPolicy`],
10//! and the strictest verdict across them becomes the [`Decision`]. Facts that
11//! need the filesystem reach the engine through [`ProgramResolver`] and
12//! [`PathResolver`]. The policy compiler ([`ir::lower()`]) derives from the same
13//! policy what an operating-system layer can enforce (ADR-019).
14
15#![warn(missing_docs)]
16// A library reports to its caller; only the `moat` binary prints.
17#![warn(clippy::print_stdout, clippy::print_stderr)]
18
19mod action;
20mod engine;
21mod expand;
22mod host;
23pub mod ir;
24mod kind;
25// Public only for the differential test against bash (`tests/lexer_vs_bash.rs`);
26// not a stable API.
27#[doc(hidden)]
28pub mod lexer;
29pub mod lint;
30mod patch;
31mod paths;
32mod pattern;
33mod policy;
34mod programs;
35mod realpath;
36mod repo;
37mod secret;
38mod shell;
39mod taint;
40pub mod token;
41mod verdict;
42pub mod yaml;
43
44pub use action::{Action, AtomicAction};
45// The taint `Secret` (material a session read) is exported as `TaintSecret`, apart
46// from the policy's brokered `Secret`.
47pub use engine::{CompiledPolicy, EvalContext, Secret as TaintSecret, Taint, evaluate};
48pub use host::file_url_path;
49pub use kind::{Kind, UnknownKind};
50pub use patch::writes as patch_writes;
51pub use paths::resolve as resolve_path;
52pub use pattern::literal_shell_pattern;
53pub use policy::{Defaults, Policy, PolicyError, RuleGroup, SandboxSettings};
54pub use programs::{MapResolver, NoResolver, ProgramResolver};
55pub use realpath::{MapPathResolver, PathResolver};
56pub use repo::{REPO_RULE_PREFIX, RepoPolicy};
57pub use secret::{Secret, Source as SecretSource};
58pub use shell::push::Push;
59pub use taint::TaintSettings;
60pub use verdict::{Decision, UnknownVerdict, Verdict};
61
62/// The shipped default policy, as YAML: what `moat init` installs and what the
63/// conformance suite pins. Parse it with [`Policy::parse`].
64pub const DEFAULT_POLICY: &str = include_str!("../policies/default-v1.yaml");