|
1 | | -from typing import override |
| 1 | +from typing import cast, override |
2 | 2 |
|
3 | 3 | from ai.backend.manager.actions.monitors.monitor import ActionMonitor |
4 | 4 | from ai.backend.manager.actions.processor import ActionProcessor |
5 | 5 | from ai.backend.manager.actions.types import AbstractProcessorPackage, ActionSpec |
| 6 | +from ai.backend.manager.actions.validator.base import ActionValidator |
6 | 7 | from ai.backend.manager.actions.validators import ActionValidators |
7 | 8 | from ai.backend.manager.services.session.actions.check_and_transit_status import ( |
8 | 9 | CheckAndTransitStatusAction, |
@@ -172,42 +173,88 @@ def __init__( |
172 | 173 | action_monitors: list[ActionMonitor], |
173 | 174 | validators: ActionValidators, |
174 | 175 | ) -> None: |
| 176 | + scope_validator = validators.rbac.scope |
| 177 | + single_entity_validator = validators.rbac.single_entity |
| 178 | + |
| 179 | + # Actions without RBAC validation (internal/legacy) |
175 | 180 | self.commit_session = ActionProcessor(service.commit_session, action_monitors) |
176 | 181 | self.complete = ActionProcessor(service.complete, action_monitors) |
177 | 182 | self.convert_session_to_image = ActionProcessor( |
178 | 183 | service.convert_session_to_image, action_monitors |
179 | 184 | ) |
180 | | - self.create_cluster = ActionProcessor(service.create_cluster, action_monitors) |
181 | | - self.create_from_params = ActionProcessor(service.create_from_params, action_monitors) |
182 | | - self.create_from_template = ActionProcessor(service.create_from_template, action_monitors) |
183 | | - self.destroy_session = ActionProcessor(service.destroy_session, action_monitors) |
184 | 185 | self.download_file = ActionProcessor(service.download_file, action_monitors) |
185 | 186 | self.download_files = ActionProcessor(service.download_files, action_monitors) |
186 | | - self.execute_session = ActionProcessor(service.execute_session, action_monitors) |
187 | 187 | self.get_abusing_report = ActionProcessor(service.get_abusing_report, action_monitors) |
188 | 188 | self.get_commit_status = ActionProcessor(service.get_commit_status, action_monitors) |
189 | 189 | self.get_container_logs = ActionProcessor(service.get_container_logs, action_monitors) |
190 | 190 | self.get_dependency_graph = ActionProcessor(service.get_dependency_graph, action_monitors) |
191 | 191 | self.get_direct_access_info = ActionProcessor( |
192 | 192 | service.get_direct_access_info, action_monitors |
193 | 193 | ) |
194 | | - self.get_session_info = ActionProcessor(service.get_session_info, action_monitors) |
195 | 194 | self.get_status_history = ActionProcessor(service.get_status_history, action_monitors) |
196 | 195 | self.interrupt = ActionProcessor(service.interrupt, action_monitors) |
197 | 196 | self.list_files = ActionProcessor(service.list_files, action_monitors) |
198 | | - self.match_sessions = ActionProcessor(service.match_sessions, action_monitors) |
199 | 197 | self.rename_session = ActionProcessor(service.rename_session, action_monitors) |
200 | 198 | self.restart_session = ActionProcessor(service.restart_session, action_monitors) |
201 | | - self.search_kernels = ActionProcessor(service.search_kernels, action_monitors) |
202 | | - self.search_sessions = ActionProcessor(service.search, action_monitors) |
203 | 199 | self.shutdown_service = ActionProcessor(service.shutdown_service, action_monitors) |
204 | 200 | self.start_service = ActionProcessor(service.start_service, action_monitors) |
205 | 201 | self.upload_files = ActionProcessor(service.upload_files, action_monitors) |
206 | | - self.modify_session = ActionProcessor(service.modify_session, action_monitors) |
207 | 202 | self.check_and_transit_status = ActionProcessor( |
208 | 203 | service.check_and_transit_status, action_monitors |
209 | 204 | ) |
210 | 205 |
|
| 206 | + # Scope actions with RBAC validation |
| 207 | + self.create_cluster = ActionProcessor( |
| 208 | + service.create_cluster, |
| 209 | + action_monitors, |
| 210 | + validators=[cast(ActionValidator, scope_validator)], |
| 211 | + ) |
| 212 | + self.create_from_params = ActionProcessor( |
| 213 | + service.create_from_params, |
| 214 | + action_monitors, |
| 215 | + validators=[cast(ActionValidator, scope_validator)], |
| 216 | + ) |
| 217 | + self.create_from_template = ActionProcessor( |
| 218 | + service.create_from_template, |
| 219 | + action_monitors, |
| 220 | + validators=[cast(ActionValidator, scope_validator)], |
| 221 | + ) |
| 222 | + self.match_sessions = ActionProcessor( |
| 223 | + service.match_sessions, |
| 224 | + action_monitors, |
| 225 | + validators=[cast(ActionValidator, scope_validator)], |
| 226 | + ) |
| 227 | + self.search_kernels = ActionProcessor( |
| 228 | + service.search_kernels, |
| 229 | + action_monitors, |
| 230 | + validators=[cast(ActionValidator, scope_validator)], |
| 231 | + ) |
| 232 | + self.search_sessions = ActionProcessor( |
| 233 | + service.search, action_monitors, validators=[cast(ActionValidator, scope_validator)] |
| 234 | + ) |
| 235 | + |
| 236 | + # Single entity actions with RBAC validation |
| 237 | + self.destroy_session = ActionProcessor( |
| 238 | + service.destroy_session, |
| 239 | + action_monitors, |
| 240 | + validators=[cast(ActionValidator, single_entity_validator)], |
| 241 | + ) |
| 242 | + self.execute_session = ActionProcessor( |
| 243 | + service.execute_session, |
| 244 | + action_monitors, |
| 245 | + validators=[cast(ActionValidator, single_entity_validator)], |
| 246 | + ) |
| 247 | + self.get_session_info = ActionProcessor( |
| 248 | + service.get_session_info, |
| 249 | + action_monitors, |
| 250 | + validators=[cast(ActionValidator, single_entity_validator)], |
| 251 | + ) |
| 252 | + self.modify_session = ActionProcessor( |
| 253 | + service.modify_session, |
| 254 | + action_monitors, |
| 255 | + validators=[cast(ActionValidator, single_entity_validator)], |
| 256 | + ) |
| 257 | + |
211 | 258 | @override |
212 | 259 | def supported_actions(self) -> list[ActionSpec]: |
213 | 260 | return [ |
|
0 commit comments