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;
37pub mod obfuscation;
38mod packages;
39mod patch;
40mod paths;
41mod pattern;
42mod personal;
43mod policy;
44mod predicate;
45mod programs;
46mod realpath;
47mod repo;
48mod requests;
49mod route;
50pub mod rule_id;
51mod secret;
52mod shell;
53mod staging;
54mod taint;
55pub mod token;
56mod verdict;
57pub mod widen;
58pub mod yaml;
59
60pub use action::{Action, AtomicAction};
61pub use arguments::{
62    Arguments, MAX_VALUE_BYTES as MAX_ARGUMENT_VALUE_BYTES, MAX_VALUES as MAX_ARGUMENT_VALUES,
63    snake as argument_key,
64};
65// The taint `Secret` (material a session read) is exported as `TaintSecret`, apart
66// from the policy's brokered `Secret`.
67pub use engine::{
68    CompiledPolicy, EvalContext, STAGING_ATOM, Secret as TaintSecret, Staging, Taint,
69    UntrustedKind, evaluate,
70};
71pub use host::{
72    MAX_DNS_LABEL_LEN, MAX_DNS_NAME_LEN, file_url_path, malformed_port_pattern, port_pattern,
73};
74pub use injection::{
75    InjectedLookup, InjectedMap, MAX_SCANNED_BYTES as MAX_INJECTED_SCAN_BYTES,
76    MAX_TOKENS_PER_OUTPUT as MAX_INJECTED_TOKENS_PER_OUTPUT, Token as InjectedToken,
77    TokenKind as InjectedTokenKind,
78};
79pub use kind::{Kind, UnknownKind};
80pub use packages::Ecosystem;
81pub use patch::{Replayed as PatchReplayed, replay as patch_replay, writes as patch_writes};
82pub use paths::resolve as resolve_path;
83pub use pattern::literal_shell_pattern;
84pub use policy::{
85    BrowserOpen, DeclaredVersion, Defaults, ForeignHooks, HookSettings, McpSettings, OldNames,
86    Policy, PolicyError, ProjectHookOff, ProjectTop, Require, RequiredBy, RequiredLevel,
87    Requirement, RuleGroup, RunBoundary, RunEnv, SUPPORTED_VERSION, SandboxSettings,
88    TITLE_MAX_CHARS, Unattended, WHY_MAX_CHARS, declared_version, env_name_problem,
89};
90pub use predicate::{ArgNames, Predicate, Provenance};
91pub use programs::{MapResolver, NoResolver, ProgramResolver};
92pub use realpath::{MapPathResolver, PathResolver};
93pub use repo::{REPO_RULE_PREFIX, RepoPolicy};
94pub use requests::{
95    REQUESTS_RULE_PREFIX, RequestCheck, RequestEntry, RequestRules, Untrusted as RequestsUntrusted,
96};
97pub use secret::{
98    CommandHome as SecretCommandHome, CommandSource as SecretCommand, METHOD_OVERRIDE_HEADERS,
99    PathRefusal, Permit, RequestPath, Route as SecretRoute, SECRET_RULE_PREFIX, Secret,
100    Source as SecretSource, Tls as SecretTls,
101};
102/// Minted, short-lived secrets and their local helpers (ADR-118).
103pub mod mint {
104    pub use crate::secret::{
105        AWS_CREDENTIALS, AwsSts, GCP_CREDENTIALS, Gcp, GithubApp, Helper, MintSource,
106    };
107}
108pub use shell::cwd::leaves_unknown_directory;
109pub use shell::installs::package_atoms;
110pub use shell::powershell::{POWERSHELL, is_powershell};
111pub use shell::push::Push;
112pub use shell::replaced::replaced_files;
113pub use staging::{DEFAULT_OUTSIDE_FOLDERS, DEFAULT_OUTSIDE_READS, StagingSettings};
114pub use taint::{TaintSettings, TrifectaVerdict};
115pub use verdict::{Decision, Notice, OLD_REVIEW, UnknownVerdict, Verdict};
116
117/// The shipped default policy, as YAML: what `moat init` installs and what the
118/// conformance suite pins. Parse it with [`Policy::parse`].
119pub const DEFAULT_POLICY: &str = include_str!("../policies/default-v1.yaml");