Skip to content

feat(BA-5777): add batch RBAC filtering infrastructure#11191

Open
fregataa wants to merge 1 commit intomainfrom
feature/BA-5777-batch-rbac-filtering-infra
Open

feat(BA-5777): add batch RBAC filtering infrastructure#11191
fregataa wants to merge 1 commit intomainfrom
feature/BA-5777-batch-rbac-filtering-infra

Conversation

@fregataa
Copy link
Copy Markdown
Member

@fregataa fregataa commented Apr 20, 2026

Summary

  • BaseBatchAction becomes a generic @dataclass with a mutable entity_ids: list[str] field and a typed_entity_ids() -> list[T] abstract method so services still see native ID types (e.g. SessionId) while the processor can narrow the batch in place.
  • BatchActionValidator gains a name() classmethod and returns BatchValidationResult (allowed IDs + DeniedEntity(entity_id, deny_reason) list). BatchActionProcessor wraps every validator call in a _validator_scope async context manager, aggregates results into BatchProcessResult.validator_decisions, and filters current_action.entity_ids directly — laying the wiring for the follow-up that will call check_batch_permission_with_scope_chain() (BA-5776).
  • Delete the orphan check_and_transit_status_multi service path (its CheckAndTransitStatusBatchAction/tests had no production wiring) and the 10 unused intermediate *BatchAction base classes.

Test plan

  • pants fmt :: / fix :: / lint --changed-since=origin/main
  • pants check --changed-since=HEAD --changed-dependents=transitive (1849 files)
  • pants test tests/unit/manager/actions/:: tests/unit/manager/services/session/:: tests/unit/manager/services/artifact_revision/::
  • CI green

Resolves BA-5777

🤖 Generated with Claude Code

Copilot AI review requested due to automatic review settings April 20, 2026 12:25
@github-actions github-actions bot added size:L 100~500 LoC comp:manager Related to Manager component labels Apr 20, 2026
fregataa added a commit that referenced this pull request Apr 20, 2026
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
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

This PR introduces infrastructure for per-entity RBAC validation on batch actions (including validator tracing and in-place batch narrowing), and removes an unused/orphaned batch session status-transition path plus several unused intermediate *BatchAction base classes.

Changes:

  • Refactors batch action plumbing: BaseBatchAction becomes a generic dataclass with mutable entity_ids: list[str] plus typed_entity_ids(), and BatchActionValidator now returns a structured BatchValidationResult and provides a stable name().
  • Extends BatchActionProcessor to wrap validator execution in an async scope, record per-validator decisions, and filter current_action.entity_ids based on validator outcomes.
  • Deletes the unused check_and_transit_status_multi batch path and removes now-unused service-level *BatchAction base classes (and associated tests/imports).

Reviewed changes

Copilot reviewed 18 out of 18 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
tests/unit/manager/services/session/test_session_lifecycle_service.py Removes orphaned tests for the deleted check_and_transit_status_multi path.
src/ai/backend/manager/services/session/service.py Deletes the unused check_and_transit_status_multi() service method and its imports.
src/ai/backend/manager/services/session/actions/check_and_transit_status.py Removes now-unused batch action/result types for check/transit status.
src/ai/backend/manager/services/session/base.py Removes SessionBatchAction base class (batch infra moves to central action layer).
src/ai/backend/manager/services/user_resource_policy/actions/base.py Removes unused UserResourcePolicyBatchAction.
src/ai/backend/manager/services/resource_preset/actions/base.py Removes unused ResourcePresetBatchAction.
src/ai/backend/manager/services/project_resource_policy/actions/base.py Removes unused ProjectResourcePolicyBatchAction.
src/ai/backend/manager/services/keypair_resource_policy/actions/base.py Removes unused KeypairResourcePolicyBatchAction.
src/ai/backend/manager/services/image/actions/base.py Removes unused ImageBatchAction.
src/ai/backend/manager/services/container_registry/actions/base.py Removes unused ContainerRegistryBatchAction.
src/ai/backend/manager/services/artifact_revision/actions/base.py Removes unused ArtifactRevisionBatchAction.
src/ai/backend/manager/services/artifact_registry/actions/base.py Removes unused ArtifactBatchRegistryAction.
src/ai/backend/manager/services/artifact/actions/base.py Removes unused ArtifactBatchAction.
src/ai/backend/manager/actions/validator/batch.py Adds DeniedEntity + BatchValidationResult, and updates validator interface to return structured per-entity outcomes.
src/ai/backend/manager/actions/validators/rbac/batch.py Implements the new batch validator interface and adds a stable validator name (rbac).
src/ai/backend/manager/actions/processor/batch.py Adds validator scoping + decision tracing and filters batch IDs based on validator results; returns BatchProcessResult.
src/ai/backend/manager/actions/action/batch.py Refactors BaseBatchAction into a generic dataclass with mutable entity_ids and typed_entity_ids().

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

Comment thread src/ai/backend/manager/actions/processor/batch.py
Comment thread src/ai/backend/manager/actions/processor/batch.py Outdated
@fregataa fregataa marked this pull request as draft April 20, 2026 12:45
- BaseBatchAction is a generic @DataClass carrying only entity_ids: list[str]
  plus an abstract typed_entity_ids() returning list[T]; user context and
  per-operation data are deliberately excluded so the processor can rebuild
  a narrowed action via type(action)(entity_ids=...) without a factory hook
- BatchActionValidator exposes name() + validate() returning
  BatchValidationResult(allowed_entity_ids, denied_entities:
  list[DeniedEntity(entity_id, deny_reason)])
- BatchActionProcessor runs each validator inside an _validator_scope async
  context manager (one place for timing/audit), appends a
  BatchValidatorDecision(validator_name, results) trace, and returns
  BatchProcessResult(result, validator_decisions) for partial-success
  responses
- Remove orphan check_and_transit_status_multi path, CheckAndTransitStatus
  batch action/result and its tests, and 10 unused intermediate batch base
  classes (Session/Image/ContainerRegistry/*ResourcePolicy/ResourcePreset/
  Artifact/ArtifactRevision/ArtifactRegistry)
- Add unit tests for BatchActionProcessor covering no-validator pass-through,
  partial/full deny, multi-validator ordering, and original-action immutability
- News fragment 11191.feature.md

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@fregataa fregataa force-pushed the feature/BA-5777-batch-rbac-filtering-infra branch from 654bb5f to 32a0fa8 Compare April 20, 2026 13:28
@github-actions github-actions bot added size:XL 500~ LoC and removed size:L 100~500 LoC labels Apr 20, 2026
@fregataa fregataa requested a review from a team April 20, 2026 13:37
@fregataa fregataa marked this pull request as ready for review April 20, 2026 13:37
@fregataa fregataa added this to the 26.5 milestone Apr 20, 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:XL 500~ LoC

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants