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 packages;
31mod patch;
32mod paths;
33mod pattern;
34mod policy;
35mod programs;
36mod realpath;
37mod repo;
38mod secret;
39mod shell;
40mod taint;
41pub mod token;
42mod verdict;
43pub mod yaml;
44
45pub use action::{Action, AtomicAction};
46// The taint `Secret` (material a session read) is exported as `TaintSecret`, apart
47// from the policy's brokered `Secret`.
48pub use engine::{CompiledPolicy, EvalContext, Secret as TaintSecret, Taint, evaluate};
49pub use host::file_url_path;
50pub use kind::{Kind, UnknownKind};
51pub use patch::writes as patch_writes;
52pub use paths::resolve as resolve_path;
53pub use pattern::literal_shell_pattern;
54pub use policy::{Defaults, Policy, PolicyError, RuleGroup, SandboxSettings};
55pub use programs::{MapResolver, NoResolver, ProgramResolver};
56pub use realpath::{MapPathResolver, PathResolver};
57pub use repo::{REPO_RULE_PREFIX, RepoPolicy};
58pub use secret::{Secret, Source as SecretSource};
59pub use shell::installs::near_miss_atoms as package_near_misses;
60pub use shell::push::Push;
61pub use taint::TaintSettings;
62pub use verdict::{Decision, UnknownVerdict, Verdict};
63
64/// The shipped default policy, as YAML: what `moat init` installs and what the
65/// conformance suite pins. Parse it with [`Policy::parse`].
66pub const DEFAULT_POLICY: &str = include_str!("../policies/default-v1.yaml");