[#12095] feat(auth): parse X-Gravitino-Active-Roles into the request path#12096
Open
bharos wants to merge 4 commits into
Open
[#12095] feat(auth): parse X-Gravitino-Active-Roles into the request path#12096bharos wants to merge 4 commits into
bharos wants to merge 4 commits into
Conversation
Code Coverage Report
Files
|
bharos
force-pushed
the
active-roles-wiring-11969
branch
5 times, most recently
from
July 20, 2026 20:41
05cae48 to
5ac66cc
Compare
bharos
marked this pull request as ready for review
July 20, 2026 20:46
bharos
force-pushed
the
active-roles-wiring-11969
branch
2 times, most recently
from
July 20, 2026 20:52
f72d5e6 to
a637b61
Compare
roryqi
reviewed
Jul 21, 2026
| * <p>Backed by a {@link ThreadLocal}; the value must be {@link #clear() cleared} when the request | ||
| * completes so it never leaks to the next request on a pooled thread. | ||
| */ | ||
| public final class ActiveRolesContext { |
Contributor
There was a problem hiding this comment.
I prefer moving this into UserPrincipal instead of thread local variable.
Contributor
Author
There was a problem hiding this comment.
Done , moved active roles onto UserPrincipal instead of a thread-local. Since UserPrincipal is immutable, withActiveRoles(...) returns a copy with the roles attached, and the filter binds that copy before doAs. Hope creating and returning a copy is OK here ? Otherwise please let me know if you think of any better way.
bharos
force-pushed
the
active-roles-wiring-11969
branch
2 times, most recently
from
July 21, 2026 18:34
09388c5 to
ac91af3
Compare
…quest path Parse the X-Gravitino-Active-Roles header once per request and carry the declared active roles on the UserPrincipal, activating the narrowing enforcement. - UserPrincipal: carry an immutable ActiveRoles (defaults to ALL) alongside the existing per-request accessToken; add withActiveRoles() to attach the parsed value. - AuthenticationFilter: parse the header after authentication and attach it to the principal; a malformed value maps to 400 via IllegalActiveRolesException (the Lance filter maps the same). - AuthorizationRequestContext: read activeRoles from the current UserPrincipal so every authorization decision uses the request's declaration. Absent header behaves as ALL (no narrowing). Membership validation (403 for an unheld role) is metalake-scoped and follows in a later PR. Part of apache#12095.
bharos
force-pushed
the
active-roles-wiring-11969
branch
from
July 21, 2026 18:55
ac91af3 to
27f2777
Compare
…med active-roles header returns 400
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.
What changes were proposed in this pull request?
Parse the
X-Gravitino-Active-Rolesheader and carry the declared active roles on theUserPrincipal, so the narrowing from #11967 takes effect.UserPrincipal: carry an immutableActiveRoles(defaults toALL) alongside the existing per-requestaccessToken;withActiveRoles()attaches the parsed value.AuthenticationFilter: parse the header after authentication and attach it to the principal. A malformed value maps to400(the Lance filter maps the same).AuthorizationRequestContext: readactiveRolesfrom the currentUserPrincipal, so every authorization decision uses the request's declaration.Membership validation (
403for an unheld role) is metalake-scoped and follows in a later PR. Part of #11965.Why are the changes needed?
#11967 added the narrowing enforcement, but nothing populated the active roles, so it never activated. This wires the header through the request path.
Does this PR introduce any user-facing change?
Yes, additive and backward compatible. A request may send
X-Gravitino-Active-Roles: <role>[,<role>] | ALL | NONEto narrow the roles used for authorization; a malformed value returns400. An absent header behaves as before (ALL).How was this patch tested?
New unit tests for
UserPrincipal.withActiveRoles, the filter's header parsing (valid / absent / malformed →400), andAuthorizationRequestContextreading the active roles from the principal. Verified with the moduletestandspotlessChecktasks forcore,server-common, andlance-rest-server.