How Casbin access control models work
masterCasbin abstracts access control into a configuration file (CONF) based on the PERM metamodel:
- Request definition (r): Defines the structure of the request (e.g.,
sub, obj, actfor subject, object, action). - Policy definition (p): Defines the structure of the stored policy rules.
- Policy effect (e): Defines how the results of the matchers are combined (e.g.,
some(where (p.eft == allow))means if any policy allows, the result is allow). - Matchers (m): Defines the logic used to match the request against the policies.
By modifying the CONF file, you can switch between different authorization mechanisms like ACL, RBAC, or ABAC without changing your application code.
# Request definition
[request_definition]
r = sub, obj, act
# Policy definition
[policy_definition]
p = sub, obj, act
# Policy effect
[policy_effect]
e = some(where (p.eft == allow))
# Matchers
[matchers]
m = r.sub == p.sub && r.obj == p.obj && r.act == p.act