Open-source authorization service inspired by Google Zanzibar for building fine-grained RBAC, ReBAC and ABAC access controls outside your app code.
apache/casbin
Go access control library that enforces ACL, RBAC, and ABAC authorization policies, configured through model and policy files.
- Stars
- 20,482
- Forks
- 1,767
- Open issues
- 39
- Last commit
- 2 days ago
What is it?
Apache Casbin is an authorization library for Go projects. It evaluates whether a subject may perform an action on an object, based on an access control model defined in a configuration file and a set of policy rules. Because the model lives in a config file, changing the authorization scheme usually means editing configuration rather than rewriting application code.
The library supports ACL, RBAC (including role hierarchies, resource roles, and per-domain or per-tenant roles), ABAC using resource attributes, RESTful path and method matching, deny-override rules, and rule priorities. Policies can be loaded from files or from a database through adapters, and run-time management APIs and an RBAC-specific API let applications change permissions without restarting. Casbin itself handles enforcement and policy storage; it does not manage users, passwords, or authentication.
The project is part of the Apache Software Foundation. Sibling implementations exist for Java, Node.js, PHP, Python, .NET, C++, and Rust, and the project offers an online editor for writing models and policies.
Key features
- 01Supports ACL, RBAC, ABAC, RESTful, deny-override, and priority-based access control models.
- 02Defines access control models in a config file based on the PERM metamodel.
- 03Loads and stores policies through pluggable adapters, such as databases.
- 04Provides management and RBAC APIs for changing permissions at run-time.
- 05Includes built-in matching operators such as keyMatch for resource path patterns.
- 06Offers synchronized enforcer variants for concurrent use.
Use cases
- Adding role-based permission checks to a Go web service or API.
- Enforcing multi-tenant rules where users hold different roles in different tenants.
- Expressing attribute-based rules, such as allowing only a resource's owner to edit it.
- Managing permissions through an admin interface that updates policies at run-time.
Quick start
- 1
Install the library with Go modules
go get github.com/casbin/casbin/v3 - 2
Create an enforcer from a model file and a policy file
- 3
Call Enforce in your code before each access to check the request
Things to know
- The Enforcer is not safe for concurrent use, so shared enforcers that change at run-time need the synced variants.
- The library does not handle authentication or manage users and roles, so your app must provide those.
Topics
FAQ
- What is casbin?
- Go access control library that enforces ACL, RBAC, and ABAC authorization policies, configured through model and policy files. Apache Casbin is an authorization library for Go projects. It evaluates whether a subject may perform an action on an object, based on an access control model defined in a configuration file and a set of policy rules. Because the model lives in a config file, changing the authorization scheme usually means editing configuration rather than rewriting application code.
- Is casbin free to use? What license does it have?
- casbin is open source under the Apache-2.0 license. Check the license terms before using it in commercial products.
- Is casbin still maintained?
- Actively maintained. The last commit to casbin was on Nov 4, 2026.
- What can I use casbin for?
- Adding role-based permission checks to a Go web service or API. Enforcing multi-tenant rules where users hold different roles in different tenants. Expressing attribute-based rules, such as allowing only a resource's owner to edit it. Managing permissions through an admin interface that updates policies at run-time.
- How do I install casbin?
- Install the library with Go modules: go get github.com/casbin/casbin/v3 Create an enforcer from a model file and a policy file Call Enforce in your code before each access to check the request
- Where can I get casbin?
- The source code and installation instructions are on GitHub: https://github.com/apache/casbin
Summary generated by AI from the project's README. GitHub stats refresh daily.
Related projects
A Laravel package for storing users, roles and permissions in the database and checking them through Laravel's gate.
Self-hosted authorization engine (PDP) that evaluates YAML policies to decide who can perform which actions on which resources.
A general-purpose policy engine that lets you write authorization and compliance rules in Rego and evaluate them from services, Kubernetes, and other systems.
A TypeScript data layer with a Prisma-compatible ORM, built-in access control, and automatic CRUD APIs and TanStack Query hooks.
Official Python monorepo of client libraries for Supabase, covering Postgres queries, auth, storage, realtime and edge functions.