-
Notifications
You must be signed in to change notification settings - Fork 175
feat(BA-5797): add effective permissions resolver for entities #11236
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| Add an effective permissions resolver in the permission controller service and repository layers that returns all permitted operations a user can perform on given entities by traversing the RBAC scope chain. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| from __future__ import annotations | ||
|
|
||
| from collections.abc import Mapping | ||
| from dataclasses import dataclass, field | ||
| from typing import override | ||
| from uuid import UUID | ||
|
|
||
| from ai.backend.common.data.permission.types import EntityType, OperationType, RBACElementType | ||
| from ai.backend.manager.actions.action import BaseAction, BaseActionResult | ||
| from ai.backend.manager.actions.types import ActionOperationType | ||
|
|
||
|
|
||
| @dataclass | ||
| class ResolveEffectivePermissionsAction(BaseAction): | ||
| """Action to resolve effective permissions per entity for a given user. | ||
|
|
||
| Given a user ID, an element type, and a list of entity IDs, returns the | ||
| set of permitted operations per entity by traversing the scope chain and | ||
| evaluating all role/permission assignments. | ||
| """ | ||
|
|
||
| user_id: UUID | ||
| target_element_type: RBACElementType | ||
| target_entity_ids: list[str] | ||
| permission_entity_type: EntityType | None = None | ||
|
|
||
| @override | ||
| def entity_id(self) -> str | None: | ||
| return str(self.user_id) | ||
|
|
||
| @override | ||
| @classmethod | ||
| def entity_type(cls) -> EntityType: | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is it intentional that entity_id is a user_id even though entity_type is not USER?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We decided to not expand/use entity type enum anymore and this abstract method is also deprecated. it is implemented to avoid type check for now |
||
| return EntityType.PERMISSION | ||
|
|
||
| @override | ||
| @classmethod | ||
| def operation_type(cls) -> ActionOperationType: | ||
| return ActionOperationType.GET | ||
|
|
||
|
|
||
| @dataclass | ||
| class ResolveEffectivePermissionsActionResult(BaseActionResult): | ||
| """Result containing the effective permissions per entity.""" | ||
|
|
||
| permissions: Mapping[str, set[OperationType]] = field(default_factory=dict) | ||
|
|
||
| @override | ||
| def entity_id(self) -> str | None: | ||
| return None | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about init result dict keys with requested entity ids first? Since the current query does not return information for entity IDs that do not match, it seems better to ensure that it returns an empty set for entity IDs that do not match at all.