Optimization for IAM-like policies #1689
Replies: 2 comments 1 reply
|
Hi! IAM-style allow/deny is one of the most common things people get stuck on with Casbin — I've been there too. Good news: you don't have to duplicate every With a single [policy_definition]
p = sub, dom, obj, act, eft
[policy_effect]
e = priority(p.eft) || denyThen your policies become clean single rows: If you later need priority tiers (e.g. a global deny that always wins over a role allow), add The other common option — when deny should always win and you don't need priorities — is: e = some(where (p.eft == allow)) && !some(where (p.eft == deny))Either way you avoid the duplication you were worried about. Out of curiosity (and because I'm collecting real-world config pain for a side project): would a small tool that lets you describe a rule in plain words — e.g. "user can read docs, role editor can write, banned team always denied" — and then auto-generates a correct |
|
Great question — this is exactly the class of tradeoff people hit when building IAM-style models on Casbin, and your 8x measurement is a good tell. It's not that either model is "wrong"; the gap comes from one structural choice. Why option 1 is faster The dominant cost in a matcher is the Option 2 also makes A secondary factor: short-circuit order. Option 1 runs Recommended model Keep roles/domains on [request_definition]
r = sub, dom, obj, act
[policy_definition]
p = sub, obj, act, eft
[role_definition]
g = _, _, _ # domain-scoped user -> role
g3 = _, _ # action mapping (HTTP -> CRUD)
# drop g2 entirely
[policy_effect]
e = some(where (p.eft == allow)) && !some(where (p.eft == deny))
[matchers]
m = keyMatch5(r.obj, p.obj) && g3(r.act, p.act) && g(r.sub, p.sub, r.dom)Why this order: One structural warning about deny Your effect mixes allow and deny. That's what prevents an early exit: a Small note, happy to expand if useful. As a side project I'm exploring a small validator/generator that would flag this exact tradeoff ("obj shouldn't be a role-graph dimension — use a path matcher") while you're writing a model, and generate a working model from a plain description. If you'd use something like that, I'd welcome your input on the experience — I posted a short research thread at #1751. |
Uh oh!
There was an error while loading. Please reload this page.
Hello,
I'm trying to design an AWS IAM like system where we have a set of resources which you can "allow" or "deny" for certain roles and users.
My Initial was this:
Initial Option: Model
Initial Option: Policy
I find it's not ideal because I would need to duplicate every
pto have one fordenyand one forallow.So My second option is this:
Tentative Option; Model
Tentative Option; Policy
Both work, but the first one is significantly (at least 8 times) faster for a few thousand checks. Is there a way for me to optimize option 2 or am I better off going with my initial design?
All reactions