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