Repository navigation
feat(auth): add RBAC role constants and hierarchy support - #647
Merged
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Adds foundational RBAC infrastructure for upcoming bearer-token authentication work by introducing explicit role constants, a role hierarchy expansion helper, and updating role checks to respect inheritance.
Changes:
- Define
ROLE_VIEWER/ROLE_OPERATOR/ROLE_ADMINconstants plusROLE_HIERARCHYandget_effective_roles(). - Update
TokenData.has_role()to check roles using hierarchy expansion; dev-mode mock user now usesROLE_ADMIN. - Add unit tests covering constants, hierarchy expansion, and
TokenData.has_role()behavior.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| kagenti/backend/app/core/auth.py | Introduces RBAC constants/hierarchy + role expansion and updates role checking and dev-mode mock roles. |
| kagenti/backend/tests/test_auth.py | Adds unit tests for role constants, hierarchy expansion, and hierarchy-aware role checks. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
pdettori
force-pushed
the
api-auth/1-rbac-foundation
branch
from
February 10, 2026 21:49
764b597 to
cc4f731
Compare
Phase 1 of API bearer token authentication (epic rossoctl#639). Add foundation for Role-Based Access Control: - Define ROLE_VIEWER, ROLE_OPERATOR, ROLE_ADMIN constants - Implement role hierarchy with transitive expansion (admin -> operator -> viewer, walks graph until no new roles) - Add get_effective_roles() with cycle-safe graph traversal - Update TokenData.has_role() to check hierarchy - Update mock user in dev mode to use kagenti-admin role - Add comprehensive unit tests for role hierarchy logic (19 tests) No endpoints are protected yet - this is pure infrastructure. Co-Authored-By: Claude Opus 4.6 <[email protected]> Signed-off-by: Paolo Dettori <[email protected]>
pdettori
force-pushed
the
api-auth/1-rbac-foundation
branch
from
February 10, 2026 21:51
cc4f731 to
3a60cab
Compare
Contributor
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
5 tasks
pdettori
force-pushed
the
api-auth/1-rbac-foundation
branch
from
February 11, 2026 02:18
3a60cab to
d2428fa
Compare
Compute effective roles (with hierarchy expansion) once at TokenData initialization instead of on every has_role() call. This avoids redundant recomputation when multiple role checks occur per request. Co-Authored-By: Claude Opus 4.6 <[email protected]> Signed-off-by: Paolo Dettori <[email protected]>
pdettori
force-pushed
the
api-auth/1-rbac-foundation
branch
from
February 11, 2026 02:26
d2428fa to
6b3d5c8
Compare
This was referenced Feb 12, 2026
7 tasks
pdettori
added a commit
to pdettori/rossoctl
that referenced
this pull request
Apr 13, 2026
) Non-admin users were denied access to tools, agents, and observability pages because validate_token only mapped the 'admin' realm role to kagenti-admin but gave no kagenti-* role to regular users. All require_roles(ROLE_VIEWER) checks returned 403. Add a default mapping that gives every authenticated user the kagenti-viewer role, matching the current intent that all users can view resources. This is part of the temporary mapping (see issue rossoctl#647) that will be replaced by explicit Keycloak role provisioning. Closes rossoctl#1130 Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Paolo Dettori <[email protected]>
2 of 3 tasks
8 tasks done
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.
Summary
Phase 1 of API bearer token authentication (Epic #639).
This PR adds the foundation for Role-Based Access Control (RBAC) without protecting any endpoints yet - pure infrastructure.
Changes
ROLE_VIEWER,ROLE_OPERATOR,ROLE_ADMINconstants matching Keycloak role nameskagenti-admininheritskagenti-operatorinheritskagenti-viewerget_effective_roles(): New function to expand roles via hierarchyTokenData.has_role(): Updated to check hierarchy (admin can satisfy viewer requirements)kagenti-adminroleTesting
cd kagenti/backend uv run pytest tests/test_auth.py -vAll 19 tests pass.
Test Plan
Stacked PR
This is PR 1/5 in the API authentication stack:
Fixes #640
🤖 Generated with Claude Code