pub struct SecurityPolicy {
pub allow_unsafe_code: bool,
pub require_signatures: bool,
pub min_trust_level: u8,
pub max_complexity: u32,
pub dangerous_permissions: Vec<String>,
pub restricted_apis: Vec<String>,
}Expand description
Security policy configuration for the plugin system
The SecurityPolicy defines the security requirements and restrictions for plugin validation and execution. It provides configurable security levels to balance functionality with safety requirements.
§Security Levels
- Strict: Maximum security with signature requirements and minimal permissions
- Standard: Balanced security for production environments
- Permissive: Relaxed security for development and testing
§Examples
use sklears_core::plugin::{SecurityPolicy, Permission};
// Create a strict security policy
let strict_policy = SecurityPolicy::strict();
assert!(strict_policy.require_signatures);
assert!(!strict_policy.allow_unsafe_code);
// Create a custom policy
let custom_policy = SecurityPolicy {
allow_unsafe_code: false,
require_signatures: true,
min_trust_level: 7,
max_complexity: 15,
dangerous_permissions: vec![
"file_system_write".to_string(),
"network_access".to_string(),
],
restricted_apis: vec![
"std::process::Command".to_string(),
],
};Fields§
§allow_unsafe_code: boolWhether to allow plugins with unsafe code blocks
require_signatures: boolWhether digital signatures are required for plugins
min_trust_level: u8Minimum trust level required for plugin publishers (0-10)
max_complexity: u32Maximum allowed cyclomatic complexity for plugin code
dangerous_permissions: Vec<String>List of dangerous permissions that trigger warnings
restricted_apis: Vec<String>List of restricted API patterns that are not allowed
Implementations§
Source§impl SecurityPolicy
impl SecurityPolicy
Sourcepub fn strict() -> Self
pub fn strict() -> Self
Create a strict security policy suitable for production environments
This policy provides maximum security with signature requirements, no unsafe code, and minimal dangerous permissions.
§Examples
use sklears_core::plugin::SecurityPolicy;
let policy = SecurityPolicy::strict();
assert!(policy.require_signatures);
assert!(!policy.allow_unsafe_code);
assert_eq!(policy.min_trust_level, 8);Sourcepub fn standard() -> Self
pub fn standard() -> Self
Create a standard security policy for typical production use
Balances security with functionality, allowing more flexibility than strict mode while maintaining essential protections.
§Examples
use sklears_core::plugin::SecurityPolicy;
let policy = SecurityPolicy::standard();
assert!(policy.require_signatures);
assert!(!policy.allow_unsafe_code);
assert_eq!(policy.min_trust_level, 5);Sourcepub fn permissive() -> Self
pub fn permissive() -> Self
Create a permissive security policy for development and testing
Provides minimal security restrictions to enable rapid development and testing. Should not be used in production environments.
§Examples
use sklears_core::plugin::SecurityPolicy;
let policy = SecurityPolicy::permissive();
assert!(!policy.require_signatures);
assert!(policy.allow_unsafe_code);
assert_eq!(policy.min_trust_level, 0);Sourcepub fn is_dangerous_permission(&self, permission: &Permission) -> bool
pub fn is_dangerous_permission(&self, permission: &Permission) -> bool
Check if a permission is considered dangerous
Dangerous permissions are those that could potentially be used maliciously or cause system damage if misused.
§Arguments
permission- The permission to check
§Returns
true if the permission is considered dangerous, false otherwise.
§Examples
use sklears_core::plugin::{SecurityPolicy, Permission};
let policy = SecurityPolicy::standard();
assert!(policy.is_dangerous_permission(&Permission::FileSystemWrite));
assert!(!policy.is_dangerous_permission(&Permission::FileSystemRead));Sourcepub fn is_restricted_api(&self, api: &str) -> bool
pub fn is_restricted_api(&self, api: &str) -> bool
Check if an API call is restricted
Restricted APIs are those that are prohibited from use in plugins due to security concerns or system stability issues.
§Arguments
api- The API call pattern to check
§Returns
true if the API is restricted, false otherwise.
§Examples
use sklears_core::plugin::SecurityPolicy;
let policy = SecurityPolicy::standard();
assert!(policy.is_restricted_api("std::process::Command"));
assert!(!policy.is_restricted_api("std::fs::read_to_string"));Sourcepub fn add_dangerous_permission(&mut self, permission: String)
pub fn add_dangerous_permission(&mut self, permission: String)
Add a dangerous permission to the policy
§Arguments
permission- The permission name to add as dangerous
Sourcepub fn remove_dangerous_permission(&mut self, permission: &str)
pub fn remove_dangerous_permission(&mut self, permission: &str)
Remove a dangerous permission from the policy
§Arguments
permission- The permission name to remove from dangerous list
Sourcepub fn add_restricted_api(&mut self, api_pattern: String)
pub fn add_restricted_api(&mut self, api_pattern: String)
Sourcepub fn remove_restricted_api(&mut self, api_pattern: &str)
pub fn remove_restricted_api(&mut self, api_pattern: &str)
Remove a restricted API pattern from the policy
§Arguments
api_pattern- The API pattern to remove from restrictions
Trait Implementations§
Source§impl Clone for SecurityPolicy
impl Clone for SecurityPolicy
Source§fn clone(&self) -> SecurityPolicy
fn clone(&self) -> SecurityPolicy
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for SecurityPolicy
impl Debug for SecurityPolicy
Auto Trait Implementations§
impl Freeze for SecurityPolicy
impl RefUnwindSafe for SecurityPolicy
impl Send for SecurityPolicy
impl Sync for SecurityPolicy
impl Unpin for SecurityPolicy
impl UnwindSafe for SecurityPolicy
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more