Understanding Casbin with different Access Control Model Configurations
ACL, RBAC, ABAC
Hello Developers 👋. Authorization is a key part of every system we built and Casbin is one common name we hear in every language for authorization.
Casbin currently has its support for Golang, Java, C/C++, Node.js, Javascript, PHP, Laravel, Python, .NET (C#), Delphi, Rust, Ruby, Swift (Objective-C), Lua (OpenResty), Dart (Flutter), and Elixir.
In this article, My goal is to demonstrate the working of casbin and its different available model configurations in a simple and understandable flow.
If you already know the basics of casbin and just need the implementation flow of casbin in golang, you can check my other article on Authorization in Golang Projects using Casbin.
Workflow of Casbin
Before going on different model configurations, let's try to understand the workflow of casbin with a simple overview diagram as shown below.

I have split the overall workflow into two-phase namely the Configuration and Implementation.
Configuration Phase
This phase is all about the configurations.
Step1 (Model)
Here we configure the model as per our requirement. We make use of the CONF file (.conf file extension) to abstract our model configuration. This configuration is based on PERM metamodel (Policy, Effect, Request, Matchers) (will go on its details below with examples).
In the above diagram, I have taken the basic and simplest model in Casbin i.e. ACL (will be discussed later)
Step2 (Policy)
Here we define the policies like who can do what and who has what permissions
Basic Syntax for Policy is
p= sub, obj, act, eft
This syntax can be read as who(sub) can/cannot(allow/deny) do what(act) on some resource(obj)
Here eft can be either allow or deny. If it is not included, the default value is allow.
In the above diagram as per policies defined
- John has permission to read RECORD1
- John has no permission to write RECORD1
- Harry has permission to read RECORD1
- Harry has permission to write RECORD1
Implementation Phase
This phase is all about the implementation as per model configurations[Step 1] and listed policies [Step 2]
Step3 (Request)
This is the real-time scenario when a user tries to access or do his desired actions on some resource.
In the above diagram as per the incoming request
- John wants to read RECORD1
- John wants to write on RECORD1
Enforcement Result
This is the real-time scenario when the decision is taken whether to allow the user to access or do his desired actions to the given resource.
Step4 (Matcher)
The first step in enforcing results is to match the request with the policy list. In the above example, we have the following matcher expression which just guarantees subject, object, and action in a request should match the ones in a policy rule.
m = r.sub == p.sub && r.obj == p.obj && r.act == p.actStep5 (Policy Effect)
After finding the policy from the policy list using matcher expression, the other step in enforcing results is applying the policy effect. In the above example, we have the following policy effect which means that a user has permission as long as there is one matching policy that allows him to do so
e = some(where (p.eft == allow))After these two steps casbin enforce result as
- John is allowed to read RECORD1 ✔️
- John is denied to write on RECORD1 ❌
Going Deeper
I hope the simple overview presented above will help to visualize the Casbin working flow to some extent. Now we will see different ways to configure the model [Step1 as per the above diagram]
Types of Access Control
Access Control List (ACL)
This is the most basic access control mechanism. This lists 1–1 mapping of each user's permission on a given resource.
If there are total three users;user1,user2,user3. There is a permissions defined for each users individually.user1 can only read record1
user2 can only write record1
user3 can read and write record1Casbin Model Configuration




