pub struct CommandPolicy {
pub mode: PolicyMode,
pub allowlist: HashSet<String>,
pub denylist: Vec<String>,
pub dangerous_patterns: Vec<String>,
}Expand description
Configurable command execution policy (runtime representation).
Validates commands against an allowlist or denylist, and always checks a set of dangerous patterns regardless of mode (defense-in-depth).
Constructed from super::config::CommandPolicyConfig at startup.
Fields§
§mode: PolicyModeOperating mode for the policy.
allowlist: HashSet<String>Set of permitted executable basenames (used in Allowlist mode).
denylist: Vec<String>Patterns to block (substring match, case-insensitive; used in Denylist mode).
dangerous_patterns: Vec<String>Patterns that are always checked regardless of mode (defense-in-depth).
Implementations§
Source§impl CommandPolicy
impl CommandPolicy
Sourcepub fn safe_defaults() -> Self
pub fn safe_defaults() -> Self
Create a policy with safe defaults.
- Mode:
Allowlist - Allowlist: common read-only / informational commands
- Dangerous patterns: the standard set from
DEFAULT_DANGEROUS_PATTERNS - Denylist: same patterns (used when mode is switched to
Denylist)
Sourcepub fn new(
mode: PolicyMode,
allowlist: HashSet<String>,
denylist: Vec<String>,
) -> Self
pub fn new( mode: PolicyMode, allowlist: HashSet<String>, denylist: Vec<String>, ) -> Self
Create a new policy with explicit configuration.
Sourcepub fn validate(&self, command: &str) -> Result<(), CommandPolicyError>
pub fn validate(&self, command: &str) -> Result<(), CommandPolicyError>
Validate a command string against this policy.
- Always checks dangerous patterns first (defense-in-depth).
- In
Allowlistmode, splits on shell compound operators (&&,||,;,|) and validates every sub-command’s basename. - In
Denylistmode, checks all denylist patterns (case-insensitive substring match).
Trait Implementations§
Source§impl Clone for CommandPolicy
impl Clone for CommandPolicy
Source§fn clone(&self) -> CommandPolicy
fn clone(&self) -> CommandPolicy
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for CommandPolicy
impl Debug for CommandPolicy
Auto Trait Implementations§
impl Freeze for CommandPolicy
impl RefUnwindSafe for CommandPolicy
impl Send for CommandPolicy
impl Sync for CommandPolicy
impl Unpin for CommandPolicy
impl UnsafeUnpin for CommandPolicy
impl UnwindSafe for CommandPolicy
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more