What is PBAC? Policy-Based Access Control in Casbin
What is PBAC?
Policy-based access control (PBAC) keeps authorization rules as policy data, separate from application code, and evaluates them at runtime. Changing who may do what means editing a policy, not shipping a new release, which is why PBAC is often chosen when security or compliance teams own the rules.
In Casbin, PBAC means storing rule expressions in policy rows and evaluating them with eval(). Unlike fixed role or attribute checks in the model, each policy row can carry its own condition.
Policies can include:
- Dynamic expressions: evaluated per request (e.g.
r.sub.Age >= 18) - Complex logic: boolean and comparison operators, attribute access
- Context: user, resource, and environment attributes
- Business rules: domain-specific logic in policy
PBAC vs ABAC vs RBAC
RBAC and ABAC describe what a decision is based on: roles, or attributes. PBAC describes how the rules are managed: as policy evaluated at runtime. The two overlap. The examples on this page are ABAC conditions managed as PBAC, and a Casbin RBAC policy is also data that can change at runtime. In practice, "PBAC" is used for systems where the rule logic itself, not only the assignments, lives in policy. Choosing an access control model compares the models on one example.
نموذج
[request_definition]
r = sub, obj, act
[policy_definition]
p = sub_rule, obj_rule, act
[policy_effect]
e = some(where (p.eft == allow))
[matchers]
m = eval(p.sub_rule) && eval(p.obj_rule) && r.act == p.act
p.sub_rule/p.obj_rule— expressions over the request (e.g.r.sub.Age >= 18,r.obj.Level >= 1)eval()— evaluates these expressions at enforce time