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, Defaults, McpSettings, OldNames, Policy, PolicyError, ProjectHookOff, ProjectTop,
77    Require, RequiredBy, RequiredLevel, Requirement, RuleGroup, RunBoundary, SUPPORTED_VERSION,
78    SandboxSettings, TITLE_MAX_CHARS, Unattended, WHY_MAX_CHARS, env_name_problem,
79};
80pub use programs::{MapResolver, NoResolver, ProgramResolver};
81pub use realpath::{MapPathResolver, PathResolver};
82pub use repo::{REPO_RULE_PREFIX, RepoPolicy};
83pub use requests::{
84    REQUESTS_RULE_PREFIX, RequestCheck, RequestEntry, RequestRules, Untrusted as RequestsUntrusted,
85};
86pub use secret::{
87    CommandHome as SecretCommandHome, CommandSource as SecretCommand, METHOD_OVERRIDE_HEADERS,
88    PathRefusal, Permit, RequestPath, Route as SecretRoute, SECRET_RULE_PREFIX, Secret,
89    Source as SecretSource, Tls as SecretTls,
90};
91pub use shell::cwd::leaves_unknown_directory;
92pub use shell::installs::package_atoms;
93pub use shell::push::Push;
94pub use shell::replaced::replaced_files;
95pub use staging::{DEFAULT_OUTSIDE_FOLDERS, DEFAULT_OUTSIDE_READS, StagingSettings};
96pub use taint::TaintSettings;
97pub use verdict::{Decision, Notice, OLD_REVIEW, UnknownVerdict, Verdict};
98
99/// The shipped default policy, as YAML: what `moat init` installs and what the
100/// conformance suite pins. Parse it with [`Policy::parse`].
101pub const DEFAULT_POLICY: &str = include_str!("../policies/default-v1.yaml");