Skip to content

Multi-Tenant Isolation

Layerr is built from the ground up as a multi-tenant system. Every workspace is a fully isolated tenant with its own data, configuration, providers, and security boundaries.

Tenant Isolation

LayerMechanismKey File
DatabaseRow-level security + workspaceId columnsecurity/tenancy/
RuntimeTenant context injectionsecurity/tenancy/context.ts
CacheNamespace-scoped cache keyssecurity/tenancy/cache.ts
LogsWorkspaceId taggingsecurity/gateway/audit.ts
NetworkWorkspace-specific API keyssecurity/gateway/middleware.ts
SecretsEncrypted per-workspace storagesecurity/secrets/store.ts

Every database table has a workspaceId column. All queries are automatically scoped:

// All database queries include WHERE workspaceId = ?
SELECT * FROM traces WHERE workspaceId = 'my-project';

The tenancy context system (security/tenancy/context.ts) ensures:

  1. Request-time injection: Each request carries a TenantContext extracted from the API key
  2. Downward propagation: Context flows through the entire execution pipeline
  3. Automatic validation: Every data access validates tenant scope
interface TenantContext {
workspaceId: string;
workspaceSlug: string;
permissions: Permission[];
entitlements: Entitlement[];
region: string;
tier: 'free' | 'standard' | 'enterprise';
}

Cache keys are prefixed with workspace identifiers:

workspace:{slug}:provider:health
workspace:{slug}:strategy:cache
workspace:{slug}:intelligence:patterns
BoundaryEnforcement
Workspace dataCan only access own traces, configs, providers
Provider secretsAPI keys are encrypted and never exposed cross-tenant
BillingCosts attributed per-workspace, no cross-charging
Rate limitsPer-workspace, independent of other tenants

The tenancy diagnostics module (security/tenancy/diagnostics.ts) provides:

  • Cross-tenant access detection: Alerts if any query lacks workspaceId filter
  • Isolation verification: Periodic checks that tenant boundaries are intact
  • Audit trails: Complete log of who accessed what workspace data
FilePurpose
security/tenancy/context.tsTenant context extraction and propagation
security/tenancy/cache.tsTenant-scoped caching
security/tenancy/diagnostics.tsIsolation verification and diagnostics
security/tenancy/index.tsTenant isolation middleware
security/workspaces/resolver.tsWorkspace resolution from API keys
security/workspaces/guards.tsWorkspace access guards
security/gateway/audit.tsAccess audit logging
RegulationLayerr Support
GDPREU data residency, right to deletion, audit trails
SOC 2Access controls, audit logging, encryption
HIPAAPHI detection in guardrails, encrypted storage