Conversation
fregataa
added a commit
that referenced
this pull request
Mar 13, 2026
Contributor
There was a problem hiding this comment.
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/SingleEntityActionProcessorwith 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 |
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>
seedspirit
approved these changes
Mar 16, 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.
Summary
KeypairScopeActionandKeypairSingleEntityActionbase classes that implement required RBAC methodsScopeActionProcessorandSingleEntityActionProcessorwith proper RBAC validatorsChanges
services/auth/actions/base.py):KeypairScopeAction- for create/list operations within a scopeKeypairSingleEntityAction- for get/update/delete/purge operations on single entitiesCreateSSHKeypair,ListSSHKeypairsGetSSHKeypair,UpdateSSHKeypair,DeleteSSHKeypair,PurgeSSHKeypairservices/auth/processors.py):ScopeActionProcessorfor scope actions withvalidators=[validators.rbac.scope]SingleEntityActionProcessorfor single-entity actions withvalidators=[validators.rbac.single_entity]Test plan
pants fmtpassespants fixpassespants lintpassesResolves BA-5035