symbi_runtime/integrations/policy_engine/
mod.rs1pub mod engine;
6pub mod types;
7
8mod existing;
10pub use existing::{
11 MockPolicyEngine, Policy, PolicyDecision as ExistingPolicyDecision, PolicyEngine,
12};
13
14pub use types::{
16 AccessContext, AccessDecision, AccessType, AllocationDecision, AllocationResult,
17 EnforcementStatistics, ResourceAccessRequest, ResourceAllocationRequest, ResourceType,
18 SourceInfo,
19};
20pub use crate::types::PolicyError;
22pub use engine::{DefaultPolicyEnforcementPoint, MockPolicyEnforcementPoint};
23
24use crate::types::*;
25use async_trait::async_trait;
26use std::sync::Arc;
27
28#[derive(Debug, Clone)]
30pub struct ResourceAccessConfig {
31 pub default_deny: bool,
33 pub enable_caching: bool,
35 pub cache_ttl_secs: u64,
37 pub policy_path: Option<String>,
39 pub enable_audit: bool,
41}
42
43impl Default for ResourceAccessConfig {
44 fn default() -> Self {
45 Self {
46 default_deny: true,
47 enable_caching: true,
48 cache_ttl_secs: 300, policy_path: None,
50 enable_audit: true,
51 }
52 }
53}
54
55#[async_trait]
57pub trait PolicyEnforcementPoint: Send + Sync {
58 async fn check_resource_access(
60 &self,
61 agent_id: AgentId,
62 resource: &ResourceAccessRequest,
63 ) -> Result<AccessDecision, PolicyError>;
64
65 async fn validate_resource_allocation(
67 &self,
68 agent_id: AgentId,
69 allocation: &ResourceAllocationRequest,
70 ) -> Result<AllocationDecision, PolicyError>;
71
72 async fn load_policies(&self, config: &ResourceAccessConfig) -> Result<(), PolicyError>;
74
75 async fn reload_policies(&self) -> Result<(), PolicyError>;
77
78 async fn get_enforcement_stats(&self) -> Result<EnforcementStatistics, PolicyError>;
80}
81
82pub struct PolicyEnforcementFactory;
84
85impl PolicyEnforcementFactory {
86 pub async fn create_enforcement_point(
88 config: ResourceAccessConfig,
89 ) -> Result<Arc<dyn PolicyEnforcementPoint>, PolicyError> {
90 let enforcement_point = DefaultPolicyEnforcementPoint::new(config).await?;
91 Ok(Arc::new(enforcement_point))
92 }
93
94 pub fn create_mock_enforcement_point() -> Arc<dyn PolicyEnforcementPoint> {
96 Arc::new(MockPolicyEnforcementPoint::new())
97 }
98}