fix(manager): format RBAC subject from integer user id - #4877
Merged
Conversation
The RBAC middleware built the Casbin enforcement subject with fmt.Sprint on the id read from the JWT claims. Because JWT claims are JSON, the id decodes as a float64, and fmt.Sprint renders any float64 value >= 1000000 in scientific notation (for example 1.234567e+06). The grouping policies are written from the integer user id (a uint), so the scientific-notation subject never matched any policy and Enforce returned false. Every request from a user whose id is >= 1000000 was rejected with HTTP 401 on every manager API endpoint. Convert the id back to uint before formatting, matching how the audit middleware already reads the same claim, so the subject equals the policy subject across the full id range. Add a regression test that drives the RBAC handler with ids around the scientific-notation boundary. Signed-off-by: Anas Khan <83116240+anxkhn@users.noreply.github.com>
anxkhn
requested review from
CooooolFrog,
EvanCley,
bergwolf,
chlins,
gaius-qi and
hhhhsdxxxx
July 14, 2026 21:38
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #4877 +/- ##
==========================================
+ Coverage 28.09% 28.11% +0.02%
==========================================
Files 232 232
Lines 23186 23186
==========================================
+ Hits 6513 6519 +6
+ Misses 16224 16214 -10
- Partials 449 453 +4
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
gaius-qi
enabled auto-merge (squash)
July 15, 2026 02:22
There was a problem hiding this comment.
Pull request overview
Fixes Manager RBAC authorization failures for large user IDs by ensuring the Casbin enforcement subject is formatted from an integer ID (matching how grouping policies are stored), and adds a regression test intended to cover IDs around the scientific-notation formatting boundary.
Changes:
- Update
RBACmiddleware to convert the JWT claim"id"(decoded asfloat64) back touintbefore formatting/enforcement. - Add an
httptest-driven regression test for RBAC behavior across a range of user IDs, including values >= 1,000,000.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| manager/middlewares/rbac.go | Formats RBAC subject using an integer-cast user ID to avoid scientific notation mismatches in Casbin subject matching. |
| manager/middlewares/rbac_test.go | Adds a regression test intended to validate RBAC decisions across IDs near/above the formatting boundary. |
- Remove explanatory comments from RBAC middleware and test helpers - Add `c.Next()` in the id-injecting middleware to ensure chain continues - Minor blank line adjustments for consistency - Update console submodule reference Signed-off-by: Gaius <gaius.qi@gmail.com>
CormickKneey
approved these changes
Jul 21, 2026
hhhhsdxxxx
approved these changes
Jul 21, 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.
The RBAC middleware built the Casbin enforcement subject with
fmt.Sprintonthe id read from the JWT claims. Because JWT claims are JSON, the id decodes as
a
float64, andfmt.Sprintrenders anyfloat64value >= 1000000 inscientific notation (for example
1.234567e+06).The grouping policies are written from the integer user id (a
uint), so thescientific-notation subject never matched any policy and
Enforcereturnedfalse. Every request from a user whose id is >= 1000000 was rejected with
HTTP 401on every manager API endpoint.This converts the id back to
uintbefore formatting, matching how the auditmiddleware already reads the same
"id"claim (manager/middlewares/audit.gouses
uint(id)), so the request subject equals the policy subject across thefull id range.
A regression test drives the real
RBAChandler throughhttptestwith idsaround the scientific-notation boundary (1, 999999, 1000000, 1234567,
4294967295). Before the fix the ids >= 1000000 return 401; after the fix all
pass.
Related Issue
Fixes #<ISSUE_NUMBER>
Motivation and Context
RBACuses the Casbin grouping matcherg(r.sub, p.sub), so the requestsubject string must equal the policy subject byte-for-byte. Policies are always
stored from the integer id (
fmt.Sprint(user.ID)whereUser.IDisuint),while the request subject was formatted from the
float64claim. The twostrings diverge for every id >= 1000000, which silently locks those accounts out
of the whole manager API. This is a fail-closed authorization defect that only
shows up once ids grow past one million, so it is easy to miss until a large
deployment hits it.
Screenshots (if appropriate)
Types of changes
Checklist