jarredhj0214 opened a new pull request, #12172:
URL: https://github.com/apache/gravitino/pull/12172

   ### What changes were proposed in this pull request?
   
   This PR updates `JcasbinLoadedRolesCache` to clear only the loaded role 
policies when a role cache entry is evicted.
   
   Instead of calling `deleteRole(roleId)`, the cache eviction now delegates to 
`JcasbinAuthorizer#clearRolePolicies`, which removes only `p(roleId, ...)` 
policies from the allow and deny enforcers.
   
   The test is also updated to verify that cache invalidation removes the role 
policies but preserves the user-role bindings.
   
   ### Why are the changes needed?
   
   `loadedRoles` tracks whether a role's permission policies have been loaded 
into jCasbin. It should only own role policy cleanup.
   
   Calling `deleteRole(roleId)` also removes `g(user/group, roleId)` role 
bindings. This can cause a transient authorization failure when a request has 
already bound user roles, then the loaded role cache entry expires and removes 
the binding before enforcement. In that case, jCasbin may return `Hit Policy: 
[]`, while a later retry succeeds after the binding is added again.
   
   Using `clearRolePolicies` keeps role policy refresh behavior while avoiding 
accidental removal of user/group role bindings.
   
   Fix: #12169
   
   ### Does this PR introduce _any_ user-facing change?
   
   No.
   
   ### How was this patch tested?
   
   ```bash
   ./gradlew spotlessApply :server-common:test --tests 
org.apache.gravitino.server.authorization.jcasbin.TestJcasbinAuthorizer 
-PskipITs -PskipDockerTests=false


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to