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] Unexpected behaviour group match #1396

Closed
sangamk opened this issue May 21, 2024 · 3 comments
Closed

[question] Unexpected behaviour group match #1396

sangamk opened this issue May 21, 2024 · 3 comments

Comments

@sangamk
Copy link

sangamk commented May 21, 2024

Describe the bug
Given a group with numerical values m = g(r.user, p.role, r.tag) and g, 1, 2, proj-1, I get true when I try to match user with id 2 even though that group does not exist.

To Reproduce
Steps to reproduce the behavior:

  1. Policy, I removed all the fluff:
[request_definition]
r = user, path, method, tag

[policy_definition]
p = role, path, method, tag

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

[role_definition]
g = _, _, _

[matchers]
m = g(r.user, p.role, r.tag)
  1. Example policy:
p, 1, /something, GET, proj-*
g, 2, 1, proj-1
g, 3, 1, proj-1
  1. Perform the following request:
1, /something, GET, proj-1

Expected behavior
When I run the code above in the online editor or in the lib I expect the return to be false instead it is true.

If I change my policy:

p, r1, /something, GET, proj-*
g, 2, r1, proj-1
g, 3, r1, proj-1

Then it works as expected.
Desktop (please complete the following information):

  • OS: Macbook
  • Browser Chrome

Additional context
In the online editor I get the same issue:
https://editor.casbin.org/#3ZLSE3E75

@casbin-bot
Copy link
Member

@tangyang9464 @JalinWang

@feellmoose
Copy link
Contributor

feellmoose commented Jun 2, 2024

There is a note for this question in [RBAC | Casbin](https://casbin.org/docs/rbac/)

  1. Do not use the same name for a user and a role inside an RBAC system, because Casbin recognizes users and roles as strings, and there's no way for Casbin to know whether you are specifying user alice or role alice. You can simply solve it by using role_alice.

Given policies

p, 1, /something, GET, proj-*
g, 2, 1, proj-1
g, 3, 1, proj-1
  1. Role 1 has a policy that allows GET actions on the /something resource for all projects matching proj-*.
  2. Users 2 and 3 inherit the permissions of Role 1 for the project proj-1. Therefore, users 2 and 3 have GET access to /something within the proj-1 project.

The issue arises when User 1, who is not explicitly granted the permissions of Role 1, also acquires those permissions.

Behavior

When adds the inheritance link between two roles (role: name1 and role: name2), we while add map between strings.

In such cases, a role in the policy is also treated as a user. Consider the following model configuration:

[request_definition]
r = user, path, method

[policy_definition]
p = role, path, method

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

[role_definition]
g = _, _

[matchers]
m = g(r.user, p.role)

And the following policy:

p, admin, /something, GET
g, alice, admin
g, bob, admin

When we use admin to access /something with the GET method, it will also be allowed because the admin role is treated as a user.

In this model, roles can effectively act as users, allowing them to inherit permissions directly. This behavior must be carefully managed to ensure that roles and users are assigned appropriately and to avoid unintended permission grants.

@sangamk sangamk closed this as completed Jun 3, 2024
@sangamk
Copy link
Author

sangamk commented Jun 3, 2024

Thanks for explaining. Makes sense

@hsluoyz hsluoyz added question and removed bug labels Jun 3, 2024
@hsluoyz hsluoyz changed the title [Bug] Unexpected behaviour group match [question] Unexpected behaviour group match Jun 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

No branches or pull requests

4 participants