Skip to main content
This page documents the security architecture of Palyra, focusing on identity management, session handling, OAuth2 integration (specifically for OpenAI), and the Role-Based Access Control (RBAC) system.

Authentication and Session Management

Authentication in Palyra is handled primarily by the palyra-auth crate, which manages credentials, profiles, and session lifecycles.

Auth Profiles and Registry

The AuthProfileRegistry is the central authority for managing authentication profiles. A profile contains credentials (API keys or OAuth tokens) scoped to either a global level or a specific agent crates/palyra-auth/src/lib.rs#10-21.

Console Sessions and CSRF Protection

The Web Console uses a session-based authentication model. When a user logs in, the daemon issues a ConsoleSession which includes a principal and a csrf_token crates/palyra-control-plane/src/models.rs#8-16. Auth Flow Diagram Title: Console Authentication and CSRF Flow Sources: crates/palyra-control-plane/src/models.rs, apps/web/src/App.config-access-support.test.tsx, crates/palyra-daemon/src/app/state.rs

OAuth2 and OpenAI Integration

Palyra implements a specialized OAuth2 flow for OpenAI, allowing users to authenticate via the OpenAI dashboard and refresh tokens automatically.

OAuth Refresh Mechanism

The palyra-auth crate provides an OAuthRefreshAdapter to handle background token rotation crates/palyra-auth/src/refresh.rs#17-20.

OpenAI Auth Surface

The daemon exposes specific endpoints for OpenAI integration:
  1. API Key Flow: Allows manual entry of sk-... keys, which are immediately validated against https://api.openai.com/v1/models crates/palyra-daemon/src/openai_auth.rs#189-195.
  2. OAuth Flow: Implements PKCE (Proof Key for Code Exchange) with generate_pkce_verifier and pkce_challenge crates/palyra-daemon/src/openai_auth.rs#99-107.
Code Mapping Diagram Title: OpenAI Auth Implementation Mapping Sources: crates/palyra-daemon/src/openai_auth.rs, crates/palyra-auth/src/refresh.rs, crates/palyra-cli/src/commands/secrets.rs

Access Control and RBAC

Palyra implements a robust Access Control system via the AccessRegistry, supporting Feature Flags, API Tokens, and Workspace-level RBAC.

Access Registry

The AccessRegistry is persisted in access_registry.json and manages the following entities crates/palyra-daemon/src/access_control.rs#13-22:
  • Feature Flags: Controls access to subsystems like compat_api, rbac, and api_tokens.
  • API Tokens: Used for programmatic access (e.g., OpenAI-compatible endpoints). Tokens have a token_hash_sha256 for secure verification crates/palyra-daemon/src/access_control.rs#151-173.

Role-Based Access Control (RBAC)

The system defines three primary WorkspaceRole levels crates/palyra-daemon/src/access_control.rs#76-80:
RolePermissions
OwnerFull access including trust.operate, rollout.manage, and workspace.manage.
Adminapi_tokens.manage, membership.manage, and sharing.manage.
Operatorsessions.use, memory.use, routines.use, and observability.read.

Principal Binding

Requests are authorized based on the principal string. RBAC Flow Diagram Title: Permission Evaluation Flow Sources: crates/palyra-daemon/src/access_control.rs, crates/palyra-daemon/src/transport/http/handlers/compat.rs

Secrets Management

Secrets (API keys, OAuth tokens) are managed via the Vault and the palyra secrets CLI. Sources: crates/palyra-cli/src/commands/secrets.rs, apps/web/src/App.config-access-support.test.tsx