Skip to main content
The Palyra Web Console implements a multi-tiered authentication and session management system designed to secure the operator surface while providing seamless transitions between the Desktop application and the browser. This system handles administrative login, session persistence via cookies, Cross-Site Request Forgery (CSRF) protection, and third-party Model Provider OAuth flows.

Console Authentication Flow

The authentication flow for the web console is primarily handled by the palyrad daemon’s admin HTTP transport layer. Access to the console requires an admin:* principal crates/palyra-daemon/src/transport/http/handlers/console/auth.rs#31-35.

1. Login & Session Issuance

The console_login_handler processes login requests. It validates the provided principal and device ID, then verifies the Authorization bearer token if the daemon is configured to require authentication crates/palyra-daemon/src/transport/http/handlers/console/auth.rs#19-88. Upon successful validation, the daemon:
  1. Mints a new session token and a CSRF token crates/palyra-daemon/src/transport/http/handlers/console/auth.rs#101-101.
  2. Sets a Set-Cookie header containing the session token. The cookie is marked Secure if the request used TLS crates/palyra-daemon/src/transport/http/handlers/console/auth.rs#103-106.
  3. Returns a ConsoleSessionResponse containing the csrf_token, principal, and expiration timestamps crates/palyra-daemon/src/transport/http/handlers/console/auth.rs#107-110.

2. Desktop Handoff

To support moving from the Desktop app to a full browser window without re-authenticating, Palyra uses a “handoff token” mechanism:

Web Console Auth Sequence

This diagram illustrates the transition from an unauthenticated state to a session established via Desktop Handoff. Sources: crates/palyra-daemon/src/transport/http/handlers/console/auth.rs#127-175, apps/web/src/App.test.tsx#69-107

ConsoleApiClient Internals

The ConsoleApiClient in apps/web/src/consoleApi.ts is the central gateway for all frontend communication with the daemon. It manages session state and enforces security protocols.

CSRF Protection

The client implements a “fail-closed” CSRF strategy for mutating requests (POST, PUT, DELETE, PATCH):

Request Lifecycle

The client uses the browser fetch API. It includes credentials: "include" on all requests to ensure the session cookie is transmitted apps/web/src/consoleApi.test.ts#89-89.
FeatureImplementation
Session RefreshgetSession() retries on 429 (rate limit) before falling back to login apps/web/src/App.test.tsx#38-67.
TimeoutHandled via AbortController (defaults vary by endpoint).
Error HandlingThrows ControlPlaneApiError containing category and retryability info apps/web/src/consoleApi.test.ts#3-8.
Sources: apps/web/src/consoleApi.ts#1-50, apps/web/src/consoleApi.test.ts#44-106

Model Provider Auth (OpenAI/Anthropic)

Palyra supports authenticating with LLM providers via API Keys or OAuth. These credentials are never stored in the clear in the main configuration; instead, they are placed in the Vault.

API Key Flow

When an operator adds an OpenAI or Anthropic API key:
  1. Validation: The daemon performs a “live probe” against the provider’s models endpoint (e.g., /v1/models for OpenAI) to verify the key before saving crates/palyra-daemon/src/openai_surface.rs#34-40.
  2. Vault Storage: The key is stored in the Vault using a scoped reference (e.g., openai/api_key/[profile_id]) crates/palyra-daemon/src/openai_surface.rs#42-48.
  3. Profile Creation: An AuthProfileView is created containing the vault reference, not the raw key crates/palyra-daemon/src/openai_surface.rs#49-60.

OpenAI OAuth Callback

For OpenAI OAuth, the daemon manages a multi-step bootstrap:

Provider Auth Code Entities

This diagram maps the UI concepts to the backend implementation functions. Sources: apps/web/src/console/sections/AuthSection.tsx#62-111, crates/palyra-daemon/src/openai_surface.rs#18-78, crates/palyra-daemon/tests/openai_auth_surface.rs#29-105

AuthSection UI

The AuthSection provides the operator interface for managing identities and provider connections.

Key Components

Security Posture

The UI enforces redaction. Sensitive values like API keys or vault references are wrapped in WorkspaceRedactedValue components or kept only in the daemon’s memory until explicitly requested via a “reveal” action apps/web/src/console/sections/AuthSection.tsx#19-20, crates/palyra-daemon/tests/openai_auth_surface.rs#101-104. Sources: apps/web/src/console/sections/AuthSection.tsx#84-144, apps/web/src/console/hooks/useAuthDomain.ts#48-68