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