hodei-authz-sdk-authz-postgres
PostgreSQL adapter for the Hodei authorization framework.
Overview
hodei-authz-sdk-authz-postgres provides a production-ready PostgreSQL implementation of the PolicyStore trait from hodei-authz-sdk-authz. It handles policy persistence, CRUD operations, and includes database migrations.
Features
- PolicyStore Implementation: Full CRUD for Cedar policies
- Database Migrations: Automatic schema management with sqlx
- UUID Generation: Unique policy identifiers
- Error Handling: Typed errors with detailed messages
- Async/Await: Built on tokio and sqlx
Installation
[]
= "0.1"
= { = "0.8", = ["runtime-tokio-rustls", "postgres"] }
Usage
Basic Setup
use PostgresPolicyStore;
use PolicyStore;
use PgPool;
async
Creating Policies
use PolicyStore;
let policy_content = r#"
permit(
principal == User::"alice",
action == Action::"read",
resource
);
"#;
let policy_id = store.create_policy.await?;
println!;
Loading Policies
use PolicyStore;
// Load all policies as a Cedar PolicySet
let policy_set = store.load_all_policies.await?;
// Use with Cedar Authorizer
use ;
let authorizer = new;
let decision = authorizer.is_authorized;
CRUD Operations
use PolicyStore;
// Get a policy
let policy = store.get_policy.await?;
// List all policies
let policies = store.list_policies.await?;
for in policies
// Update a policy
store.update_policy.await?;
// Delete a policy
store.delete_policy.await?;
Database Schema
The migration creates the following table:
(
id TEXT PRIMARY KEY,
content TEXT NOT NULL,
created_at TIMESTAMP NOT NULL DEFAULT NOW,
updated_at TIMESTAMP
);
Migrations
Migrations are embedded in the binary and run automatically:
let store = new;
store.migrate.await?;
Error Handling
use PolicyStoreError;
match store.get_policy.await
Testing
Integration tests require a running PostgreSQL instance:
# Start PostgreSQL
# Run tests
DATABASE_URL="postgres://postgres:postgres@localhost/test"
License
MIT OR Apache-2.0