Skip to content

feat(BA-5380): seed RBAC permissions for vfolder:data and session:app#11457

Open
fregataa wants to merge 8 commits intomainfrom
feat/BA-5380-BA-5383-rbac-data-migration
Open

feat(BA-5380): seed RBAC permissions for vfolder:data and session:app#11457
fregataa wants to merge 8 commits intomainfrom
feat/BA-5380-BA-5383-rbac-data-migration

Conversation

@fregataa
Copy link
Copy Markdown
Member

@fregataa fregataa commented May 1, 2026

Summary

  • Forward-only Alembic migrations that backfill vfolder:data (CRUD) and session:app (read) permissions for owner/admin roles in domain/project/user scopes.
  • Migrates existing vfolder_permissions invitations to per-entity vfolder:data grants using the entity-as-scope pattern (permissions(scope_type='vfolder', scope_id=vfolder_id, ...)); mount perms map ro→{read}, rw→{read,update}, wd→{read,update,hard-delete} (no soft-delete on data).
  • Sub-entity rows in association_scopes_entities are intentionally omitted: the resolver walks parent vfolder/session edges via permission_entity_type, and the existing uq_scope_id_entity_id constraint would conflict with parent edges anyway. Downgrade is a no-op to protect operator-managed grants.

Test plan

  • pants fmt fix lint check on the two new migration files
  • Local DB upgrade: 102 rows seeded (vfolder:data 82 + session:app 20) on a 33-role / 1-invitation dataset
  • Verify entity-as-scope tuples (vfolder, model_deployment scopes) excluded from broad seed — invitee gets exactly mount-perm-mapped ops, no over-grant
  • Downgrade is no-op (data preserved); re-upgrade is idempotent (no duplicate rows via ON CONFLICT DO NOTHING)
  • CI green

Resolves BA-5380
Resolves BA-5383

Copilot AI review requested due to automatic review settings May 1, 2026 11:33
@github-actions github-actions Bot added size:L 100~500 LoC comp:manager Related to Manager component require:db-migration Automatically set when alembic migrations are added or updated labels May 1, 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

Adds forward-only Alembic data migrations to backfill RBAC permissions rows for two sub-entity permission domains (vfolder:data and a session app-related entity type), including mapping legacy vfolder invitation mount permissions into per-vfolder entity-as-scope grants.

Changes:

  • Seed vfolder:data owner operations for non-member roles across domain/project/user scopes.
  • Backfill vfolder_permissions invitation records into permissions(scope_type='vfolder', scope_id=<vfolder_id>, entity_type='vfolder:data', ...) using a mount-permission→operation mapping.
  • Seed a read-only session app-related entity-type permission for non-member roles across domain/project/user scopes.

Reviewed changes

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

File Description
src/ai/backend/manager/models/alembic/versions/6e5a7a62a687_migrate_vfolder_data_to_rbac.py Seeds vfolder:data permissions for org scopes and migrates legacy vfolder invitations to per-vfolder RBAC grants.
src/ai/backend/manager/models/alembic/versions/3632aad9d5d9_migrate_session_app_to_rbac.py Seeds a read-only session app-related entity-type permission for org scopes.

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

fregataa added a commit that referenced this pull request May 1, 2026
@fregataa fregataa requested a review from a team May 1, 2026 12:26
@fregataa fregataa marked this pull request as draft May 1, 2026 13:06
@fregataa fregataa marked this pull request as ready for review May 2, 2026 17:36
fregataa added a commit that referenced this pull request May 2, 2026
@fregataa fregataa force-pushed the feat/BA-5380-BA-5383-rbac-data-migration branch from 1126c18 to ba36f51 Compare May 2, 2026 17:40
seedspirit
seedspirit previously approved these changes May 4, 2026
@seedspirit seedspirit self-requested a review May 4, 2026 07:32

# Constants
MEMBER_ROLE_PATTERN = "%member"
ENTITY_TYPE = "session:app"
Copy link
Copy Markdown
Contributor

@seedspirit seedspirit May 4, 2026

Choose a reason for hiding this comment

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

The entity type enum is defined as SESSION_APP_SERVICE = "session:app_service". Does it matter if there is a mismatch?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Also, vfolder:data does not appear to exist in the EntityType (or anywhere in the codebase).

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

they are added in #11456

@seedspirit seedspirit self-requested a review May 4, 2026 07:34
fregataa added a commit that referenced this pull request May 6, 2026
@fregataa fregataa force-pushed the feat/BA-5380-BA-5383-rbac-data-migration branch from ba36f51 to 70eeb09 Compare May 6, 2026 05:56
fregataa added a commit that referenced this pull request May 6, 2026
@fregataa fregataa force-pushed the feat/BA-5380-BA-5383-rbac-data-migration branch from 70eeb09 to d55509f Compare May 6, 2026 14:50
@fregataa fregataa requested a review from a team May 6, 2026 15:04
fregataa and others added 6 commits May 7, 2026 11:14
Forward-only Alembic migrations that backfill owner/admin permissions for
the new sub-entity types in domain/project/user scopes, and migrate
vfolder_permissions invitations to per-entity `vfolder:data` grants.
Sub-entity scope-entity edges are intentionally omitted — the resolver
walks parent edges via `permission_entity_type`. Downgrade is a no-op.

Resolves BA-5380
Resolves BA-5383
- Remove unused `REF_RELATION_TYPE` constant from the vfolder:data migration.
- Clarify the 11457 news fragment.
The earlier broad scope-wide seed granted vfolder:data and session:app
operations on domain/project/user scopes for non-member roles. The RBAC
resolver's scope-chain walker traverses user → project → domain via the
membership edges in association_scopes_entities, so a project- or
domain-scoped grant on these owner-only sub-entities would let project
admins (or domain admins) reach user-owned vfolders and sessions inside
their scope — violating the owner-only intent.

Replace with per-entity (entity-as-scope) grants:
- user-owned vfolders → owner's system role only
- project-owned vfolders → project's non-member roles only
- vfolder_permissions invitations → invitee's system role with
  mount-permission-mapped ops (already entity-as-scope)
- live sessions → creator's system role + project non-member roles
- dead sessions (TERMINATING/TERMINATED/CANCELLED/ERROR) excluded

These rows match the resolver's self-scope branch only; the walker never
visits them, so no upward leak.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
fregataa and others added 2 commits May 7, 2026 11:14
Repoint the vfolder:data data migration onto the current main head to
resolve divergent alembic heads, and replace the silent skip for unknown
vfolder_permissions.permission values with a warning log so operators
can investigate stray rows.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Rename `session:app` to `session:app_service` in the data migration
seed and changelog to match `EntityType.SESSION_APP_SERVICE` defined in
`common/data/permission/types.py`. Without this, seeded permission rows
would never resolve at runtime.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@fregataa fregataa force-pushed the feat/BA-5380-BA-5383-rbac-data-migration branch from d55509f to ab38733 Compare May 7, 2026 02:31
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 require:db-migration Automatically set when alembic migrations are added or updated size:L 100~500 LoC

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants