casbin / jcasbin

An authorization library that supports access control models like ACL, RBAC, ABAC in Java
https://casbin.org
Apache License 2.0
2.38k stars 461 forks source link

transitivity not respected #17

Closed zamrokk closed 5 years ago

zamrokk commented 5 years ago

if I create a new group of resource from the base example, then Alice is not able to access to resources contains on this new group but only the group itself

p, alice, data1,   read
p, bob, data2, write
p, data2_admin, data2, read
p, data2_admin, data2, write
g, alice, data2_admin
g, data3, datagroup
p, data2_admin, datagroup, read

if I request like this

{
    "user":"alice",
    "resource":"data3",
    "action":"read"
}

then the answer is : NO , expected is : YES

proof :

zamrokk commented 5 years ago

Fixed by :

[matchers]
m = g(r.sub, p.sub) && g(r.obj, p.obj) && r.act == p.act

why it was not set by default ? :/

Well it works

hsluoyz commented 5 years ago

Hi @zamrokk , your solution is not robust as you are mixing resource roles with user roles. If you happen to have a user named data3, and a role named datagroup. The former will inherit the latter based on your policy. The correct way is to use g2 for resource roles.

g, alice, data2_admin
g2, data3, datagroup

See RBAC with resource roles at: https://github.com/casbin/jcasbin#examples

zamrokk commented 5 years ago

yes correct , I understand it better now :)

thanks for the info :P