Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

POC try scaling abac rules #121

Merged
merged 3 commits into from
Apr 19, 2020
Merged

Conversation

GopherJ
Copy link
Member

@GopherJ GopherJ commented Apr 18, 2020

This PR allows to define in model some thing like this, I would like to solve: casbin/casbin#354

[request_definition]
r = sub, obj, act

[policy_definition]
p = sub, obj, act

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

[matchers]
m = Any(_) && r.obj == p.obj && r.act == p.act

and in policy we can then write like this:

p, Any(r.sub.age > 18), /data1, read

This policy means that we don't care who is the person sending request, but his/her age should be greater than 18

I made it works in casbin-rs, not sure if we should do like this but I think it may helps solving some problems.

Also can the syntax be better?

@GopherJ GopherJ changed the title finish scaling abac rules POC try scaling abac rules Apr 18, 2020
@codecov
Copy link

codecov bot commented Apr 18, 2020

Codecov Report

Merging #121 into master will increase coverage by 0.03%.
The diff coverage is 92.10%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #121      +/-   ##
==========================================
+ Coverage   87.20%   87.23%   +0.03%     
==========================================
  Files          19       19              
  Lines        2961     2992      +31     
==========================================
+ Hits         2582     2610      +28     
- Misses        379      382       +3     
Impacted Files Coverage Δ
src/enforcer.rs 91.76% <91.66%> (-0.06%) ⬇️
src/util.rs 97.43% <92.85%> (-2.57%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 222c27d...d3207c5. Read the comment docs.

@hsluoyz
Copy link
Member

hsluoyz commented Apr 18, 2020

@GopherJ very good work! Actually it inspires me about a better grammar:

model:

[request_definition]
r = sub, obj, act

[policy_definition]
p = sub_rule, obj, act

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

[matchers]
m = eval(p.sub_rule) && r.obj == p.obj && r.act == p.act

policy:

p, any(r.sub.age > 18), /data1, read

I made this change because Any(r.sub.age > 18) is rule instead of subject itself. eval() is a built-in function that evaluates a boolean expression into a boolean. The user needs to make sure any(r.sub.age > 18) is a valid expression for Casbin matcher.

@GopherJ
Copy link
Member Author

GopherJ commented Apr 18, 2020

@hsluoyz I love the new grammar because Any is just what I used to test and avoid conflicts ~~ sub_rule is a good design which refers to an ABAC rule.

So just to think about implementation:

we should check if matcher has eval(*) right? If yes, we replace it by the inside variable's value and add a () to avoid && || priority problem.

@hsluoyz
Copy link
Member

hsluoyz commented Apr 18, 2020

I think your implementation is simple and correct. Thumbs up!

@GopherJ
Copy link
Member Author

GopherJ commented Apr 18, 2020

ok thanks!

@hsluoyz
Copy link
Member

hsluoyz commented Apr 19, 2020

lgtm

@hsluoyz hsluoyz merged commit 16f45d0 into casbin:master Apr 19, 2020
@hsluoyz
Copy link
Member

hsluoyz commented Apr 19, 2020

As next step, we can:

  1. Sync this feature to Golang' Casbin and solve this issue: Scaling ABAC Rules casbin#354
  2. Add it to ABAC docs: https://casbin.org/docs/en/abac

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants