access_control module, which manages principal-based identity, API tokens, and feature flagging.
Cedar-Based Policy Engine (palyra-policy)
The palyra-policy crate implements the core authorization logic. It uses a default set of Cedar policies to enforce a “deny-by-default” posture while allowing granular overrides based on the request context.
Policy Evaluation Flow
When a component (like theGatewayService) needs to authorize an action, it constructs a PolicyRequest and a PolicyRequestContext. These are passed to the engine, which evaluates them against the loaded PolicySet.
- Request Construction: A
PolicyRequestis created containing theprincipal,action, andresourcecrates/palyra-policy/src/lib.rs#11-15. - Context Enrichment: The
PolicyRequestContextprovides environmental metadata such asdevice_id,session_id, andcapabilitiescrates/palyra-policy/src/lib.rs#18-26. - Cedar Evaluation: The engine uses the
cedar-policycrate’sAuthorizerto match the request against theDEFAULT_POLICY_SRCcrates/palyra-policy/src/lib.rs#99-181. - Decision: The result is a
PolicyDecision(AlloworDenyByDefault) along with a detailedPolicyExplanationfor auditing crates/palyra-policy/src/lib.rs#61-81.
Default Policy Rules
The system ships with several hardcoded baseline policies:deny_sensitive_without_approval: Blocks actions marked as sensitive ifallow_sensitive_toolsis false in the config crates/palyra-policy/src/lib.rs#100-105.allow_read_only_actions: Permits non-mutating actions liketool.listordaemon.statuscrates/palyra-policy/src/lib.rs#107-118.allow_allowlisted_tool_execute: Permitstool.executeonly if the tool is in the allowlist and the principal/channel are authorized crates/palyra-policy/src/lib.rs#120-127.
Tool Call Policy and Capabilities
Thetool_protocol module defines how policies are applied specifically to tool execution. Tools are classified by their Capabilities, which determine the level of sensitivity and the required sandbox enforcement.
Tool Capability Classification
Tools are associated withToolCapability variants crates/palyra-daemon/src/tool_protocol.rs#47-52:
ProcessExec: Execution of native binaries.Network: Egress to external hosts.SecretsRead: Access to the Palyra Vault.FilesystemWrite: Modifications to the workspace.
Sensitivity and Approval
A tool is considered “sensitive” if it possesses any capability listed inSENSITIVE_CAPABILITY_POLICY_NAMES crates/palyra-daemon/src/tool_protocol.rs#148-149. If a tool is sensitive, the ToolDecision will often require approval_required: true, triggering a manual user intervention in the Web Console crates/palyra-daemon/src/tool_protocol.rs#29-34.
Sources: crates/palyra-daemon/src/tool_protocol.rs#19-150
Access Control and Principal Authorization
Theaccess_control module in palyra-daemon manages identity persistence and API-level permissions. It uses an AccessRegistry stored in access_registry.json to track tokens and roles crates/palyra-daemon/src/access_control.rs#13-14.
Identity and Roles
Palyra uses a Role-Based Access Control (RBAC) model defined byWorkspaceRole crates/palyra-daemon/src/access_control.rs#76-80:
- Owner: Full access, including
trust.operateandworkspace.manage. - Admin: Management of tokens and memberships.
- Operator: Usage-only access (chat, memory, routines).
API Token Lifecycle
Tokens are issued with specificscopes and a principal identifier crates/palyra-daemon/src/access_control.rs#151-173. When a request arrives via the compat (OpenAI-compatible) API, the daemon:
- Extracts the token from the
Authorizationheader. - Validates the hash against
ApiTokenRecord::token_hash_sha256crates/palyra-daemon/src/access_control.rs#155. - Checks if the token has the required permission (e.g.,
PERMISSION_COMPAT_CHAT_CREATE) crates/palyra-daemon/src/transport/http/handlers/compat.rs#134-142.
Implementation Diagrams
Logic Flow: Tool Authorization to Execution
This diagram bridges the Natural Language concept of “Authorizing a Tool” to the specific code entities involved in the decision and execution pipeline. Sources: crates/palyra-daemon/src/tool_protocol.rs#20-65, crates/palyra-policy/src/lib.rs#211-215, crates/palyra-daemon/src/sandbox_runner.rs#147-151Data Flow: Principal-Based Access Control
This diagram maps the authentication of a request to the internal registry and permission sets. Sources: crates/palyra-daemon/src/transport/http/handlers/compat.rs#128-142, crates/palyra-daemon/src/access_control.rs#13-103Sandbox Enforcement
For tools requiringProcessExec capabilities, the sandbox_runner applies strict resource constraints.
| Constraint | Implementation Detail | Source |
|---|---|---|
| Executable Denylist | Prevents shells (bash, pwsh) and interpreters (python, node) unless explicitly allowed. | crates/palyra-daemon/src/sandbox_runner.rs#30-44 |
| Workspace Scoping | Validates that all file arguments stay within the workspace_root. | crates/palyra-daemon/src/sandbox_runner.rs#175-180 |
| Egress Control | EgressEnforcementMode (None, Preflight, Strict) filters network requests. | crates/palyra-daemon/src/sandbox_runner.rs#47-62 |
| Resource Quotas | Enforces cpu_time_limit_ms, memory_limit_bytes, and max_output_bytes. | crates/palyra-daemon/src/sandbox_runner.rs#90-92 |