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.
| Subsystem | Purpose | Key Files |
|---|
| Secrets Manager | Encrypted storage for API keys and credentials | security/secrets/ |
| Credential Rotation | Automatic rotation of provider API keys | security/rotation/ |
| Access Control | Permission engine for workspace resources | security/access/ |
| Tenant Isolation | Multi-tenant workspace boundary enforcement | security/tenancy/ |
| Gateway Security | Token validation, audit logging, rate limiting | security/gateway/ |
| Guardrails | Content policy enforcement and PII detection | guardrails/evaluator.ts |
| Entitlements Engine | License and feature-gating | entitlements/engine.ts |
API keys and credentials are stored encrypted (security/secrets/store.ts):
| Feature | Implementation |
|---|
| Encryption at rest | AES-256 via security/secrets/manager.ts |
| Key derivation | PBKDF2 with workspace-specific salts |
| Redaction | Automatic redaction in logs (security/secrets/redact.ts) |
| Access audit | Every key access is logged |
The rotation engine (security/rotation/engine.ts) handles:
| Function | Purpose |
|---|
CredentialRotationEngine | Orchestrates scheduled key rotation |
rotateKey() | Rotates a single provider key |
detectStaleKeys() | Identifies keys approaching expiry |
| Provider Type | Rotation Interval |
|---|
| Cloud providers (OpenAI, Anthropic) | 90 days |
| Self-hosted (Ollama, local) | Disabled |
| Enterprise contracts | Configurable |
The permission engine (security/access/engine.ts) enforces:
| Permission | Description |
|---|
workspaces:read | View workspace configuration |
workspaces:write | Modify workspace settings |
providers:create | Add new provider connections |
providers:delete | Remove provider connections |
traces:read | View execution traces |
traces:delete | Delete execution traces |
billing:read | View billing and cost data |
billing:write | Modify budget settings |
admin:all | Super admin access |
Workspace isolation is enforced at multiple levels (security/tenancy/):
| Level | Enforcement |
|---|
| Database | Row-level security per workspaceId |
| Runtime | Context injection prevents cross-tenant lookups |
| Cache | Tenant-scoped cache keys |
| Logs | WorkspaceId tagged on every log entry |
The guardrails evaluator (guardrails/evaluator.ts) checks requests for:
| Check | Action |
|---|
| PII detection | Block or redact if PII detected |
| Sensitive data | Sanitize sensitive data in traces (sanitizeSensitiveData()) |
| Content policy | Enforce workspace content policies |
| Rate limiting | Per-workspace and per-provider rate limits |
The entitlements engine (entitlements/engine.ts) manages:
| Feature | Control |
|---|
| License activation | Validates license keys |
| Feature gating | Enables/disables features based on tier |
| Snapshot management | License snapshot and validation |
| File | What It Does |
|---|
security/secrets/store.ts | Encrypted credential storage |
security/secrets/manager.ts | Key derivation and encryption |
security/secrets/redact.ts | Log redaction |
security/rotation/engine.ts | Key rotation orchestration |
security/rotation/detector.ts | Stale key detection |
security/access/engine.ts | Permission evaluation |
security/tenancy/context.ts | Tenant context injection |
security/gateway/middleware.ts | Gateway token validation |
security/gateway/audit.ts | Access audit logging |
guardrails/evaluator.ts | Content policy and PII checks |
entitlements/engine.ts | License and feature entitlements |
- Execution Engine → reads API keys from Secrets Manager
- Provider Registry → triggers rotation on credential expiry
- Workspace Profiles → reads tenant context for isolation
- Economics → respects feature entitlements (e.g., simulation access)
- All API routes → pass through gateway middleware for auth and audit