Hodei Authorization Framework
Cedar Policy-based authorization framework for Rust applications, inspired by AWS IAM.
Overview
Hodei is a complete authorization framework that provides:
- Cedar Policy Engine: Policy-based access control using Amazon's Cedar
- Multi-Tenancy: Built-in tenant isolation with HRN (Hodei Resource Name)
- Derive Macros: Automatic code generation for entities and actions
- Database Adapters: PostgreSQL and Redis support out of the box
- Web Integration: Axum middleware and extractors
- Type-Safe: Leverages Rust's type system for compile-time safety
Quick Start
Installation
[]
= { = "0.1", = ["full"] }
Define Your Domain
use hodei-authz-*;
use ;
Write Cedar Policies
// Only document owner can read
permit(
principal,
action == Action::"Document::Read",
resource
) when {
resource.owner_id == principal
};
// Admins can do anything
permit(
principal,
action,
resource
) when {
principal.role == "admin"
};
Use in Your Application
use PostgresPolicyStore;
use RedisCacheInvalidation;
use ;
use PgPool;
async
Features
Core Features
default- Core functionality (kernel + core + derive)postgres- PostgreSQL adapterredis- Redis cache invalidationaxum- Axum web framework integrationfull- All features enabled
# Minimal installation
[]
= "0.1"
# With database support
[]
= { = "0.1", = ["postgres", "redis"] }
# Everything
[]
= { = "0.1", = ["full"] }
Architecture
Hodei is composed of several crates:
- hodei-authz-sdk-hrn: Core types (HRN)
- hodei-authz-sdk-derive: Derive macros
- hodei-authz-sdk-authz: Traits and logic
- hodei-authz-sdk-authz-postgres: PostgreSQL adapter
- hodei-authz-sdk-authz-redis: Redis adapter
- hodei-authz-sdk-authz-axum: Axum integration
- hodei-authz-sdk: Meta-crate (this crate)
Examples
Basic Authorization
use hodei-authz-*;
let user = User ;
// Check if user can read document
let can_read = check_authorization.await?;
With Axum
use AuthenticatedUser;
use ;
async
let app = new
.route
.layer;
Documentation
License
MIT OR Apache-2.0