Skip to content

Entitlements & Security

The Security Layer protects every aspect of the Layerr system, from API keys to workspace isolation to regulatory compliance. It ensures that secrets never leak, tenants never cross boundaries, and guardrails prevent misuse.

SubsystemPurposeKey Files
Secrets ManagerEncrypted storage for API keys and credentialssrc/backend/crypto.ts, security/secrets/
Credential RotationAutomatic rotation of provider API keyssecurity/rotation/
Access ControlPermission engine for workspace resourcessecurity/access/
Tenant IsolationMulti-tenant workspace boundary enforcementsecurity/tenancy/
Gateway SecurityToken validation, audit logging, rate limitingsecurity/gateway/
GuardrailsContent policy enforcement and PII detectionguardrails/evaluator.ts
Entitlements EngineLicense and feature-gatingentitlements/engine.ts

API keys and credentials are stored encrypted (src/backend/crypto.ts):

FeatureImplementation
Encryption at restAES-256-GCM via src/backend/crypto.ts
Key derivationscrypt (crypto.scryptSync) with a random per-record salt
Per-field encryptionlocalKey, cloudKey, router.key, and each localProviders[*].key are encrypted individually
Encryption secretDerived from ENCRYPTION_SECRET (falls back to ADMIN_API_KEY with a warning)
RedactionAutomatic redaction in logs (security/secrets/redact.ts)
Access auditEvery key access is logged

The rotation engine (security/rotation/engine.ts) handles:

FunctionPurpose
CredentialRotationEngineOrchestrates scheduled key rotation
rotateKey()Rotates a single provider key
detectStaleKeys()Identifies keys approaching expiry
Provider TypeRotation Interval
Cloud providers (OpenAI, Anthropic)90 days
Self-hosted (Ollama, local)Disabled
Enterprise contractsConfigurable

API and gateway requests authenticate with the ADMIN_API_KEY, supplied either as a bearer token or a dedicated header:

Authorization: Bearer <ADMIN_API_KEY>
x-admin-key: <ADMIN_API_KEY>

If ADMIN_API_KEY is not configured, all API access is disabled. The gateway and orchestration routes (for example POST /v1/chat/completions) layer additional entitlement checks on top of the key:

RequirementEnforced By
Valid ADMIN_API_KEY (Bearer or x-admin-key)gatewayAuthMiddleware
Capability gateway_accessrequireCapability('gateway_access')
Scope orchestration.executerequireGatewayScope('orchestration.execute')

There is no separate per-workspace API key; access is governed by the single admin key plus the capability and scope entitlements above.

Client-supplied provider URLs are validated by security/url-validation.ts before any outbound fetch. The policy blocks cloud metadata endpoints (169.254.169.254, metadata.google.internal), the Kubernetes API, IPv6 loopback, and loopback to Layerr’s own port. It deliberately allows private-LAN addresses (192.168.x, 10.x, 172.16-31.x) so that self-hosted local Ollama instances remain reachable.

The permission engine (security/access/engine.ts) enforces:

PermissionDescription
workspaces:readView workspace configuration
workspaces:writeModify workspace settings
providers:createAdd new provider connections
providers:deleteRemove provider connections
traces:readView execution traces
traces:deleteDelete execution traces
billing:readView billing and cost data
billing:writeModify budget settings
admin:allSuper admin access

Workspace isolation is enforced at multiple levels (security/tenancy/):

LevelEnforcement
DatabaseRow-level security per workspaceId
RuntimeContext injection prevents cross-tenant lookups
CacheTenant-scoped cache keys
LogsWorkspaceId tagged on every log entry

The guardrails evaluator (guardrails/evaluator.ts) checks requests for:

CheckAction
PII detectionBlock or redact if PII detected
Sensitive dataSanitize sensitive data in traces (sanitizeSensitiveData())
Content policyEnforce workspace content policies
Rate limitingPer-workspace and per-provider rate limits

The entitlements engine (entitlements/engine.ts) manages:

FeatureControl
License activationValidates license keys
Feature gatingEnables/disables features based on tier
Snapshot managementLicense snapshot and validation
FileWhat It Does
src/backend/crypto.tsAES-256-GCM encryption, scrypt key derivation, password hashing
security/secrets/redact.tsLog redaction
security/url-validation.tsOutbound URL (SSRF) validation for provider targets
security/rotation/engine.tsKey rotation orchestration
security/rotation/detector.tsStale key detection
security/access/engine.tsPermission evaluation
security/tenancy/context.tsTenant context injection
security/gateway/middleware.tsGateway token validation
security/gateway/audit.tsAccess audit logging
guardrails/evaluator.tsContent policy and PII checks
entitlements/engine.tsLicense and feature entitlements
  1. Execution Engine → reads API keys from Secrets Manager
  2. Provider Registry → triggers rotation on credential expiry
  3. Workspace Profiles → reads tenant context for isolation
  4. Economics → respects feature entitlements (e.g., simulation access)
  5. All API routes → pass through gateway middleware for auth and audit