arsenal-core · policy
Declared module signatures, types, configuration, and source documentation.
Source: arsenal/crates/arsenal-core/src/policy.rs. SHA-256: 83a040bdc4d7f6631dfce58a3d61ba40b22723f7c77fa42497d76a247537f813.
This source reference follows declared modules and preserves feature attributes. It includes public declarations and implementation methods in those modules. Private-module exports and trait resolution still require the compiler; not every declaration is a crate-root import. Function bodies and constant values are omitted. Source comments describe their implementation context and are not a production deployment claim.
policy::PolicyId
Policy identifier
#[derive(Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
#[serde(transparent)]
pub struct PolicyId(String);Source line: 29.
policy::PolicyId::new
Create a new policy ID
Errors
Returns an error if the ID is invalid
pub fn new(id: impl Into<String>) -> ArsenalResult<Self>;Source line: 36.
policy::PolicyId::generate
Generate a new random policy ID
#[must_use]
pub fn generate() -> Self;Source line: 58.
policy::PolicyId::as_str
Get the inner string
#[must_use]
pub fn as_str(&self) -> &str;Source line: 64.
policy::PolicyDocument
Policy document - the complete policy definition
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct PolicyDocument {
/// Policy ID
pub id: PolicyId,
/// Policy version (for updates)
pub version: u32,
/// Tenant this policy belongs to
pub tenant_id: TenantId,
/// Human-readable name
pub name: String,
/// Description
#[serde(skip_serializing_if = "Option::is_none")]
pub description: Option<String>,
/// Policy rules
pub rules: Vec<PolicyRule>,
/// Default effect when no rules match
pub default_effect: PolicyEffect,
/// Whether this policy is active
pub is_active: bool,
/// Priority (higher = evaluated first)
pub priority: i32,
/// When the policy was created
pub created_at: chrono::DateTime<chrono::Utc>,
/// When the policy was last modified
pub updated_at: chrono::DateTime<chrono::Utc>,
/// Policy signature (if signed)
#[serde(skip_serializing_if = "Option::is_none")]
pub signature: Option<PolicySignature>,
/// Custom labels
#[serde(default)]
pub labels: HashMap<String, String>
}Source line: 83.
policy::PolicyDocument::new
Create a new policy document
Errors
Returns an error if validation fails
pub fn new(tenant_id: TenantId, name: impl Into<String>) -> ArsenalResult<Self>;Source line: 120.
policy::PolicyDocument::add_rule
Add a rule to the policy
Errors
Returns an error if too many rules
pub fn add_rule(&mut self, rule: PolicyRule) -> ArsenalResult<()>;Source line: 148.
policy::PolicyDocument::evaluate
Evaluate the policy for a given request
#[must_use]
pub fn evaluate(&self, request: &PolicyRequest) -> PolicyDecision;Source line: 159.
policy::PolicyDocument::to_cbor
Serialize to CBOR bytes
Errors
Returns an error if serialization fails
pub fn to_cbor(&self) -> ArsenalResult<Vec<u8>>;Source line: 191.
policy::PolicyDocument::from_cbor
Deserialize from CBOR bytes
Errors
Returns an error if deserialization fails
pub fn from_cbor(bytes: &[u8]) -> ArsenalResult<Self>;Source line: 206.
policy::PolicyRule
A single policy rule
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct PolicyRule {
/// Rule ID (unique within policy)
pub id: String,
/// Rule description
#[serde(skip_serializing_if = "Option::is_none")]
pub description: Option<String>,
/// Effect when rule matches
pub effect: PolicyEffect,
/// Conditions that must be met
pub conditions: Vec<PolicyCondition>,
/// Scopes this rule applies to
#[serde(skip_serializing_if = "Option::is_none")]
pub scopes: Option<ScopeSet>,
/// Constraints to apply
#[serde(skip_serializing_if = "Option::is_none")]
pub constraints: Option<Constraints>,
/// Rate limits to apply
#[serde(skip_serializing_if = "Option::is_none")]
pub rate_limits: Option<RateLimits>,
/// Usage budget to apply
#[serde(skip_serializing_if = "Option::is_none")]
pub budget: Option<UsageBudget>
}Source line: 218.
policy::PolicyRule::new
Create a new rule
#[must_use]
pub fn new(id: impl Into<String>, effect: PolicyEffect) -> Self;Source line: 245.
policy::PolicyRule::with_condition
Add a condition
#[must_use]
pub fn with_condition(mut self, condition: PolicyCondition) -> Self;Source line: 260.
policy::PolicyRule::with_scopes
Set scopes
#[must_use]
pub fn with_scopes(mut self, scopes: ScopeSet) -> Self;Source line: 267.
policy::PolicyRule::matches
Check if this rule matches the request
#[must_use]
pub fn matches(&self, request: &PolicyRequest) -> bool;Source line: 274.
policy::PolicyCondition
Policy condition for rule evaluation
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(tag = "type", rename_all = "snake_case")]
pub enum PolicyCondition {
/// Match on agent ID
AgentId {
/// Operator for comparison
operator: ConditionOperator,
/// Value to compare against
value: String,
},
/// Match on tenant ID
TenantId {
/// Operator for comparison
operator: ConditionOperator,
/// Value to compare against
value: String,
},
/// Match on requested scope
Scope {
/// Operator for comparison
operator: ConditionOperator,
/// Value to compare against
value: String,
},
/// Match on environment
Environment {
/// Operator for comparison
operator: ConditionOperator,
/// Value to compare against
value: String,
},
/// Match on time of day
TimeOfDay {
/// Allowed hours (0-23)
allowed_hours: Vec<u8>,
},
/// Match on day of week
DayOfWeek {
/// Allowed days (0=Sunday, 6=Saturday)
allowed_days: Vec<u8>,
},
/// Match on IP address
IpAddress {
/// Allowed CIDRs
allowed_cidrs: Vec<String>,
},
/// Match on custom attribute
Attribute {
/// Attribute key
key: String,
/// Operator for comparison
operator: ConditionOperator,
/// Value to compare against
value: String,
},
/// Boolean AND of conditions
And {
/// Conditions to AND together
conditions: Vec<PolicyCondition>,
},
/// Boolean OR of conditions
Or {
/// Conditions to OR together
conditions: Vec<PolicyCondition>,
},
/// Boolean NOT of condition
Not {
/// Condition to negate
condition: Box<PolicyCondition>,
},
}Source line: 283.
policy::PolicyCondition::evaluate
Evaluate the condition against a request
#[must_use]
pub fn evaluate(&self, request: &PolicyRequest) -> bool;Source line: 356.
policy::ConditionOperator
Comparison operator for conditions
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
pub enum ConditionOperator {
/// Exact equality
Equals,
/// Not equal
NotEquals,
/// String contains
Contains,
/// String starts with
StartsWith,
/// String ends with
EndsWith,
/// Regex match
Matches,
/// In list
In,
/// Not in list
NotIn,
}Source line: 419.
policy::ConditionOperator::compare
two strings using this operator
#[must_use]
pub fn compare(&self, actual: &str, expected: &str) -> bool;Source line: 441.
policy::PolicyEffect
Policy effect (allow or deny)
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "lowercase")]
pub enum PolicyEffect {
/// Allow the action
Allow,
/// Deny the action
Deny,
}Source line: 482.
policy::PolicyRequest
Request context for policy evaluation
#[derive(Debug, Clone)]
pub struct PolicyRequest {
/// Agent ID making the request
pub agent_id: String,
/// Tenant ID
pub tenant_id: String,
/// Requested scope
pub requested_scope: String,
/// Request timestamp
pub timestamp: chrono::DateTime<chrono::Utc>,
/// Environment (e.g., "production", "staging")
pub environment: Option<String>,
/// Client IP address
pub client_ip: Option<String>,
/// Custom attributes
pub attributes: HashMap<String, String>
}Source line: 491.
policy::PolicyRequest::new
Create a new policy request
#[must_use]
pub fn new(agent_id: String, tenant_id: String, requested_scope: String) -> Self;Source line: 511.
policy::PolicyRequest::with_environment
Set environment
#[must_use]
pub fn with_environment(mut self, env: impl Into<String>) -> Self;Source line: 525.
policy::PolicyRequest::with_client_ip
Set client IP
#[must_use]
pub fn with_client_ip(mut self, ip: impl Into<String>) -> Self;Source line: 532.
policy::PolicyRequest::with_attribute
Add an attribute
#[must_use]
pub fn with_attribute(mut self, key: impl Into<String>, value: impl Into<String>) -> Self;Source line: 539.
policy::PolicyDecision
Result of policy evaluation
#[derive(Debug, Clone)]
pub struct PolicyDecision {
/// The effect (allow/deny)
pub effect: PolicyEffect,
/// ID of the rule that matched (if any)
pub matched_rule: Option<String>,
/// Reason for the decision
pub reason: Option<String>
}Source line: 547.
policy::PolicyDecision::is_allowed
Check if the decision allows the action
#[must_use]
pub fn is_allowed(&self) -> bool;Source line: 559.
policy::PolicyDecision::is_denied
Check if the decision denies the action
#[must_use]
pub fn is_denied(&self) -> bool;Source line: 565.
policy::PolicySignature
Policy signature for tamper-resistance
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct PolicySignature {
/// Signature bytes
pub bytes: Vec<u8>,
/// Algorithm used
pub algorithm: String,
/// Key ID used for signing
pub key_id: String,
/// When the signature was created
pub signed_at: chrono::DateTime<chrono::Utc>
}Source line: 572.