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