Skip to content

feat(BA-5035): Apply RBAC validator for Keypair actions#10051

Merged
fregataa merged 8 commits into
mainfrom
BA-5035
Mar 16, 2026
Merged

feat(BA-5035): Apply RBAC validator for Keypair actions#10051
fregataa merged 8 commits into
mainfrom
BA-5035

Conversation

@fregataa
Copy link
Copy Markdown
Member

Summary

  • Integrated RBAC validators into Keypair (SSH keypair) action processors following the established pattern from Group, VFolder, and Session services
  • Created KeypairScopeAction and KeypairSingleEntityAction base classes that implement required RBAC methods
  • Refactored all Keypair actions to extend appropriate base classes (scope-based or single-entity)
  • Updated processors to use ScopeActionProcessor and SingleEntityActionProcessor with proper RBAC validators

Changes

  • New base classes (services/auth/actions/base.py):
    • KeypairScopeAction - for create/list operations within a scope
    • KeypairSingleEntityAction - for get/update/delete/purge operations on single entities
  • Refactored actions to implement RBAC methods:
    • Scope actions: CreateSSHKeypair, ListSSHKeypairs
    • Single-entity actions: GetSSHKeypair, UpdateSSHKeypair, DeleteSSHKeypair, PurgeSSHKeypair
  • Updated processors (services/auth/processors.py):
    • Wired ScopeActionProcessor for scope actions with validators=[validators.rbac.scope]
    • Wired SingleEntityActionProcessor for single-entity actions with validators=[validators.rbac.single_entity]

Test plan

  • pants fmt passes
  • pants fix passes
  • pants lint passes
  • CI type checks pass
  • CI tests pass

Resolves BA-5035

Copilot AI review requested due to automatic review settings March 13, 2026 02:55
@github-actions github-actions Bot added size:L 100~500 LoC comp:manager Related to Manager component labels Mar 13, 2026
fregataa added a commit that referenced this pull request Mar 13, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Integrates RBAC validation into Keypair (SSH keypair) actions by switching to scope/single-entity action + processor patterns and enriching action results with identifiers needed by RBAC-aware base classes.

Changes:

  • Introduced Keypair-specific base action/result classes for scope and single-entity RBAC patterns.
  • Refactored Keypair actions/results to implement RBAC methods (scope/target entity/target element).
  • Wired Keypair processors to ScopeActionProcessor / SingleEntityActionProcessor with RBAC validators.

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 9 comments.

Show a summary per file
File Description
src/ai/backend/manager/services/auth/service.py Adds required identifiers to Keypair action results (access_key, user_id) to support RBAC-aware result base classes.
src/ai/backend/manager/services/auth/processors.py Switches Keypair processors to scope/single-entity processors and attaches RBAC validators.
src/ai/backend/manager/services/auth/actions/upload_ssh_keypair.py Refactors upload action/result to scope-based RBAC action/result with scope + target element methods.
src/ai/backend/manager/services/auth/actions/get_ssh_keypair.py Refactors get action/result to single-entity RBAC action/result with target entity + target element methods.
src/ai/backend/manager/services/auth/actions/generate_ssh_keypair.py Refactors generate action/result to scope-based RBAC action/result with scope + target element methods.
src/ai/backend/manager/services/auth/actions/base.py Adds KeypairScopeAction / KeypairSingleEntityAction base classes and corresponding result base classes.
changes/10051.feature.md Adds a changelog entry for RBAC enforcement on Keypair actions.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +5 to +7
from ai.backend.common.data.permission.types import RBACElementType
from ai.backend.manager.actions.types import ActionOperationType
from ai.backend.manager.services.auth.actions.base import AuthAction
from ai.backend.manager.data.permission.types import RBACElementRef
Comment on lines +29 to +30
def target_element(self) -> RBACElementRef:
return RBACElementRef(RBACElementType.KEYPAIR, self.access_key)
Comment on lines +5 to +8
from ai.backend.common.data.permission.types import RBACElementType, ScopeType
from ai.backend.manager.actions.types import ActionOperationType
from ai.backend.manager.data.auth.types import SSHKeypair
from ai.backend.manager.services.auth.actions.base import AuthAction
from ai.backend.manager.data.permission.types import RBACElementRef
Comment on lines +34 to +35
def target_element(self) -> RBACElementRef:
return RBACElementRef(RBACElementType.USER, str(self.user_id))
Comment on lines +5 to +8
from ai.backend.common.data.permission.types import RBACElementType, ScopeType
from ai.backend.manager.actions.types import ActionOperationType
from ai.backend.manager.data.auth.types import SSHKeypair
from ai.backend.manager.services.auth.actions.base import AuthAction
from ai.backend.manager.data.permission.types import RBACElementRef
Comment on lines +36 to +37
def target_element(self) -> RBACElementRef:
return RBACElementRef(RBACElementType.USER, str(self.user_id))
Comment on lines +34 to +36
class GetSSHKeypairActionResult(KeypairSingleEntityActionResult):
public_key: str
access_key: str
Comment on lines +39 to +41
class GenerateSSHKeypairActionResult(KeypairScopeActionResult):
ssh_keypair: SSHKeypair
user_id: uuid.UUID
Comment on lines +41 to +43
class UploadSSHKeypairActionResult(KeypairScopeActionResult):
ssh_keypair: SSHKeypair
user_id: uuid.UUID
fregataa and others added 7 commits March 15, 2026 12:04
Add KeypairScopeAction, KeypairScopeActionResult,
KeypairSingleEntityAction, and KeypairSingleEntityActionResult
base classes following the established pattern from
Group/VFolder RBAC implementations.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Classify and refactor SSH Keypair actions:
- GetSSHKeypairAction: Refactored to extend KeypairSingleEntityAction
  with target_entity_id() and target_element() implementation
- GenerateSSHKeypairAction: Refactored to extend KeypairScopeAction
  with scope_type(), scope_id(), and target_element() implementation
- UploadSSHKeypairAction: Refactored to extend KeypairScopeAction
  with scope_type(), scope_id(), and target_element() implementation

All keypair actions now implement required RBAC methods and use
EntityType.KEYPAIR. Updated service layer to provide additional
fields (access_key, user_id) in ActionResults.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
- Use `SingleEntityActionProcessor` for `get_ssh_keypair` with single_entity RBAC validator
- Use `ScopeActionProcessor` for `generate_ssh_keypair` and `upload_ssh_keypair` with scope RBAC validator
- Keep internal actions (signout, authorize, etc.) on plain `ActionProcessor`
- Pass RBAC validators from `ActionValidators` to enable RBAC enforcement

Follows the pattern established in group processors.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Fixed type error in GetSSHKeypairAction by using the correct enum value:
- Changed ActionOperationType.READ → ActionOperationType.GET
- Verified all quality checks pass (fmt, fix, lint, check)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Update test mocks to include required fields for ActionResult classes:
- GetSSHKeypairActionResult: add access_key parameter
- GenerateSSHKeypairActionResult: add user_id parameter
- UploadSSHKeypairActionResult: add user_id parameter

Fixes typecheck errors in CI where ActionResult classes require
entity/scope identifiers for RBAC validation.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
MagicMock(spec=ActionValidators) fails because dataclass fields without
defaults are not in dir(cls), causing AttributeError on .rbac access.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
MagicMock(spec=RBACValidators) doesn't expose dataclass instance fields
(scope, single_entity), causing AttributeError when AuthProcessors
tries to access validators.rbac.single_entity.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@fregataa fregataa merged commit c952075 into main Mar 16, 2026
30 checks passed
@fregataa fregataa deleted the BA-5035 branch March 16, 2026 06:23
@fregataa fregataa added this to the 26.4 milestone Mar 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp:manager Related to Manager component size:L 100~500 LoC

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants