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