question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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

See original GitHub issue

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;
};

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:17 (13 by maintainers)

github_iconTop GitHub Comments

3reactions
cwkang1998commented, Mar 6, 2022

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

1reaction
Shivansh-yadav13commented, Mar 5, 2022

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

Read more comments on GitHub >

github_iconTop Results From Across the Web

No results found

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found