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 requests;
45mod route;
46pub mod rule_id;
47mod secret;
48mod shell;
49mod staging;
50mod taint;
51pub mod token;
52mod verdict;
53pub mod yaml;
54
55pub use action::{Action, AtomicAction};
56// The taint `Secret` (material a session read) is exported as `TaintSecret`, apart
57// from the policy's brokered `Secret`.
58pub use engine::{
59    CompiledPolicy, EvalContext, STAGING_ATOM, Secret as TaintSecret, Staging, Taint,
60    UntrustedKind, evaluate,
61};
62pub use host::{
63    MAX_DNS_LABEL_LEN, MAX_DNS_NAME_LEN, file_url_path, malformed_port_pattern, port_pattern,
64};
65pub use injection::{
66    InjectedLookup, InjectedMap, MAX_SCANNED_BYTES as MAX_INJECTED_SCAN_BYTES,
67    MAX_TOKENS_PER_OUTPUT as MAX_INJECTED_TOKENS_PER_OUTPUT, Token as InjectedToken,
68    TokenKind as InjectedTokenKind,
69};
70pub use kind::{Kind, UnknownKind};
71pub use packages::Ecosystem;
72pub use patch::{Replayed as PatchReplayed, replay as patch_replay, writes as patch_writes};
73pub use paths::resolve as resolve_path;
74pub use pattern::literal_shell_pattern;
75pub use policy::{
76    BrowserOpen, DeclaredVersion, Defaults, McpSettings, OldNames, Policy, PolicyError,
77    ProjectHookOff, ProjectTop, Require, RequiredBy, RequiredLevel, Requirement, RuleGroup,
78    RunBoundary, SUPPORTED_VERSION, SandboxSettings, TITLE_MAX_CHARS, Unattended, WHY_MAX_CHARS,
79    declared_version, env_name_problem,
80};
81pub use programs::{MapResolver, NoResolver, ProgramResolver};
82pub use realpath::{MapPathResolver, PathResolver};
83pub use repo::{REPO_RULE_PREFIX, RepoPolicy};
84pub use requests::{
85    REQUESTS_RULE_PREFIX, RequestCheck, RequestEntry, RequestRules, Untrusted as RequestsUntrusted,
86};
87pub use secret::{
88    CommandHome as SecretCommandHome, CommandSource as SecretCommand, METHOD_OVERRIDE_HEADERS,
89    PathRefusal, Permit, RequestPath, Route as SecretRoute, SECRET_RULE_PREFIX, Secret,
90    Source as SecretSource, Tls as SecretTls,
91};
92pub use shell::cwd::leaves_unknown_directory;
93pub use shell::installs::package_atoms;
94pub use shell::push::Push;
95pub use shell::replaced::replaced_files;
96pub use staging::{DEFAULT_OUTSIDE_FOLDERS, DEFAULT_OUTSIDE_READS, StagingSettings};
97pub use taint::TaintSettings;
98pub use verdict::{Decision, Notice, OLD_REVIEW, UnknownVerdict, Verdict};
99
100/// The shipped default policy, as YAML: what `moat init` installs and what the
101/// conformance suite pins. Parse it with [`Policy::parse`].
102pub const DEFAULT_POLICY: &str = include_str!("../policies/default-v1.yaml");