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

[Question]casbin.NewEnforcer encountered Unforeseen results #689

Closed
walterlife opened this issue Jan 27, 2021 · 15 comments
Closed

[Question]casbin.NewEnforcer encountered Unforeseen results #689

walterlife opened this issue Jan 27, 2021 · 15 comments
Assignees
Labels

Comments

@walterlife
Copy link

walterlife commented Jan 27, 2021

Hi, Team
First of all great library
I encountered a scenario, the same policy, the first check failed, and the check succeeded after 10ms. Have you encountered such a scenario?

2021-01-27 20:00:20.700 INFO model/policy.go:58 Policy:
2021-01-27 20:00:20.700 INFO model/policy.go:60 p: sub, tenant, obj, act, eft, group: [[team_admin 20882020120002 SAVE_SUBGROUP allow ] [team_admin 20882020120002 DELETE_SUBGROUP allow ] [team_admin 20882020120002 QUERY_SUBGROUP_LIST allow ] [team_admin 20882020120002 SAVE_MEMBER allow ] [team_admin 20882020120002 DELETE_MEMBER allow ] [team_admin 20882020120002 QUERY_TEAM_MEMBER_LIST allow ] [team_admin 20882020120002 AdminPermission allow ] [team_admin 20882020120002 WorkerPermission allow ]]
2021-01-27 20:00:20.700 INFO model/policy.go:64 g: , , _: [[1397 team_admin 20882020120002]]
2021-01-27 20:00:20.700 INFO model/assertion.go:86 Role links for: g
2021-01-27 20:00:20.700 INFO rolemanage/role_manager.go:234 1397 < team_admin
2021-01-27 20:00:20.701 INFO v2@v2.12.0/enforcer.go:570 Request: 1397, 20882020120002, WorkerPermission, , 8 ---> false

2021-01-27 20:00:20.722 INFO model/policy.go:58 Policy:
2021-01-27 20:00:20.722 INFO model/policy.go:60 p: sub, tenant, obj, act, eft, group: [[team_admin 20882020120002 SAVE_SUBGROUP allow ] [team_admin 20882020120002 DELETE_SUBGROUP allow ] [team_admin 20882020120002 QUERY_SUBGROUP_LIST allow ] [team_admin 20882020120002 SAVE_MEMBER allow ] [team_admin 20882020120002 DELETE_MEMBER allow ] [team_admin 20882020120002 QUERY_TEAM_MEMBER_LIST allow ] [team_admin 20882020120002 AdminPermission allow ] [team_admin 20882020120002 WorkerPermission allow ]] 
2021-01-27 20:00:20.722 INFO model/policy.go:64 g: , , _: [[1397 team_admin 20882020120002]]
2021-01-27 20:00:20.722 INFO model/assertion.go:86 Role links for: g
2021-01-27 20:00:20.722 INFO rolemanage/role_manager.go:234 1397 < team_admin
2021-01-27 20:00:20.722 INFO v2@v2.12.0/enforcer.go:570 Request: 1397, 20882020120002, WorkerPermission, , 8 ---> true

Above is the problematic data

@nodece
Copy link
Member

nodece commented Jan 27, 2021

Could you try casbin.NewSyncedEnforcer?

@hsluoyz
Copy link
Member

hsluoyz commented Jan 27, 2021

@walterlife plz add the issue title.

@walterlife walterlife changed the title [Question] [Question]casbin.NewEnforcer encountered Unforeseen results Jan 27, 2021
@walterlife
Copy link
Author

Could you try casbin.NewSyncedEnforcer?

I use NewEnforcer,Is there any difference between the two

@hsluoyz
Copy link
Member

hsluoyz commented Jan 27, 2021

@walterlife can you provide:

  1. Example model
  2. Example policy
  3. Example code

@walterlife
Copy link
Author

@walterlife can you provide:

  1. Example model
  1. Example policy
  2. Example code

@walterlife walterlife reopened this Jan 27, 2021
@hsluoyz hsluoyz moved this from Casbin Easy Tasks to Casbin Easy Tasks 2 in Casbin Easy Tasks for Beginners/Student Applicants Jan 28, 2021
@hsluoyz
Copy link
Member

hsluoyz commented Jan 28, 2021

@walterlife any update?

@walterlife
Copy link
Author

walterlife commented Jan 28, 2021

[request_definition]
r = sub, tenant, obj, act, group

[policy_definition]
p = sub, tenant, obj, act, eft, group

[role_definition]
g = _, _, _

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

[matchers]
m = (g(r.sub, p.sub, r.tenant) \
    && r.tenant == p.tenant \
    && (r.group == p.group || p.group == '*') \
    && keyMatch(r.obj, p.obj) \
    && regexMatch(r.act, p.act)) \
	|| (r.sub == p.sub && p.tenant == '*' && p.obj == '*') \
    || (r.sub == p.sub && r.tenant == p.tenant && p.obj == '*') \
    || (r.sub == p.sub && r.tenant == p.tenant && p.obj == '*' && r.group == p.group)

above is model config
I use it like this

ok, errs := enforcer.Enforce(rule.V0, rule.V1, res.Resource, action, rule.V5)

@hsluoyz
Copy link
Member

hsluoyz commented Jan 28, 2021

@closetool plz take a look.

@kilosonc
Copy link
Contributor

@walterlife may I have your policy file and source code

@walterlife
Copy link
Author

@walterlife may I have your policy file and source code

Is it convenient to add WeChat?

@kilosonc
Copy link
Contributor

@walterlife may I have your policy file and source code

Is it convenient to add WeChat?

Can you just paste some piece of pivotal file here

@hsluoyz
Copy link
Member

hsluoyz commented Jan 29, 2021

@walterlife plz provide model, policy, request and true + expected response, like this issue: #693

Better tested in: https://casbin.org/en/editor

@hsluoyz
Copy link
Member

hsluoyz commented Feb 5, 2021

@closetool

I think his log already contains the rules. We can roughly reproduce it for now.

2021-01-27 20:00:20.722 INFO model/policy.go:60 p: sub, tenant, obj, act, eft, group: [[team_admin 20882020120002 SAVE_SUBGROUP allow ] [team_admin 20882020120002 DELETE_SUBGROUP allow ] [team_admin 20882020120002 QUERY_SUBGROUP_LIST allow ] [team_admin 20882020120002 SAVE_MEMBER allow ] [team_admin 20882020120002 DELETE_MEMBER allow ] [team_admin 20882020120002 QUERY_TEAM_MEMBER_LIST allow ] [team_admin 20882020120002 AdminPermission allow ] [team_admin 20882020120002 WorkerPermission allow ]] 
2021-01-27 20:00:20.722 INFO model/policy.go:64 g: , , _: [[1397 team_admin 20882020120002]]

@kilosonc
Copy link
Contributor

kilosonc commented Feb 5, 2021

@walterlife I can not make it happen again, so perhaps you used casbin in concurrency, and should use SyncedEnforcer

@hsluoyz
Copy link
Member

hsluoyz commented Feb 7, 2021

Closed as resolved.

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

No branches or pull requests

4 participants