feat(BA-2946): Apply RBAC validator infrastructure to Session actions#9624
Draft
feat(BA-2946): Apply RBAC validator infrastructure to Session actions#9624
Conversation
Refactor Session actions to use BaseScopeAction and BaseSingleEntityAction for RBAC validation support, following VFolder patterns from BEP-1048. Changes: - Add SessionScopeAction and SessionSingleEntityAction base classes - Refactor 6 scope-level actions (Create, Search, Match) - Add _scope_type and _scope_id fields for RBAC validation - Implement scope_type(), scope_id(), target_element() methods - Refactor 4 single-entity actions (Get, Destroy, Execute, Modify) - Add session_id field for RBAC validation - Implement target_entity_id() and target_element() methods - Add field_data() method to SessionSingleEntityAction TODO: - Set _scope_type/_scope_id from context in API/processor layer - Resolve session_id from session_name before RBAC validation - Apply same pattern to remaining 20+ single-entity actions - Connect RBAC validators to action processors Related: BA-4617, BA-4620, BEP-1048 Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Contributor
There was a problem hiding this comment.
Pull request overview
Refactors Session service actions to use the RBAC validator base action infrastructure (scope-level and single-entity) to align with BEP-1048 patterns.
Changes:
- Added Session-specific
BaseScopeAction/BaseSingleEntityActionwrappers inservices/session/base.py. - Updated several Session actions (search/match/create/modify/get/execute/destroy) to provide RBAC scope/target element metadata.
- Added a changelog entry documenting the RBAC infra addition.
Reviewed changes
Copilot reviewed 12 out of 12 changed files in this pull request and generated 12 comments.
Show a summary per file
| File | Description |
|---|---|
| src/ai/backend/manager/services/session/base.py | Introduces SessionScope/SingleEntity base action wrappers for RBAC validation. |
| src/ai/backend/manager/services/session/actions/search_kernel.py | Migrates kernel search action to scope-based RBAC action and supplies scope target element. |
| src/ai/backend/manager/services/session/actions/search.py | Migrates session search action to scope-based RBAC action and supplies scope target element. |
| src/ai/backend/manager/services/session/actions/modify_session.py | Migrates session modify action to single-entity RBAC action and supplies session target element. |
| src/ai/backend/manager/services/session/actions/match_sessions.py | Migrates session match action to scope-based RBAC action and supplies scope target element. |
| src/ai/backend/manager/services/session/actions/get_session_info.py | Migrates get-session-info action to single-entity RBAC action and supplies session target element. |
| src/ai/backend/manager/services/session/actions/execute_session.py | Migrates execute-session action to single-entity RBAC action and supplies session target element. |
| src/ai/backend/manager/services/session/actions/destroy_session.py | Migrates destroy-session action to single-entity RBAC action and supplies session target element. |
| src/ai/backend/manager/services/session/actions/create_from_template.py | Migrates create-from-template action to scope-based RBAC action and supplies scope target element. |
| src/ai/backend/manager/services/session/actions/create_from_params.py | Migrates create-from-params action to scope-based RBAC action and supplies scope target element. |
| src/ai/backend/manager/services/session/actions/create_cluster.py | Migrates create-cluster action to scope-based RBAC action and supplies scope target element. |
| changes/9624.feature.md | Records the feature addition in the changelog. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
src/ai/backend/manager/services/session/actions/get_session_info.py
Outdated
Show resolved
Hide resolved
src/ai/backend/manager/services/session/actions/get_session_info.py
Outdated
Show resolved
Hide resolved
src/ai/backend/manager/services/session/actions/get_session_info.py
Outdated
Show resolved
Hide resolved
| api_version: tuple[Any, ...] | ||
| owner_access_key: AccessKey | ||
| params: ExecuteSessionActionParams | ||
| session_id: str = "" # TODO: Resolve from session_name before RBAC validation |
There was a problem hiding this comment.
Same issue as GetSessionInfoAction: target_entity_id() and target_element() can return an empty ID when session_id hasn’t been resolved. Prefer session_id: str | None and fail fast in target_entity_id()/target_element() if it’s not set (or require session_id as a mandatory field for this action).
src/ai/backend/manager/services/session/actions/execute_session.py
Outdated
Show resolved
Hide resolved
src/ai/backend/manager/services/session/actions/destroy_session.py
Outdated
Show resolved
Hide resolved
src/ai/backend/manager/services/session/actions/destroy_session.py
Outdated
Show resolved
Hide resolved
Address PR review feedback by refactoring Session action classes: - Move common RBAC methods (scope_type, scope_id, target_element, target_entity_id, field_data) from concrete classes to base classes (SessionScopeAction and SessionSingleEntityAction) - Change field defaults from GLOBAL/empty string to None with explicit validation to prevent empty RBAC elements - Add proper error messages when fields not set before RBAC validation - Fix ModifySessionAction: rename session_id to session_uuid to avoid type conflict with base class (UUID vs str), convert in __post_init__ - Update API call in gql_legacy/session.py to use new parameter name This eliminates ~200 lines of duplicated code across 10 action classes and ensures scope is always explicitly set (never defaulting to GLOBAL per user requirement). Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
…pe/_scope_id fields Change SessionScopeAction pattern to compute scope from business context instead of storing it in separate fields: - Remove _scope_type and _scope_id fields from all SessionScopeAction concrete classes (SearchSessionsAction, CreateFromParamsAction, etc.) - Each concrete class now computes scope directly from its business fields: * scope_type() always returns ScopeType.USER * scope_id() returns str(self.user_id) * target_element() uses USER scope with user_id - Add user_id field to actions that lacked it: * SearchSessionsAction * SearchKernelsAction * MatchSessionsAction Benefits: - Eliminates redundant fields (_scope_type, _scope_id) - Scope derivation logic co-located with action definition - Enforces "always USER scope" requirement at type level - API handlers now only need to provide user_id, not compute scope This follows user requirement: "scope는 모두 user id로 설정. global scope는 절대 쓰지 마라" (always use user id for scope, never use GLOBAL scope). Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Update all API handlers to provide user_id when creating SessionScopeAction instances (SearchSessionsAction, SearchKernelsAction, MatchSessionsAction). Changes: - GraphQL data loaders: get user_id from current_user() context * session/loader.py * kernel/loader.py - GraphQL fetchers: get user_id from current_user() context * kernel/fetcher/kernel.py * session/fetcher/session.py - GraphQL types: add user_id to SearchKernelsAction in kernels field * session/types.py - REST API handlers: get user_id from current_user() context * rest/session/handler.py (MatchSessionsAction) * rest/compute_sessions/handler.py (SearchSessionsAction, SearchKernelsAction) All actions now receive user_id which is used to compute USER scope for RBAC validation as required by the design. Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Remove 4 single entity actions and SessionSingleEntityAction base class to keep this branch focused on scope actions only. Single entity actions will be handled in separate branches (BA-4864). Changes: - Removed SessionSingleEntityAction and SessionSingleEntityActionResult from base.py - Restored 4 single entity action files to main state: - destroy_session.py - execute_session.py - get_session_info.py - modify_session.py - Kept SessionScopeAction and 6 scope actions: - create_cluster, create_from_params, create_from_template - match_sessions, search_kernel, search Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
- Add permission_repository parameter to SessionProcessors.__init__ - Instantiate ScopeActionRBACValidator and SingleEntityActionRBACValidator - Apply scope validator to 6 scope actions (create_cluster, create_from_params, create_from_template, match_sessions, search_kernels, search_sessions) - Apply single entity validator to 4 single entity actions (destroy_session, execute_session, get_session_info, modify_session) - Reorganize processor initialization into three logical sections: no validation, scope validation, single entity validation Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
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
BaseScopeActionandBaseSingleEntityActionbase classes for RBAC validationSessionScopeActionandSessionSingleEntityActionwithtarget_element()methods for BEP-1048 complianceTest plan
Next Steps
This PR provides the infrastructure foundation for Session RBAC validation. Follow-up work required:
_scope_type,_scope_id, andsession_idfieldsResolves BA-2946