Skip to content

fix: filter direct-user rules by domain in GetImplicitUsersForResourceByDomain - #1772

Closed
yxshee wants to merge 1 commit into
apache:masterfrom
yxshee:fix/resource-by-domain
Closed

yxshee wants to merge 1 commit into
apache:masterfrom
yxshee:fix/resource-by-domain

Conversation

@yxshee

@yxshee yxshee commented Nov 8, 2026

Copy link
Copy Markdown

GetImplicitUsersForResourceByDomain only checked the domain of a rule when its subject was a role in the queried domain. Rules whose subject is a plain user, or a role that only exists in another domain, were returned no matter which domain they belong to.

With examples/rbac_with_domains_model.conf and examples/rbac_with_domains_policy.csv:

e.AddPolicy("carol", "domain2", "data1", "read")
e.AddPolicy("manager", "domain2", "data1", "write")
e.AddGroupingPolicy("dave", "manager", "domain2")
e.GetImplicitUsersForResourceByDomain("data1", "domain1")

Actual: [[alice domain1 data1 read] [alice domain1 data1 write] [carol domain2 data1 read] [manager domain2 data1 write]]
Expected: [[alice domain1 data1 read] [alice domain1 data1 write]] (Enforce("carol", "domain1", "data1", "read") is false, and manager is a role, not a user, in domain2).

The domain check now runs for every rule before the role/user split, using the same exact comparison the role branch already used.

The new cases in TestGetImplicitUsersForResourceByDomain fail on master with Implicit users for data1 in domain domain1 : [... [carol domain2 data1 read] [manager domain2 data1 write]] , supposed to be [[alice domain1 data1 read] [alice domain1 data1 write]]. go test -race ./... passes and golangci-lint v2.15 reports 0 issues.

@hsluoyz

hsluoyz commented Nov 15, 2026

Copy link
Copy Markdown
Member

Thanks for the report and the clear reproduction, the bug is real.

It's fixed on master in c157de4 with a slightly broader change, so I'm closing this PR:

  • The domain check now applies to every rule, as you proposed. It uses the role manager's Match, the same way GetImplicitPermissionsForUser does, so domain patterns (AddNamedDomainMatchingFunc) behave consistently between the two APIs.
  • Roles are detected through the role manager instead of GetAllRolesByDomain, so links in pattern domains like g, alice, admin, * are expanded instead of returning admin as a user.
  • Multi-level roles are expanded with GetImplicitUsers, and intermediate roles are no longer returned as users.
  • A model without a dom field now returns an error instead of panicking.

Your test cases are included in TestGetImplicitUsersForResourceByDomain, together with cases for the points above.

@hsluoyz hsluoyz closed this Nov 15, 2026
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