Introduce
My next post is about tools for managing roles and dynamically controlling access to resources. Some business requirements demand extreme flexibility, often requiring a combination of RBAC + ABAC at the same time.
From my experience, I’ve seen a lot of solutions, but most don’t cover all the key points. There are three circles that are really hard to combine: Performance, Security, and Flexibility. And when someone tries to implement all three—oh, it’s painful.
But I found a technology that (almost) solves this challenge: Cerbos—a scalable, open-source authorization layer for handling roles and permissions. (Cerbos site)
Why is it good?
✅ Centralized configuration – Everything is managed in one place.
✅ Easy integration – SDKs are available for all popular languages:
🔹 .NET, Go, Java, JS, PHP, Python, Ruby, Rust
✅ Great documentation – Clear examples and guidance.
✅ Playground for testing – No need to run an app or set up tools. Just test and debug your policy inside the Cerbos Playground. Super useful!
✅ YAML-based policies – Simple, readable, and easy for non-developers to configure.
Less talk, more code—let’s go! 🚀
How to start the Cerbos server locally (In my case, running the binary via Brew was faster and easier than using Docker—surprisingly! 👀)
Link on a repository with code: https://github.com/kolomiietsmykola/cerbos-demo
Description of actions in code
"seller"
is assigned a"user"
role- Attribute
"regular": true
product:object
)
- r1 ("Private_Product") →
owner: seller
,public: false
- r2 ("Product_Card_2") →
owner: another_seller
,public: true
view:public,
edit, and
create)Different examples and scenarios
1. Full Access for Product Owners
- If a user owns a product, they can perform any action ('*' wildcard).
2. Limited Access to Private Products for Non-Owners
- Buyers or other users cannot view private products unless explicitly allowed.
- The private attribute determines whether a product is public or private.
- Only owners and moderators can access private products.
3. Prevent Editing of Flagged Products
- Even owners cannot edit products if they are flagged.
- Only moderators or admins can edit flagged products.
Comparing
Feature | Cerbos | Zanzibar / SpiceDB |
---|---|---|
Type | Policy-based Access Control (PBAC) | Relationship-based Access Control (ReBAC) |
Core Model | Policies define roles, attributes, and conditions for access decisions | Uses a graph-based model where relationships between users and resources define access |
Best for | Fine-grained authorization with conditional rules (e.g., attribute-based) | Large-scale systems requiring hierarchical and dynamic relationships |
Use Cases | Enterprise apps, API authorization, microservices | Social networks, multi-tenant SaaS, document-sharing apps |
Scalability | Lightweight, fast decision engine (embedded or API-based) | Distributed, designed for high-scale and low-latency lookups |
Evaluation Speed | Fast, as policies are evaluated in-memory or via API | Optimized for caching and distributed queries but may require DB lookups |
Complexity | Easier to set up, simple YAML policies | More complex setup, requires database or backend storage |
Storage | Stateless (no storage required) | Requires a database (e.g., CockroachDB, PostgreSQL, memory-based) |
Deployment | Can run as a service or embedded in an app | Runs as a distributed service, needs persistent storage |
Integration | API-based, SDKs for multiple languages | API-based, supports gRPC and REST, libraries available |
Authorization Model | Attribute-based and role-based (ABAC/RBAC) | Relationship-based (ReBAC), similar to Google's Zanzibar |
Flexibility | Supports custom conditions and attributes | Supports dynamic relationships and hierarchical permissions |
Examples | Controlling API access based on roles, attributes, or user context | Managing access in collaboration tools, social networks, or large-scale multi-tenant applications |
When to Use Cerbos
- If you need fine-grained access control with attribute-based conditions.
- If you want a lightweight authorization engine without needing a database.
- If your application has a simple or moderate complexity access model.
- If you prefer YAML-based policies for easier management.
When to Use Zanzibar/SpiceDB
- If you need Google Zanzibar-like scalability for millions of relationships.
- If your application requires complex, hierarchical relationships for access control.
- If you want highly dynamic access control, like in social networks or SaaS platforms.
- If you can manage a dedicated database for access control storage.
Comments
Post a Comment