Urgent.News

What's breaking now, across thousands of outlets.

Tech

Stuck on Casbin's model.conf? 5 mistakes beginners hit most

Stuck on Casbin's model.conf? The 5 mistakes beginners hit most (with a runnable fix) Casbin is one of the few permission frameworks that works across languages (Go / Java / Python / Node…), and its architecture is refreshingly clean: model.conf defines the rules, the policy stores the data. But nearly every beginner stumbles on "those few lines of rules" — especially when everything just returns…

Struggling with Casbin's model.conf? Here are the five mistakes that beginners commonly make when working with this permission framework. Casbin works across multiple programming languages, including Go, Java, Python, and Node.js. Its architecture is defined by the model.conf file, which outlines the rules, while the policy stores the data.

1. The matcher field names may not match the request or policy columns. The columns declared in [request_definition] and [policy_definition] are the only ones the matcher can use, and their order is crucial. For instance, if your request is "alice reads data1" but you accidentally swap the action and object, the matcher will return false, and no error will be raised. This makes it challenging to debug the issue.

2. Understanding how g() works is essential. The function g(r.sub, p.sub) is not magical; it checks if the subject (r.sub) is equal to the policy subject (p.sub), either directly or through role inheritance. A common mistake is assuming that g() alone is sufficient. In reality, role relationships must also be defined in the policy using g rows. If not, no user will ever match.

3. The policy effect and matchers may behave unexpectedly when used together. The [policy_effect] section determines how multiple matched policies are combined into a single result. By default, each policy is allow, meaning one allow rule is enough to grant access. However, if you need to explicitly deny access for a user or team, use an eft column with priority(p.eft) || deny to create a clean and efficient policy table.

4. Missing role-graph rows can cause issues with the g function. The policy needs both parts to function correctly: the policy definition (p) and the role graph (g). For example, if alice belongs to the 'admin' role and wants to read '/data read', both the policy and role graph must be defined as p, admin, /data, read and g, alice, admin. If this role-graph row is missing, alice will not be able to match the '/data read' rule.

5. The cache may not update when refreshing the enforcer. If you use the syncedCachedEnforcer, updating the policy but still receiving the same enforce result usually means the cache was not refreshed. This issue is unrelated to the rules in model.conf. First, check the cache, and then revisit the model.conf file.

Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.

Read the original at dev.to →

More in Tech

What Building 77 Browser-Based Calculators Taught Me About Input Validation

Building one calculator is straightforward. Building dozens of calculators with different units, assumptions, ranges, and failure modes is where input handling becomes the real product.

  • Validate data domain, not just type; enforce range constraints with requireRange utility
  • Convert all units to base unit before computation, convert final result to display unit

How I Audit JavaScript Regexes for Catastrophic Backtracking

I maintain CodeSwap , a developer-tools site with browser-based utilities and technical guides. While reviewing its regular-expression tools, I wanted a repeatable answer to a deceptively simple…

  • Systematic audit process identifies ambiguous repetition and measures performance growth.
  • Node.js 22 test reveals exponential growth in matching time with increasing input length.

Every typing site makes you type prose. I built one that makes you type code.

I have been typing for twenty years and I still slow down on =>. Not on words. Words are fine. It is {}, [], &&, ::, ?., !== — the keys my fingers only ever meet inside code, and never inside the…

  • Typre is a typing site exclusively for real code
  • Features include no repeated snippets, separate run lengths, language-specific pools
  • Offline functionality with bundled snippets and real-time syntax highlighting

More from Sunday 30 August →