Skip to main content

CompiledPolicy

Struct CompiledPolicy 

Source
pub struct CompiledPolicy<'p> { /* private fields */ }
Expand description

A policy with all patterns compiled for one evaluation context.

Compile once per process (or per policy reload) and reuse for every tool call; compilation dominates the cost of a single decision. It borrows the policy (Self::compile) or owns it (Self::compile_owned, for a caller such as openmoat-sdk that keeps one engine for as long as it likes).

Implementations§

Source§

impl CompiledPolicy<'_>

Source

pub fn exposure( &self, action: &Action, cwd: &str, paths: &dyn PathResolver, ) -> Taint

What running action in cwd exposed its session to: secret material from a read the secrets-paths group names, untrusted content from a fetch, a web search, an unknown tool or an MCP result. The caller passes only calls that ran; the parts of an action that cannot be classified expose nothing they can name.

Source

pub fn with_taint( &self, decision: Decision, action: &Action, paths: &dyn PathResolver, taint: &Taint, ) -> Decision

decision for action, tightened by taint: after secret material, network to any host but the secret’s own, and every MCP call, web search and unknown tool (the hosts they reach are unknown), needs review; after untrusted content, a write to a protected path needs review. Merging keeps the strictest verdict, so this never loosens a decision.

Source§

impl<'p> CompiledPolicy<'p>

Source

pub fn compile( policy: &'p Policy, ctx: &EvalContext, ) -> Result<Self, PolicyError>

Compile every pattern of policy for ctx. Fails on a pattern that does not compile, and on a moved_dirs entry whose default could alias every pattern (empty, bare /, or not an absolute or ~/-rooted directory).

Source

pub fn compile_owned( policy: Policy, ctx: &EvalContext, ) -> Result<CompiledPolicy<'static>, PolicyError>

Self::compile for a policy the result keeps, so it borrows nothing.

Source

pub fn policy(&self) -> &Policy

The policy this was compiled from.

Source

pub fn context(&self) -> &EvalContext

The context this was compiled for.

Source

pub fn evaluate_atomic(&self, action: &AtomicAction) -> Option<Decision>

Evaluate one atomic action: deny → allow → review → defer → default, with a repository policy’s review rules (Policy::repo_review) tried before allow.

Returns None for a whole-pipeline atom that no rule mentions: pipelines are only there so rules like curl * | sh can see across |; the per-sub-command atoms carry the default verdict.

Source§

impl CompiledPolicy<'_>

Source

pub fn decide(&self, action: &Action) -> Decision

Decide one host action without executable resolution.

Unparseable input yields the policy’s catch-all verdict (review or defer) with the parser’s reason, never allow.

Source

pub fn atoms( &self, action: &Action, paths: &dyn PathResolver, ) -> (Vec<AtomicAction>, Option<String>)

The atomic actions Self::decide_with evaluates for action, with an extra atom for every path an unquoted glob operand names in the directories paths lists, and for every read or write paths resolves through a symlink; and the reason when part of the action cannot be classified or a glob not expanded in full (review).

Source

pub fn pushes(&self, action: &Action) -> Vec<Push>

The commands of action that publish local commits (git push, gh pr create), each with the directories it may run in. Only a shell command has any.

Source

pub fn executed(&self, action: &Action, paths: &dyn PathResolver) -> Vec<String>

The files action runs as code (ADR-039): a script an interpreter or a shell runs (python3 x.py, bash x.sh, source x), a file it loads first (node -r ./x.js) and a program named by a path (./x), through every wrapper the classifier unwraps (env, time, bash -c '…'), as canonical paths, each also as paths resolves it through a symlink. Only a shell command runs any; a test runner, build tool or package script (pytest, npm test, go run .) names none.

Source

pub fn decide_with( &self, action: &Action, resolver: &dyn ProgramResolver, paths: &dyn PathResolver, ) -> Decision

Decide one host action, resolving shell programs through resolver so that executables pins and installation pins are enforced, and paths through paths so a symlink cannot move a read or write past a rule.

Trait Implementations§

Source§

impl<'p> Debug for CompiledPolicy<'p>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'p> Freeze for CompiledPolicy<'p>

§

impl<'p> RefUnwindSafe for CompiledPolicy<'p>

§

impl<'p> Send for CompiledPolicy<'p>

§

impl<'p> Sync for CompiledPolicy<'p>

§

impl<'p> Unpin for CompiledPolicy<'p>

§

impl<'p> UnsafeUnpin for CompiledPolicy<'p>

§

impl<'p> UnwindSafe for CompiledPolicy<'p>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.