Cedrus Core
Business logic and authorization engine for Cedrus.
Overview
cedrus-core is the core library that implements the Cedar Policy authorization engine with multi-tenant support. It provides:
- Multi-project isolation: Each project has its own schemas, entities, and policies
- Authorization engine: Real-time policy evaluation using Cedar
- Caching layer: Fast in-memory access with distributed cache support
- Database abstraction: Pluggable storage backends (DynamoDB, CouchDB)
- Cluster synchronization: Pub/sub for multi-instance deployments
- Thread-safe operations: Concurrent access using DashMap
Architecture
Core Components
┌─────────────────────────────────────────────────────────┐
│ Cedrus Core │
├─────────────────────────────────────────────────────────┤
│ Authorization Engine (Cedar Policy Evaluation) │
├─────────────────────────────────────────────────────────┤
│ Cache Layer (DashMap / Valkey) │
├─────────────────────────────────────────────────────────┤
│ Database Layer (DynamoDB / CouchDB) │
├─────────────────────────────────────────────────────────┤
│ PubSub Layer (Valkey / Dummy) │
└─────────────────────────────────────────────────────────┘
Storage Traits
The library defines three main traits for pluggable backends:
Database Trait
Persists Cedar policies, entities, and schemas:
- Implementations: DynamoDB, CouchDB
- Operations: CRUD for projects, schemas, entities, policies, templates, template links
- Query support: Filtering and pagination
Cache Trait
Provides fast in-memory access to authorization data:
- Implementations: Valkey (Redis), DashMap (in-memory)
- Purpose: Reduce database load and improve authorization performance
- Scope: Per-project caching of schemas, entities, and policy sets
PubSub Trait
Enables cluster synchronization across multiple Cedrus instances:
- Implementations: Valkey (Redis), Dummy (single instance)
- Purpose: Notify other instances of data changes
- Events: Project updates, entity changes, policy modifications
Multi-Tenant Model
Admin Project
Cedrus uses Cedar policies to control access to itself:
- Project ID:
00000000-0000-0000-0000-000000000000(nil UUID) - Purpose: Manages users and their access to projects
- Entities:
Cedrus::User: Represents usersCedrus::Project: Represents tenant projectsCedrus::Group: User groups (e.g., "Admins")
User Projects
Each project is an isolated tenant with:
- Unique ID: UUID v7
- API Key: Base64-encoded key for service authentication
- Owner: User who created the project
- Roles: Template-based role assignments
- Isolated data: Own schemas, entities, and policies
Authorization Flow
- Authentication: User authenticates via OIDC (JWT token) or API key
- Principal resolution: Map token/key to
Cedrus::Userentity - Admin check: Verify if user is in "Admins" group
- Project authorization: Evaluate Cedar policies in Admin Project
- Resource authorization: Evaluate Cedar policies in target project
Key Features
Real-Time Authorization
// Check if user can perform action on resource
let response = cedrus.is_authorized?;
match response.decision
Batch Authorization
// Check multiple requests at once
let requests = vec!;
let responses = cedrus.is_authorized_batch?;
Entity Hierarchy
Entities support parent relationships for group membership:
let entity = new;
Policy Templates
Reusable policy patterns with slots:
// Template with ?principal and ?resource slots
let template = Template ;
// Link template to specific entities
let link = TemplateLink ;
Initialization
Single Instance Setup
use ;
// Create backends
let db = database_factory.await;
let cache = cache_factory.await;
let pubsub = pubsub_factory.await;
// Initialize Cedrus
let cedrus = new;
// Initialize admin project (first run only)
init_project.await?;
// Load data from database to cache
init_cache.await?;
// Load cache data to memory
load_cache.await?;
Cluster Setup
For multi-instance deployments:
- One instance calls
init_project()andinit_cache() - All instances call
load_cache()to load from shared cache - All instances subscribe to pub/sub for synchronization
// Subscribe to cluster events
let ops = ;
spawn;
Configuration
Database Options
CouchDB:
CouchDbConfig
DynamoDB:
DynamoDbConfig
Cache Options
In-Memory (Development):
DashMapConfig
Distributed (Production):
ValKeyConfig
PubSub Options
Single Instance:
DummyConfig
Cluster:
ValKeyConfig
Event System
Cedrus uses an event-driven architecture for cache synchronization:
Event Types
ProjectCreate: New project createdProjectUpdate: Project metadata updatedProjectRemove: Project deletedProjectPutSchema: Schema updatedProjectAddEntities: Entities addedProjectRemoveEntities: Entities deletedProjectAddPolicies: Policies addedProjectRemovePolicies: Policies deletedProjectAddTemplates: Templates addedProjectAddTemplateLinks: Template links added
Event Flow
- Local change: Instance modifies data in database and cache
- Publish event: Instance publishes event to pub/sub channel
- Receive event: Other instances receive event
- Update cache: Other instances update their local cache
Performance Considerations
Caching Strategy
- Schemas: Cached per project (rarely change)
- Entities: Cached per project (moderate changes)
- Policies: Cached per project (moderate changes)
- Authorization: Uses in-memory Cedar engine with cached data
Entity Resolution
The authorization engine automatically resolves entity hierarchies:
// Fetches entity and all parent entities recursively
let entities = cedrus.get_cedar_entities?;
Batch Operations
Use batch operations for better performance:
project_entities_add(): Add multiple entities at onceproject_policies_add(): Add multiple policies at onceis_authorized_batch(): Evaluate multiple requests at once
Integration
This library is used by:
- cedrus-http: REST API server that exposes Cedrus functionality
- Custom applications: Can embed Cedrus Core directly
Dependencies
cedrus-cedar: Type definitions and serializationcedar-policy: Official Cedar policy enginedashmap: Concurrent hash mapaws-sdk-dynamodb: DynamoDB clientcouch_rs: CouchDB clientredis: Valkey/Redis clientjwt-authorizer: JWT validation