Skip to main content

rust_supervisor/ipc/security/
allowlist.rs

1//! External command allowlist.
2//!
3//! Only absolute executable paths listed in the allowlist configuration
4//! are eligible for execution via control-plane extension points.
5//! Default: empty list (deny all external commands).
6
7use crate::config::ipc_security::AllowlistConfig;
8use crate::dashboard::error::DashboardError;
9
10/// Checks whether an executable path is in the allowlist.
11///
12/// # Arguments
13///
14/// - `path`: Absolute executable path to check.
15/// - `config`: Allowlist configuration.
16///
17/// # Returns
18///
19/// Returns `Ok(())` when the path is allowed, or `Err(DashboardError)`
20/// with `allowlist_empty` or `allowlist_denied`.
21pub fn check_allowlist(path: &str, config: &AllowlistConfig) -> Result<(), DashboardError> {
22    if !config.enabled {
23        return Ok(());
24    }
25
26    if config.allowed_paths.is_empty() {
27        return Err(DashboardError::allowlist_empty());
28    }
29
30    if !config.allowed_paths.iter().any(|p| p == path) {
31        return Err(DashboardError::allowlist_denied(path));
32    }
33
34    Ok(())
35}