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

[RBAC w/ Domain] Checking for an object/action permission in any domain. #304

Closed
ShawnPavel opened this issue Jul 28, 2021 · 17 comments · Fixed by #351
Closed

[RBAC w/ Domain] Checking for an object/action permission in any domain. #304

ShawnPavel opened this issue Jul 28, 2021 · 17 comments · Fixed by #351
Assignees
Labels
enhancement New feature or request

Comments

@ShawnPavel
Copy link

ShawnPavel commented Jul 28, 2021

I'm attempting to figure out how to discover if a user has the ability to perform a specific action on an object in any of my domains. Here's basically what I'm working with:

config

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

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

[role_definition]
g = _, _, _

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

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

policies

p, admin, tenant1, data1, read
p, admin, tenant1, data1, write
p, admin, tenant1, data2, read
p, admin, tenant1, data2, write
p, user, tenant1, data1, read
p, user, tenant1, data2, read

p, admin, tenant2, data1, read
p, admin, tenant2, data1, write
p, admin, tenant2, data2, read
p, admin, tenant2, data2, write
p, user, tenant2, data1, read
p, user, tenant2, data2, read

g, alice, admin, tenant1
g, bob, user, tenant2

I want to check if Alice has the write action on data1 for any domain. What is the best way to do this?

I can do an enforce and supply a domain to check if the user has data1 write access, but I can't do it for all domains at once.

I have attempted to add a custom domain matching function using the following code, but the wildCardDomainMatch doesn't seem to ever be called.

initialization

    this._permissionEnforcer = await newEnforcer(this._model, this._adapter);
    const rm = new DefaultRoleManager(10);
    await rm.addDomainMatchingFunc(this.wildCardDomainMatch);
    await this._permissionEnforcer.setRoleManager(rm);
    await this._permissionEnforcer.loadPolicy();

Domain Match Function

private wildCardDomainMatch = (requestDomain: string, policyDomain: string): boolean => {
  if (requestDomain === "*") {
      return true;
  }

  return requestDomain === policyDomain;
};
@hsluoyz
Copy link
Member

hsluoyz commented Jul 29, 2021

@nodece @Zxilly @Gabriel-403

@hsluoyz hsluoyz self-assigned this Jul 29, 2021
@hsluoyz hsluoyz added the question Further information is requested label Jul 29, 2021
@Zxilly
Copy link
Contributor

Zxilly commented Jul 29, 2021

@hsluoyz Did this util exist in casbin-golang? I wonder what should I named it.

@ShawnPavel
Copy link
Author

@Zxilly I didn't see any util in the casbin-golang that met this criteria.

@Zxilly
Copy link
Contributor

Zxilly commented Jul 31, 2021

Maybe we can add a series of util function, like getImplicitCrossDomainPermissionsForUser(), to achieve this. I didn't find a good solution to implement this in enforce().

@Zxilly
Copy link
Contributor

Zxilly commented Jul 31, 2021

@ShawnPavel And another option is (g(r.sub, p.sub, r.dom) || r.sub == admin), for this can have a better performance.

@ShawnPavel
Copy link
Author

@ShawnPavel And another option is (g(r.sub, p.sub, r.dom) || r.sub == admin), for this can have a better performance.

@Zxilly I'm not sure how that would help in this use case. They users aren't admins that I'm checking.

@ShawnPavel
Copy link
Author

Maybe we can add a series of util function, like getImplicitCrossDomainPermissionsForUser(), to achieve this. I didn't find a good solution to implement this in enforce().

How would this work?

@kasvith
Copy link

kasvith commented Sep 22, 2021

+1 I need this too

@cwkang1998
Copy link
Contributor

Its stated here https://casbin.org/docs/en/rbac-with-domains-api#getrolesforuserindomain that its available for node-casbin, but this is not yet available from what I see right now (Unless I am wrong, if so then please forgive me for being blind).

if this is not already done and is already at somewhere, I am willing to contribute and add this functionality in.

@hsluoyz
Copy link
Member

hsluoyz commented Nov 16, 2021

Hi @cwkang1998 I think nobody is working on this now. Contribution is welcome! Please make a PR for it. Can you also join our QQ group? https://casbin.org/en/help

@nodece
Copy link
Member

nodece commented Nov 16, 2021

I remember this feature has been supported, see https://casbin.org/docs/en/rbac#use-pattern-matching-in-rbac, I'm not sure whether is correct.

We should add this section doc to casbin website.

@cwkang1998
Copy link
Contributor

I remember this feature has been supported, see https://casbin.org/docs/en/rbac#use-pattern-matching-in-rbac, I'm not sure whether is correct.

We should add this section doc to casbin website.

Its definitely doable with the current Management API, its just that the simplified API in the RBAC with domain API stated is not there yet hahahaha.

@cwkang1998
Copy link
Contributor

Hi @cwkang1998 I think nobody is working on this now. Contribution is welcome! Please make a PR for it. Can you also join our QQ group? https://casbin.org/en/help

Sure!

@Shivansh-yadav13
Copy link
Member

do we still plan to add GetUsersForRoleInDomain() & GetRolesForUserInDomain() for node-casbin?
& additional getImplicitCrossDomainPermissionsForUser()?

@cwkang1998
Copy link
Contributor

Thanks for reminding me @Shivansh-yadav13 , I will submit a PR either by tonight or tmr night.

cwkang1998 added a commit to cwkang1998/node-casbin that referenced this issue Mar 10, 2022
…omain` as alias to rbac

Documentation indicates that there is existance of `getUsersForRoleInDomain` and
`getRolesForUserInDomain` api, but it does not yet exists. This commit implements these functions,
by aliasing them to existing rbac function that had already cater for domain apis, to increase and
improve dev experience.

re casbin#304
cwkang1998 added a commit to cwkang1998/node-casbin that referenced this issue Mar 10, 2022
Documentation indicates that there is existance of `getUsersForRoleInDomain` and
`getRolesForUserInDomain` api, but it does not yet exists. This commit implements these functions,
by aliasing them to existing rbac function that had already cater for domain apis, to increase and
improve dev experience.

re casbin#304
@Shivansh-yadav13
Copy link
Member

Shivansh-yadav13 commented Mar 17, 2022

I think if we just use GetDomains(user) and then just for-loop enforce then we will be able to know if Alice has the write action on data1 for any domain. (get domain needs to be added)

@cwkang1998
Copy link
Contributor

I think if we just use GetDomains(user) and then just for-loop enforce then we will be able to know if Alice has the write action on data1 for any domain. (get domain needs to be added)

You can take a look at my PR and see if it resolves the need for this. if not I think we can add this api in, but I feel like the current implementation can already achieve this.

hsluoyz pushed a commit that referenced this issue Mar 18, 2022
…#351)

Documentation indicates that there is existance of `getUsersForRoleInDomain` and
`getRolesForUserInDomain` api, but it does not yet exists. This commit implements these functions,
by aliasing them to existing rbac function that had already cater for domain apis, to increase and
improve dev experience.

re #304
@hsluoyz hsluoyz added enhancement New feature or request and removed question Further information is requested labels Mar 18, 2022
github-actions bot pushed a commit that referenced this issue Mar 18, 2022
# [5.14.0](v5.13.2...v5.14.0) (2022-03-18)

### Features

* **rbac:** add `getUsersForRoleInDomain` & `getRolesForUserInDomain` ([#351](#351)) ([4896ca2](4896ca2)), closes [#304](#304)
Zxilly added a commit that referenced this issue Apr 15, 2022
* fix: *matcher result should be boolean or number* for KeyGet2 (#347)

* fix: *matcher result should be boolean or number* for  KeyGet2

* fix: updated error hint

* fix: basic keyGet2 test

* fix: basic_keyget2_policy.csv

(cherry picked from commit 0257078)
Signed-off-by: Zxilly <zhouxinyu1001@gmail.com>

* feat(rbac): add `getUsersForRoleInDomain` & `getRolesForUserInDomain` (#351)

Documentation indicates that there is existance of `getUsersForRoleInDomain` and
`getRolesForUserInDomain` api, but it does not yet exists. This commit implements these functions,
by aliasing them to existing rbac function that had already cater for domain apis, to increase and
improve dev experience.

re #304

(cherry picked from commit 4896ca2)

* feat: #357 Support keyMatch5 (#359)

(cherry picked from commit e6a6d8a)

* test: use new utils

Signed-off-by: Zxilly <zhouxinyu1001@gmail.com>

Co-authored-by: Shivansh Yadav <yadavshivansh@gmail.com>
Co-authored-by: Chen Wen Kang <23054115+cwkang1998@users.noreply.github.com>
Co-authored-by: ZCDC_Ren <kuanglong0312@sina.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants