Repository navigation
fix: casbin org matching logic with glob - #1193
Merged
Merged
Conversation
sauraww
approved these changes
Dec 1, 2026
Datron
reviewed
Dec 1, 2026
| } | ||
|
|
||
| fn org_domain(domain: Dynamic) -> Dynamic { | ||
| let domain = domain.into_string().unwrap_or_default(); |
Contributor
There was a problem hiding this comment.
If domain can't be unwrapped, it will fall back to empty string, and we return that as Dynamic. This could be exploited due to a mistake in configuration or values passed?
Comment on lines
+434
to
+435
| assert_eq!(map(""), ""); | ||
| assert_eq!(org_domain(Dynamic::from(1_i64)).into_string().unwrap(), ""); |
Contributor
There was a problem hiding this comment.
Should this be inverted? We should fail on empty strings and wrong parses right?
Datron
approved these changes
Dec 2, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
A role granted at org level (e.g.
g, user, reader, aarokyasbx_*) did nothing for requests to that org's workspaces (aarokyasbx_backend). The grant only worked if the same role also had aprow at exactly{org}_*.adminhappened to work for orgs created through the API, becauseadd_org_policycreated ap admin {org}_*row.reader, and any role whose policies are defined at*, were denied, so people had to be granted the role again on every workspace.Root cause
g()matches domains by exact string. The matcher only checked a grant atp.domorr.dom, never at the request's org ({org}_*).Changes
Matcher (
model.conf)orgDomain(org_ws→org_*;*andorg_*are returned unchanged). The subject check now also matches a grant atorgDomain(r.dom), so a role granted at{org}_*applies to every workspace in that org, whatever domain the role's policies use.globMatch(r.dom, p.dom)→p.dom == orgDomain(r.dom). This gives the same result for every domain shape we allow (*,org_*,org_ws). It also avoids casbin compiling a new glob for every policy row on every request.g3beforeg2, the global grant last). Dropped the redundant== true. No decision changes from the reordering: every clause is joined by&&and has no side effects.Org creation / backfill
add_org_policynow only addsg, {admin_email}, admin, {org}_*. The per-orgp admin {org}_* * * *row isn't needed any more, because the seededp admin * * * *now applies through the org grant.POST /authz/admin/backfillkeeps working and now inserts only thegrows.Workspace admin sync removed
on_workspace_creation/on_workspace_admin_updatefromAuthorizerand their casbin/no-auth implementations, the calls in the workspace create/update handlers, and the workspace backfill endpoint.adminon it toworkspace_admin_email, and changing that email no longer moves the grant. Workspace access now has to be granted explicitly, or comes from an org-level grant.Testing
9 new unit tests in
casbin.rs, run against the realmodel.confwith an in-memory enforcer:aarokyavsaarokyasbx), or*;readerstays read-only, and reads resolve throughg3action groups;prow;*grants behave as before.The two tests that reproduce the bug fail on the old matcher and pass on the new one.
Rollout notes
p admin {org}_*rows are now redundant but harmless. Keep them until this has been stable, because they're what keeps org admins working if this is rolled back.grows stay as they are./superposition/organisations) still use domain*, soorganisation:getandorganisation:listremain global-only.