How It Works
Within Casbin, access control models are represented as CONF files structured around the PERM metamodel (Policy, Effect, Request, Matchers). Changing your project's authorization mechanism is as straightforward as updating a configuration file. You can build custom access control models by mixing and matching available components—for example, combining RBAC roles with ABAC attributes in a single model that operates on one policy rule set.
The PERM model consists of four core elements: Policy, Effect, Request, and Matchers. These components work together to define how resources and users interact.
Request
Specifies the parameters required for access requests. At minimum, a basic request contains three elements in tuple form: subject (the entity requesting access), object (the target resource), and action (the intended operation).
A typical request definition looks like:
r={sub,obj,act}
This definition establishes both the parameter names and their sequence as expected by the access control matching function.
Policy
Establishes the structure for access rules. This component defines the field names and their order within policy rule documents.
Example definitions:
p={sub, obj, act} or p={sub, obj, act, eft}
Note: When eft (policy result) isn't included in the definition, the result field in policy files is ignored, and matching policies default to "allow".
Matcher
Specifies how requests are matched against policies.
Example: m = r.sub == p.sub && r.act == p.act && r.obj == p.obj
This straightforward matching rule states that when request parameters (entity, resource, and operation) match those in a policy, that policy's result (p.eft) applies. The policy result is stored in p.eft.