palyra-policy crate. It leverages the Cedar policy language to provide fine-grained, attribute-based access control (ABAC) for tool executions, skill invocations, and administrative actions.
Overview and Purpose
The primary role of the engine is to intercept requests within thepalyra-daemon and determine if a given principal (e.g., a user or an automated agent) is permitted to perform an action on a specific resource. This is most critically used during the decide_tool_call flow to ensure that LLM-driven tool requests adhere to security guardrails.
Key Components
palyra-policycrate: Encapsulates the Cedar SDK, providing a high-level API for evaluation. crates/palyra-policy/src/lib.rs#1-10DEFAULT_POLICY_SRC: A hardcoded set of baseline Cedar policies that enforce “deny-by-default” and manage sensitive operations. crates/palyra-policy/src/lib.rs#99-181PolicyEvaluationConfig: A runtime configuration object that bridges daemon settings (like allowlisted tools) into the policy evaluation context. crates/palyra-policy/src/lib.rs#29-38
Data Mapping: Tools to Cedar Entities
When a tool call is evaluated, Palyra maps internal Rust structures to Cedar’sRequest and Context entities.
Entity Mapping Table
| Palyra Concept | Cedar Entity | Code Reference |
|---|---|---|
| Principal | Principal::<id> | crates/palyra-policy/src/lib.rs#12 |
| Action | Action::<name> | crates/palyra-policy/src/lib.rs#13 |
| Resource | Resource::<id> | crates/palyra-policy/src/lib.rs#14 |
| Capabilities | context.capabilities | crates/palyra-policy/src/lib.rs#25 |
| Sensitivity | context.is_sensitive_action | crates/palyra-policy/src/lib.rs#103 |
Natural Language to Code Entity Space
This diagram illustrates how a natural language request from an LLM (“Run the ‘ls’ command”) is transformed into a formal Cedar Authorization Request. Sources: crates/palyra-daemon/src/tool_protocol.rs#205-230, crates/palyra-policy/src/lib.rs#211-230Policy Evaluation Flow
Thedecide_tool_call function in the daemon is the primary consumer of the policy engine. It prepares a PolicyRequest and evaluates it against the loaded PolicySet.
Tool Decision Logic
- Budget Check: Validates if the
max_calls_per_runhas been exceeded. crates/palyra-daemon/src/tool_protocol.rs#242-250 - Context Assembly: Gathers
principal,session_id, andcapabilities(e.g.,network,process_exec). crates/palyra-daemon/src/tool_protocol.rs#252-270 - Cedar Evaluation: Calls
evaluate_with_contextin thepalyra-policycrate. crates/palyra-policy/src/lib.rs#211-215 - Approval Check: If the action is “sensitive” (e.g.,
process_exec), the engine may return anAllowdecision that still flagsapproval_required. crates/palyra-daemon/src/tool_protocol.rs#315-330
Decision Flow Diagram
This diagram traces the internal function calls from the daemon’s tool protocol into the Cedar engine. Sources: crates/palyra-daemon/src/tool_protocol.rs#232-340, crates/palyra-policy/src/lib.rs#211-250Default Policies (DEFAULT_POLICY_SRC)
Palyra ships with a set of embedded policies that define the safety baseline. These are defined in crates/palyra-policy/src/lib.rs.
Core Policy Logic
- Sensitive Action Blocking: Forbids sensitive actions if
allow_sensitive_toolsis false. crates/palyra-policy/src/lib.rs#100-105 - Read-Only Access: Permits common status and health checks (e.g.,
tool.read,daemon.status). crates/palyra-policy/src/lib.rs#107-118 - Allowlisted Execution: Permits
tool.executeonly if the tool is in theallowlisted_toolslist and the principal/channel are authorized. crates/palyra-policy/src/lib.rs#120-127 - Capability Management: Maps capabilities like
process_execorsecrets_readto required permissions. crates/palyra-daemon/src/tool_protocol.rs#47-64
Sensitive Actions List
The following actions are categorized as sensitive by default and often trigger a human-in-the-loop approval requirement:cron.deletememory.deletememory.purgetool.execute(if tool has sensitive capabilities likeProcessExec)
Configuration: PolicyEvaluationConfig
This struct controls how the engine interprets the runtime state of the daemon.
Key Fields Explained
allowlisted_tools: Tools the agent is explicitly allowed to call. crates/palyra-policy/src/lib.rs#30allow_sensitive_tools: A global toggle that, if false, forces all sensitive tool calls to be denied or routed for manual approval. crates/palyra-policy/src/lib.rs#32sensitive_capability_names: Maps toToolCapabilityvariants likefilesystem_writeornetwork. crates/palyra-daemon/src/tool_protocol.rs#148-150