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 → review → 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;
20pub mod attribution;
21pub mod diffscan;
22mod engine;
23mod expand;
24mod host;
25mod injection;
26pub mod ir;
27mod kind;
28// Public only for the differential test against bash (`tests/lexer_vs_bash.rs`);
29// not a stable API.
30#[doc(hidden)]
31pub mod lexer;
32pub mod lint;
33pub mod mcp_flow;
34mod packages;
35mod patch;
36mod paths;
37mod pattern;
38mod personal;
39mod policy;
40mod programs;
41mod realpath;
42mod repo;
43mod secret;
44mod shell;
45mod taint;
46pub mod token;
47mod verdict;
48pub mod yaml;
49
50pub use action::{Action, AtomicAction, UNCHECKED_RULE};
51// The taint `Secret` (material a session read) is exported as `TaintSecret`, apart
52// from the policy's brokered `Secret`.
53pub use engine::{
54    CompiledPolicy, EvalContext, HOLDS_PROTECTED_RULE, Secret as TaintSecret, TAINT_RULE, Taint,
55    UntrustedKind, evaluate,
56};
57pub use host::{
58    MAX_DNS_LABEL_LEN, MAX_DNS_NAME_LEN, file_url_path, malformed_port_pattern, port_pattern,
59};
60pub use injection::{
61    INJECTED_RULE, InjectedLookup, InjectedMap, MAX_SCANNED_BYTES as MAX_INJECTED_SCAN_BYTES,
62    MAX_TOKENS_PER_OUTPUT as MAX_INJECTED_TOKENS_PER_OUTPUT, Token as InjectedToken,
63    TokenKind as InjectedTokenKind,
64};
65pub use kind::{Kind, UnknownKind};
66pub use patch::writes as patch_writes;
67pub use paths::resolve as resolve_path;
68pub use pattern::literal_shell_pattern;
69pub use policy::{
70    BrowserOpen, Defaults, McpSettings, OldNames, Policy, PolicyError, RuleGroup,
71    SUPPORTED_VERSION, SandboxSettings,
72};
73pub use programs::{MapResolver, NoResolver, ProgramResolver};
74pub use realpath::{MapPathResolver, PathResolver};
75pub use repo::{REPO_RULE_PREFIX, RepoPolicy};
76pub use secret::{
77    METHOD_OVERRIDE_HEADERS, PathRefusal, Permit, RequestPath, Route as SecretRoute,
78    SECRET_RULE_PREFIX, Secret, Source as SecretSource, Tls as SecretTls,
79};
80pub use shell::cwd::leaves_unknown_directory;
81pub use shell::installs::near_miss_atoms as package_near_misses;
82pub use shell::push::Push;
83pub use taint::TaintSettings;
84pub use verdict::{Decision, OLD_REVIEW, UnknownVerdict, Verdict};
85
86/// The shipped default policy, as YAML: what `moat init` installs and what the
87/// conformance suite pins. Parse it with [`Policy::parse`].
88pub const DEFAULT_POLICY: &str = include_str!("../policies/default-v1.yaml");