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