casbin / casbin

An authorization library that supports access control models like ACL, RBAC, ABAC in Golang: https://discord.gg/S5UjpzGZjN
https://casbin.org
Apache License 2.0
17.87k stars 1.65k forks source link

[Question] RBAC with conditions and DynamoDB Adapter #1331

Open kawtar01 opened 1 year ago

kawtar01 commented 1 year ago

Want to prioritize this issue? Try:

issuehunt-to-marktext


What's your scenario? What do you want to achieve? Context:

Scenario: Given that "some_user@somedomain.com" has a role/group "guests" and that the role/group "guests" has been granted temporary access to some resources in a domain when "some_user@domain" tries to access these resources and the time is not matching the temporary access condition then the access is denied.

Goal: I'm trying to leverage the concept of RBAC with conditions to set temporary access on some resources to some roles that I have defined within a domain.

Questions:

Your model:

[request_definition]
r = sub, dom, obj, act

[policy_definition]
p = sub, dom, obj, act

[role_definition]
g = _, _, _, (_, _)
g2 = _, _, _

[policy_effect]
e = some(where (p.eft == allow))

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

Your policy:

Json file that I load:
[
    {"policy_type":"p","sub":"admins","dom":"OrgA","obj":"orgA_partitions","act":"read"},
    {"policy_type":"p","sub":"admins","dom":"OrgA","obj":"orgA_partitions","act":"write"},
    {"policy_type":"p","sub":"admins","dom":"OrgA","obj":"orgA_partitions_resources","act":"read"},
    {"policy_type":"p","sub":"admins","dom":"OrgA","obj":"orgA_partitions_resources","act":"write"},
    {"policy_type":"p","sub":"guests","dom":"OrgA","obj":"orgA_partitions","act":"read"},
    {"policy_type":"p","sub":"guests","dom":"OrgA","obj":"orgA_p1_buildings","act":"read"},
    {"policy_type":"p","sub":"guests","dom":"OrgA","obj":"orgA_p1_buildings_b1","act":"read"},
    {"policy_type":"p","sub":"guests","dom":"OrgA","obj":"orgA_p1_buildings_b1","act":"write"},
    {"policy_type":"p","sub":"guests","dom":"OrgA","obj":"orgA_p1_buildings_b2_floors_f1","act":"read"},

    {"policy_type":"g","user":"super_user@somedomain.com","group":"admins", "dom":"OrgA" , "condition":{"start":"0000-01-01 00:00:00","end":"9999-12-30 00:00:00"}},
    {"policy_type":"g","user":"some_user@somedomain.com","group":"guests","dom":"OrgA" , "condition":{"start":"0000-01-01 00:00:00","end":"0000-01-02 00:00:00"}},
    {"policy_type":"g2","obj":"/partitions/:id","objSet":"orgA_partitions", "dom":"OrgA" },
    {"policy_type":"g2","obj":"/partitions/*","objSet":"orgA_partitions_resources", "dom":"OrgA" },
    {"policy_type":"g2","obj":"/partitions/p1/buildings","objSet":"orgA_p1_buildings", "dom":"OrgA"},
    {"policy_type":"g2","obj":"/partitions/p1/buildings/b1","objSet":"orgA_p1_buildings_b1", "dom":"OrgA"},
    {"policy_type":"g2","obj":"/partitions/p1/buildings/b2/floors/f1","objSet":"orgA_p1_buildings_b2_floors_f1", "dom":"OrgA"}
  ]

Your request(s):

super_user@somedomain, OrgA,  /partitions/*, read ---> false (expected: true)
super_user@somedomain, OrgA,  /partitions/*, write ---> false (expected: true)
some_user@somedomain, OrgA,  /partitions/*, read ---> false (expected: false)
some_user@somedomain, OrgA,  /partitions/*, write ---> false (expected: false)

As am new to Casbin, I'm not really sure if there is something I'm missing, if this is due to the Adapter,...

Thanks a lot for your help and guidance :)

casbin-bot commented 1 year ago

@tangyang9464 @JalinWang

hsluoyz commented 3 months ago

@kawtar01 can you make a PR?