Skip to main content
Palyra implements a multi-layered security architecture that governs how users, services, and external applications interact with the daemon. This system encompasses administrative access via the Web Console and CLI, programmatic access through OpenAI-compatible endpoints, and a structured identity model for fine-grained permissioning.

Identity & The Principal Concept

The core unit of identity in Palyra is the Principal. Every request processed by the palyrad gateway or Admin API is associated with a principal string that identifies the actor.
  • Console Admin: Typically represented as admin:web-console. This principal is used for managing the daemon’s configuration, auth profiles, and vault secrets crates/palyra-daemon/tests/openai_auth_surface.rs#23-23.
  • API Tokens: Programmatic principals generated for external integrations.
  • Channel Principals: Identities derived from external connectors (e.g., Discord user IDs).
The access_control.rs module defines the WorkspaceRole enum, which maps principals to specific permission sets like Owner, Admin, and Operator crates/palyra-daemon/src/access_control.rs#76-80.

Permissions Mapping

RoleKey Permissions
OwnerAll permissions, including api_tokens.manage, trust.operate, and rollout.manage crates/palyra-daemon/src/access_control.rs#114-123.
AdminManagement of tokens, memberships, and sharing crates/palyra-daemon/src/access_control.rs#124-129.
OperatorUsage-focused: sessions.use, memory.use, and compat.chat.create crates/palyra-daemon/src/access_control.rs#104-112.
Sources: crates/palyra-daemon/src/access_control.rs#76-135, crates/palyra-daemon/tests/openai_auth_surface.rs#21-23

Auth Profile Management (palyra-auth)

The palyra-auth crate manages credentials for external Model Providers (OpenAI, Anthropic). It abstracts the complexity of API keys and OAuth2 flows into a unified AuthProfileRecord crates/palyra-auth/src/lib.rs#10-16.

Credential Lifecycle

  1. Ingestion: Credentials enter the system via the Web Console or CLI.
  2. Validation: The daemon performs a “pre-flight” check against the provider (e.g., calling /v1/models) to ensure the key is valid before saving crates/palyra-daemon/src/openai_surface.rs#32-38.
  3. Vault Storage: Raw keys are never stored in the main configuration. They are persisted in the palyra-vault and referenced via a vault_ref crates/palyra-daemon/src/openai_surface.rs#40-46.
  4. Selection: A profile is marked as the “default” for a specific provider kind, which the orchestrator then uses for model calls crates/palyra-daemon/src/openai_surface.rs#60-68.

Code Entity Relationship: Auth Flow

The following diagram illustrates the flow from a Natural Language request in the UI to the underlying Rust entities. Title: Auth Profile Creation Flow Sources: apps/web/src/console/hooks/useAuthDomain.ts#130-166, crates/palyra-daemon/src/openai_surface.rs#16-76, crates/palyra-daemon/src/openai_auth.rs#189-195

OpenAI-Compatible Auth Surface

Palyra provides a compatibility layer (compat.rs) that allows external tools to use Palyra as if it were the OpenAI API. This surface is protected by AuthenticatedApiToken crates/palyra-daemon/src/transport/http/handlers/compat.rs#78-88. Sources: crates/palyra-daemon/src/transport/http/handlers/compat.rs#105-126, crates/palyra-common/src/redaction.rs#1-37

Access Control Implementation

Access control logic is centralized in access_control.rs, which manages the access_registry.json file crates/palyra-daemon/src/access_control.rs#13-14. Title: Access Control Architecture Sources: crates/palyra-daemon/src/access_control.rs#137-183, crates/palyra-daemon/src/transport/http/handlers/compat.rs#1-10

CLI Authentication Commands

The CLI provides a comprehensive suite for managing identities and profiles without the Web Console.

Command Dispatch Example

When a user runs palyra auth profiles list, the CLI:
  1. Resolves a gRPC connection to the Admin endpoint crates/palyra-cli/src/commands/auth.rs#9-12.
  2. Constructs a ListAuthProfilesRequest with filters for provider kind or scope crates/palyra-cli/src/commands/auth.rs#51-63.
  3. Injects necessary metadata (tokens/CSRF) into the request crates/palyra-cli/src/commands/auth.rs#64-64.
Sources: crates/palyra-cli/src/commands/auth.rs#4-96

Security Middleware & CSRF

The Admin API (used by the Web Console) employs strict security measures: Sources: crates/palyra-common/src/redaction.rs#3-22, crates/palyra-daemon/src/openai_surface.rs#40-46, crates/palyra-daemon/tests/openai_auth_surface.rs#106-130