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, policies, and templates
- Authorization engine: Real-time policy evaluation using Cedar
- Caching layer: Fast in-memory access powered by DashMap
- Database abstraction: Pluggable storage backend powered by Nitrite DB (
mango-query-rs) - Thread-safe operations: Concurrent access using DashMap and async Tokio runtime
Architecture
Core Components
┌─────────────────────────────────────────────────────────┐
│ Cedrus Core │
├─────────────────────────────────────────────────────────┤
│ Authorization Engine (Cedar Policy Evaluation) │
├─────────────────────────────────────────────────────────┤
│ Cache Layer (DashMap In-Memory Cache) │
├─────────────────────────────────────────────────────────┤
│ Database Layer (Nitrite DB / mango-query-rs) │
└─────────────────────────────────────────────────────────┘
Storage Traits
The library defines key traits for storage and caching:
Database Trait (crate::db::Database)
Persists Cedar policies, entities, schemas, templates, template links, and projects:
- Implementation:
NitriteDb(embedded document storage) - Operations: CRUD for projects, schemas, entities, policies, templates, template links, API keys
- Query support: MangoQuery filtering (
mango-query-rs) and pagination
Cache Trait (crate::cache::Cache)
Provides fast in-memory access to authorization data:
- Implementation:
DashMapCache - Purpose: Reduce database lookups and improve authorization evaluation performance
- Scope: Per-project caching of schemas, entities, policies, and templates
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, projects, and administrative access
- Entities:
Cedrus::User: Represents usersCedrus::Project: Represents tenant projectsCedrus::Group: User groups (e.g., "Admins")Cedrus::ApiKey: Admin and project API keys
User Projects
Each project is an isolated tenant with:
- Unique ID: UUID v7
- API Key: Base64-encoded key for service-to-service authentication
- Owner: User entity who owns the project
- Roles: Template-based role assignments
- Isolated data: Own schemas, entities, policies, and templates
Authorization Flow
- Authentication: User authenticates via OIDC (JWT token) or API key
- Token mapping: Map token claims to
EntityUid, parent groups, and entity attributes - Admin check: Verify if user is in "Admins" group or holds admin API key
- Project authorization: Evaluate Cedar policies in Admin Project
- Resource authorization: Evaluate Cedar policies in target project
Key Features
Real-Time Authorization
// Check if principal can perform action on resource
let response = cedrus.is_authorized.await?;
match response.decision
Batch Authorization
// Check multiple requests concurrently
let requests = vec!;
let responses = cedrus.is_authorized_batch.await?;
Entity Hierarchy
Entities support parent relationships for group membership (e.g. OIDC cognito:groups mapped to Group::"X"):
let mut parents = new;
parents.insert;
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
use ;
// 1. Initialize DB and Cache backends
let db = Boxnew;
let cache = Boxnew;
// 2. Instantiate Cedrus authorization engine
let mut cedrus = new.await;
// 3. Initialize Admin Project (on first startup)
cedrus.init_admin_project.await?;
Performance Considerations
Caching Strategy
- Schemas: Cached per project (loaded concurrently during evaluation)
- Entities: Cached per project and loaded alongside request entities
- Policies & Templates: Cached per project
- Concurrent evaluation:
is_authorizedfetches policies and entities concurrently usingtokio::try_join!
Batch Operations
Use batch operations for high-throughput evaluation:
project_entities_add(): Add multiple entities at onceproject_policies_add(): Add multiple policies at onceis_authorized_batch(): Evaluate multiple authorization requests at once
Integration
This library is used by:
- cedrus: REST API server that exposes Cedrus functionality over HTTP/OpenAPI
- Custom applications: Can embed Cedrus Core directly into Rust microservices
Dependencies
cedrus-cedar: Type definitions, serialization, and Cedar bindingscedar-policy: Official Cedar policy enginemango-query-rs: Query filtering engine for Nitrite DBdashmap: Concurrent in-memory hash mapjwt-authorizer: JWT token validationtokio: Async runtime