Skip to content

fix(rbac): backfill admin.overview and servers.use permissions to viewer roles - #3390

Merged
crivetimihai merged 16 commits into
mainfrom
issue_3329_RBAC_privilage
Mar 18, 2026
Merged

crivetimihai merged 16 commits into
mainfrom
issue_3329_RBAC_privilage

Conversation

@rakdutta

@rakdutta rakdutta commented Mar 2, 2026 •

Copy link
Copy Markdown
Collaborator

closes issue #3329

Description

Ensures viewer, platform_viewer, developer, and team_admin roles have the correct permission set on both new and existing deployments.

Problem

The admin.overview and servers.use permissions were missing from certain roles in existing databases. These permissions existed in the bootstrap definition but were never backfilled via a migration for users who had already run prior migrations.

Solution

  • Added Alembic migration abf8ac3b6008 to backfill the missing permissions into existing role records.
  • Updated bootstrap_db.py default role definitions so new deployments receive the correct permissions from first boot.

Changes

mcpgateway/alembic/versions/abf8ac3b6008_add_admin_overview_and_tools_execute_to_.py (new)

Data migration that adds missing permissions to existing role records:

Role Permissions Added
viewer admin.overview, servers.use
platform_viewer admin.overview, servers.use
developer admin.overview
team_admin admin.overview
  • Idempotent: skips roles not found and skips permissions already present
  • Supports SQLite (plain JSON) and PostgreSQL (CAST … AS JSONB)
  • Symmetric downgrade() removes the added permissions
  • Guards against missing roles table (fresh DBs handled by bootstrap_db.py)

mcpgateway/bootstrap_db.py

Updated default role definitions in bootstrap_default_roles():

  • team_admin: added admin.overview
  • developer: added admin.overview
  • viewer: added admin.overview, servers.use
  • platform_viewer: added admin.overview, servers.use

docs/docs/manage/rbac.md

Updated permission tables and role listings to reflect the new permissions.

tests/unit/mcpgateway/db/test_rbac_permission_backfill_migration.py (new)

Tests for the migration covering module structure, upgrade/downgrade logic, idempotency, edge cases, and round-trip verification.

tests/unit/mcpgateway/services/test_rbac_permission_matrix.py

Updated permission fixtures to match the new role definitions.


Testing

  • Run alembic upgrade head on an existing SQLite or PostgreSQL database and verify the four roles have the new permissions.
  • Run alembic downgrade -1 and verify the permissions are removed.
  • Bootstrap a fresh database and confirm the roles are created with the correct permissions from bootstrap_db.py.

@rakdutta
rakdutta marked this pull request as ready for review March 2, 2026 12:59
@rakdutta
rakdutta requested a review from crivetimihai as a code owner March 2, 2026 12:59
@rakdutta rakdutta added the rbac Role-based Access Control label Mar 2, 2026
@madhav165
madhav165 force-pushed the issue_3329_RBAC_privilage branch from 27ede39 to 7e3dd7c Compare March 2, 2026 15:51
@madhav165

Copy link
Copy Markdown
Contributor

Minor: the revision ID aa1b2c3d4e5f appears hand-crafted. Consider regenerating it via make db-migrate to get a proper Alembic-generated ID — just delete the current file, re-run make db-migrate, and paste the migration body into the new file.

madhav165
madhav165 previously approved these changes Mar 2, 2026
@rakdutta

rakdutta commented Mar 2, 2026

Copy link
Copy Markdown
Collaborator Author

@madhav165 : Regenerated the alembic id based on review comments

crivetimihai
crivetimihai previously approved these changes Mar 3, 2026

@crivetimihai crivetimihai left a comment

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.

Review: APPROVED

Rebased onto main (clean, no conflicts), squashed 5 commits into a single conventional commit preserving original author.

Changes Reviewed

Migration (abf8ac3b6008)

  • Migration chain verified: down_revision = "d9e0f1a2b3c4" is correct (single head confirmed via alembic heads)
  • Logic is correct: idempotent add/remove, PostgreSQL JSONB CAST + SQLite plain JSON branching
  • Consistent with established codebase patterns (9f5d93ced2b3, b2d9c6e4f1a7, a31c6ffc2239)
  • print() is the correct convention (412 uses across 44 migration files; only 1 outlier uses logging)
  • Symmetric downgrade properly reverses the upgrade

Bootstrap (bootstrap_db.py)

  • Additions match the migration backfill exactly
  • Subset hierarchy preserved: viewer < developer < team_admin

Security

  • admin.overview is enforced at admin.py:1557 with allow_admin_bypass=False — all roles need it explicitly
  • tools.execute is enforced on tool invocation endpoints (main.py, streamablehttp_transport.py)
  • No write/create/update/delete permissions granted to viewer roles — only read + execute access
  • tools.execute for viewers is appropriate: MCP protocol requires tool invocation for basic functionality

Fixes Applied During Review

  • Removed emoji from print statement (consistency with reference migrations)
  • Added # pylint: disable=no-member (matches d9e0f1a2b3c4 pattern)
  • Updated test_rbac_permission_matrix.py — synced permission constants with new bootstrap definitions (280 tests pass)
  • Added test_rbac_permission_backfill_migration.py — 33 tests covering module structure, _load_permissions edge cases, upgrade/downgrade logic, idempotency, edge cases

Test Results

  • 33/33 migration tests pass
  • 280/280 permission matrix tests pass

@rakdutta

rakdutta commented Mar 3, 2026 •

Copy link
Copy Markdown
Collaborator Author

start working on issue #3415 to include servers.user permission for team_admin and developer, viewer and plat_viewer role in alembic script.

@rakdutta
rakdutta force-pushed the issue_3329_RBAC_privilage branch from 22824e8 to 3448628 Compare March 3, 2026 09:37
@rakdutta

rakdutta commented Mar 3, 2026 •

Copy link
Copy Markdown
Collaborator Author

Added servers.use permission to viewer, platform_viewer, developer, and team_admin roles. Updated the Alembic script accordingly.
update bootstrap_db.py
Issue #3415 will be addressed in a separate PR.

@rakdutta
rakdutta force-pushed the issue_3329_RBAC_privilage branch from e3e6036 to bc95080 Compare March 3, 2026 12:19
@crivetimihai

Copy link
Copy Markdown
Member

Thanks, please leave this with me now, I've started the code review.

@crivetimihai
crivetimihai force-pushed the issue_3329_RBAC_privilage branch from 5f9a64c to eefe7cc Compare March 3, 2026 12:52

@crivetimihai crivetimihai left a comment

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.

Review: Approved with fixes applied

Reviewed the full diff, rebased onto latest main (b4d8770), and applied the following fixes:

Issues found and fixed

  1. Downgrade regression (high): The migration included servers.use in ROLE_PERMISSION_ADDITIONS for developer and team_admin, but those roles already have servers.use in their baseline definitions. This meant downgrade() would strip a pre-existing permission, breaking transport access. Fixed by removing servers.use from developer/team_admin entries — upgrade is still idempotent (skips if present), but downgrade no longer destroys pre-existing state.

  2. Bootstrap/migration inconsistency: servers.use was being backfilled by the migration for viewer and platform_viewer but was missing from bootstrap_db.py. New deployments would lack it while migrated deployments would have it. Fixed by adding servers.use to both roles in bootstrap.

  3. E2E test alignment: The new RBAC transport e2e tests (merged in #3424) expected non-admin users to be denied tools.execute on the default /mcp endpoint. However, all non-admin users auto-receive platform_viewer (global scope), which now includes tools.execute. Fixed by updating 4 e2e tests to expect success instead of denial, matching the intent of #3329.

  4. Test coverage gaps: Migration test fixtures used unrealistic baselines (developer/team_admin missing servers.use), masking the downgrade regression. Fixed with realistic fixtures and a new round-trip restoration test.

  5. Documentation drift: Updated RBAC docs (role tables, permission categories, available permissions, info boxes) and role descriptions to reflect the new viewer/platform_viewer capabilities.

  6. Unrelated changes: Reverted uv.lock dependency bumps (cookiecutter, fastapi, filelock) that were unrelated to the RBAC fix.

Verification

  • 323 unit tests passing
  • Migration/bootstrap/test constants/docs all cross-checked for consistency
  • Downgrade safety verified: no pre-existing permissions in removal lists

Closes #3329

crivetimihai
crivetimihai previously approved these changes Mar 3, 2026

@crivetimihai crivetimihai left a comment

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.

Review: Approved with fixes applied

Reviewed the full diff, rebased onto latest main, and applied the following fixes:

Issues found and fixed

  1. Downgrade regression (high): The migration included servers.use in ROLE_PERMISSION_ADDITIONS for developer and team_admin, but those roles already have servers.use in their baseline definitions. This meant downgrade() would strip a pre-existing permission, breaking transport access. Fixed by removing servers.use from developer/team_admin entries — upgrade is still idempotent (skips if present), but downgrade no longer destroys pre-existing state.

  2. Bootstrap/migration inconsistency: servers.use was being backfilled by the migration for viewer and platform_viewer but was missing from bootstrap_db.py. New deployments would lack it while migrated deployments would have it. Fixed by adding servers.use to both roles in bootstrap.

  3. E2E test alignment: The new RBAC transport e2e tests (merged in #3424) expected non-admin users to be denied tools.execute on the default /mcp endpoint. However, all non-admin users auto-receive platform_viewer (global scope), which now includes tools.execute. Fixed by updating 4 e2e tests to expect success instead of denial, matching the intent of #3329.

  4. Test coverage gaps: Migration test fixtures used unrealistic baselines (developer/team_admin missing servers.use), masking the downgrade regression. Fixed with realistic fixtures and a new round-trip restoration test.

  5. Documentation drift: Updated RBAC docs (role tables, permission categories, available permissions, info boxes) and role descriptions to reflect the new viewer/platform_viewer capabilities.

  6. Unrelated changes: Reverted uv.lock dependency bumps (cookiecutter, fastapi, filelock) that were unrelated to the RBAC fix.

Verification

  • 323 unit tests passing
  • Migration/bootstrap/test constants/docs all cross-checked for consistency
  • Downgrade safety verified: no pre-existing permissions in removal lists

Closes #3329

@crivetimihai

Copy link
Copy Markdown
Member

Follow-up: Viewer role permissions model — read-only vs read+execute

This PR fixes #3329 correctly, but raises a broader design question worth tracking.

The concern

platform_viewer is auto-assigned to every non-admin user on creation (via default_user_role in config). By adding tools.execute and servers.use to this role:

  1. All authenticated non-admin users can now execute tools on the default /mcp endpoint (global scope)
  2. There is no built-in read-only role — the only way to restrict a user to read-only is to manually revoke their auto-assigned platform_viewer and assign a custom role
  3. The viewer role description was historically "Read-only access to resources and admin UI", but now includes execute capabilities

Why this matters

Tool execution is a mutation operation — it runs side effects on external systems (MCP servers). Granting this to all users by default may not be appropriate for all deployments, particularly those with compliance or least-privilege requirements.

Options to consider

  1. Keep current model (this PR): All authenticated users can test tools. Simple, fixes [BUG][RBAC]: Non-admin users cannot access Overview page and have inconsistent Test/View privileges #3329. No built-in read-only role.
  2. Split viewer into viewer + tester: Keep viewer/platform_viewer read-only, introduce tester/platform_tester roles with execute. Clear separation, more roles to manage.
  3. Team-scoped tool execution on admin UI: Remove tools.execute from platform_viewer (global), keep it on team-scoped viewer. Make admin UI "Test" button use team-scoped MCP endpoint. Most precise, larger implementation effort.
  4. Make DEFAULT_USER_ROLE configurable per deployment: Let admins choose their default role. Flexible, doesn't solve the single-role ambiguity.

Decision needed

  • Should viewer be conceptually read-only or read+test?
  • Should platform_viewer (auto-assigned globally) include tools.execute?

If the current model is intentional, no action needed. If this warrants further discussion, consider opening a follow-up issue.

@madhav165 madhav165 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Hi @rakdutta , looks like lots of doc strings still mention about test permissions and some tests have tools.execute too. Let's limit this PR to servers.use as discussed.

@crivetimihai

Copy link
Copy Markdown
Member

Review: Consistency fixes for tools.execute removal

The last commit (f11e740 "remove tools.execute") removed tools.execute from the migration and bootstrap_db.py but left stale references in 4 other files. Pushed 928fe1e to complete the cleanup:

What was fixed

File Issue Fix
Migration docstring "admin.overview,, double commas, extra spaces from hasty find/delete Cleaned up formatting
bootstrap_db.py viewer/platform_viewer description said "Read and test access" — misleading without tools.execute Reverted to "Read-only access"
docs/rbac.md Permission tables still listed tools.execute for viewer/platform_viewer; descriptions said "read and test" Removed tools.execute, restored "read-only"
test_rbac_permission_matrix.py VIEWER_PERMISSIONS and PLATFORM_VIEWER_PERMISSIONS included tools.execute Removed
test_rbac_permission_backfill_migration.py Hardcoded ["admin.overview", "tools.execute"] in individual tests instead of using the actual ROLE_PERMISSION_ADDITIONS values; module docstring stale Replaced with ROLE_PERMISSION_ADDITIONS["viewer"] references throughout
test_mcp_rbac_transport.py (e2e) Tests changed from deny→success with docstrings claiming "platform_viewer grants global tools.execute" — but platform_viewer no longer has it Restored original deny assertions from main

Tests added

  • test_upgrade_via_entry_point — calls upgrade() with mocked alembic.op.get_bind against a populated DB, verifies all permissions applied and pre-existing permissions preserved
  • test_downgrade_via_entry_point — full round-trip via public entry points, verifies exact restoration of original state

Verification

  • 43/43 migration backfill tests pass
  • 282/282 permission matrix tests pass
  • Single alembic head confirmed (abf8ac3b6008)

Open design question

Per the earlier discussion: viewer roles are now read-only + admin.overview + servers.use (transport access), but do NOT have tools.execute. This means the original issue #3329 ("Test on tools fails") is only partially addressed — the Overview page now loads, but tool testing for non-admin users still requires a follow-up (either adding tools.execute to viewer roles, or implementing team-scoped tool execution in the admin UI).

@rakdutta
rakdutta force-pushed the issue_3329_RBAC_privilage branch from 2c2d4fd to e677db3 Compare March 9, 2026 05:04
@rakdutta rakdutta added the ica ICA related issues label Mar 16, 2026
rakdutta and others added 15 commits March 18, 2026 13:28
…iewer roles

Add Alembic migration to backfill missing permissions into existing role
records and update bootstrap_db.py so new deployments receive the correct
permissions from first boot.

Roles updated:
- viewer: admin.overview, tools.execute
- platform_viewer: admin.overview, tools.execute
- developer: admin.overview
- team_admin: admin.overview

The migration is idempotent, supports both PostgreSQL (JSONB) and SQLite,
and includes a symmetric downgrade.

Closes #3329

Signed-off-by: Rakhi Dutta <[email protected]>
Signed-off-by: Mihai Criveti <[email protected]>
Signed-off-by: Mihai Criveti <[email protected]>
Signed-off-by: Rakhi Dutta <[email protected]>
Signed-off-by: Rakhi Dutta <[email protected]>
…st coverage

Add servers.use permission to viewer and platform_viewer role definitions
in bootstrap_db.py to match what the Alembic migration backfills. Without
this, new deployments would lack servers.use for viewer roles while migrated
deployments would have it, causing inconsistent tool-testing behavior.

Also adds migration tests covering servers.use addition/removal for all
roles and reverts unrelated uv.lock dependency bumps.

Signed-off-by: Mihai Criveti <[email protected]>
… roles

Update viewer and platform_viewer role descriptions from "Read-only" to
"Read and test" to reflect the addition of tools.execute and servers.use
permissions. Update RBAC documentation to include admin.overview,
tools.execute, and servers.use in the built-in roles table, permission
categories, and available permissions reference.

Signed-off-by: Mihai Criveti <[email protected]>
The module docstring and upgrade/downgrade docstrings only mentioned
admin.overview and tools.execute, but ROLE_PERMISSION_ADDITIONS also
includes servers.use for all four roles. Align documentation with code.

Signed-off-by: Mihai Criveti <[email protected]>
Fix migration downgrade regression: remove servers.use from developer and
team_admin entries in ROLE_PERMISSION_ADDITIONS since those roles already
have it in their baseline definitions. Without this, a downgrade would
strip a pre-existing permission, breaking transport access.

Update migration test fixtures with realistic baselines (developer and
team_admin include servers.use) and add a round-trip test that verifies
upgrade->downgrade restores exact original permissions for all roles.

Update e2e RBAC tests: since all non-admin users auto-receive
platform_viewer (global) which now includes tools.execute, the tests
that expected denial on the default /mcp endpoint now correctly expect
success. This aligns with the intent of issue #3329.

Fix remaining stale "read-only" text in rbac.md migration info box
for platform_viewer.

Signed-off-by: Mihai Criveti <[email protected]>
Signed-off-by: Rakhi Dutta <[email protected]>
…ency

The previous commit removed tools.execute from the migration and
bootstrap_db.py but left it in docs, test constants, and e2e tests.
This commit completes the cleanup:

- Fix migration docstring formatting artifacts (double commas, extra spaces)
- Revert viewer/platform_viewer description to "Read-only access"
- Remove tools.execute from rbac.md viewer/platform_viewer permission tables
- Remove tools.execute from test_rbac_permission_matrix.py constants
- Replace hardcoded stale permission lists in migration backfill tests
  with ROLE_PERMISSION_ADDITIONS references
- Restore original e2e deny assertions for tool execution (non-admin
  users lack global tools.execute)
- Add integration tests for upgrade()/downgrade() via public entry points

Signed-off-by: Mihai Criveti <[email protected]>
Signed-off-by: Rakhi Dutta <[email protected]>
Signed-off-by: Rakhi Dutta <[email protected]>
Signed-off-by: Rakhi Dutta <[email protected]>
Point migration abf8ac3b6008 down_revision from e1f2a3b4c5d6 to
64acf94cb7f2 (the actual current Alembic head on main) to eliminate
the multiple-heads condition that would break alembic upgrade.

Update the corresponding test constant to match.

Signed-off-by: Mihai Criveti <[email protected]>
@crivetimihai
crivetimihai force-pushed the issue_3329_RBAC_privilage branch from 7423a3f to 78a8212 Compare March 18, 2026 14:30
crivetimihai
crivetimihai previously approved these changes Mar 18, 2026

@crivetimihai crivetimihai left a comment

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.

Review: fix(rbac): backfill admin.overview and servers.use permissions to viewer roles

Rebased & Fixed

  • Rebased onto current main (3c5375e), resolved 3 merge conflicts (uv.lock x2, e2e tests).
  • Fixed critical issue: migration down_revision pointed to e1f2a3b4c5d6 which created multiple Alembic heads. Updated to 64acf94cb7f2 (actual current head on main). Without this fix, alembic upgrade head would fail on any deployment.

Code Review

Migration (abf8ac3b6008) — Correct and well-structured:

  • Idempotent: skips if permissions already present, skips if roles table missing
  • Handles both SQLite (plain JSON) and PostgreSQL (CAST AS JSONB)
  • Symmetric downgrade removes only what was added
  • Downgrade is safe for developer/team_admin: their pre-existing servers.use is preserved because it's not in their ROLE_PERMISSION_ADDITIONS entry

Bootstrap ↔ Migration consistency — Verified exact match:

Role Migration adds Bootstrap now includes
viewer admin.overview, servers.use ✅ both present
platform_viewer admin.overview, servers.use ✅ both present
developer admin.overview ✅ present (already had servers.use)
team_admin admin.overview ✅ present (already had servers.use)

New and migrated deployments will have identical permission sets.

Security — No privilege escalation:

  • admin.overview is read-only (dashboard visibility via token scoping middleware)
  • servers.use enables MCP transport access (SSE/WS/Streamable HTTP) but does not grant tools.execute
  • Viewers still cannot execute tools — e2e tests still verify denial on the default global endpoint

Test coverage — 98% on migration file (43 tests), 282 permission matrix tests pass. Only uncovered line is the PostgreSQL CAST branch (expected with SQLite test DB).

Minor notes (non-blocking):

  • E2e test assertions are slightly weaker after removing _assert_access_denied_tool_call helper (inline checks don't verify "access denied" message text for all roles). Acceptable for e2e where error format varies.
  • test_main.py patches for a2a_service=None are unrelated but fix pre-existing test failures. Harmless.

All 325 unit tests pass. Single Alembic head confirmed.

Restore _assert_access_denied_tool_call() in the e2e test — the
replacement inline assertions were broken (checked result.isError
but the actual response uses the error key with JSON-RPC code -32003)
and weaker (did not verify "access denied" message or error code).

Add a migration test documenting the known downgrade limitation: if a
role already had a backfilled permission before the migration ran,
downgrade() will remove it. This is an accepted trade-off for a simple
data migration targeting system-bootstrapped roles.

Signed-off-by: Mihai Criveti <[email protected]>

@crivetimihai crivetimihai left a comment •

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.

Updated review after addressing feedback:

  • Restored _assert_access_denied_tool_call() helper in e2e tests — the inline replacements were broken (checked result.isError but actual response uses error key with JSON-RPC code -32003). E2e file now has zero diff vs main.
  • Added test_downgrade_strips_pre_existing_permissions documenting the known limitation: downgrade is not provenance-aware and will remove listed permissions even if they pre-existed. Accepted trade-off for a migration targeting system-bootstrapped roles with known baselines.
  • admin.overview for team-scoped roles: real gap (template omits team_id), but pre-existing in main — not introduced by this PR. platform_viewer (global) benefits immediately.

All 332 unit tests pass. Single Alembic head confirmed.

@crivetimihai
crivetimihai merged commit 36204a4 into main Mar 18, 2026
40 checks passed
@crivetimihai
crivetimihai deleted the issue_3329_RBAC_privilage branch March 18, 2026 16:08
msureshkumar88 pushed a commit that referenced this pull request May 13, 2026
…wer roles (#3390)

* fix(rbac): backfill admin.overview and tools.execute permissions to viewer roles

Add Alembic migration to backfill missing permissions into existing role
records and update bootstrap_db.py so new deployments receive the correct
permissions from first boot.

Roles updated:
- viewer: admin.overview, tools.execute
- platform_viewer: admin.overview, tools.execute
- developer: admin.overview
- team_admin: admin.overview

The migration is idempotent, supports both PostgreSQL (JSONB) and SQLite,
and includes a symmetric downgrade.

Closes #3329

Signed-off-by: Rakhi Dutta <[email protected]>
Signed-off-by: Mihai Criveti <[email protected]>

* lint

Signed-off-by: Mihai Criveti <[email protected]>

* alembic

Signed-off-by: Rakhi Dutta <[email protected]>

* test case fix

Signed-off-by: Rakhi Dutta <[email protected]>

* fix(rbac): add missing servers.use to viewer bootstrap and improve test coverage

Add servers.use permission to viewer and platform_viewer role definitions
in bootstrap_db.py to match what the Alembic migration backfills. Without
this, new deployments would lack servers.use for viewer roles while migrated
deployments would have it, causing inconsistent tool-testing behavior.

Also adds migration tests covering servers.use addition/removal for all
roles and reverts unrelated uv.lock dependency bumps.

Signed-off-by: Mihai Criveti <[email protected]>

* docs(rbac): update role descriptions and permission tables for viewer roles

Update viewer and platform_viewer role descriptions from "Read-only" to
"Read and test" to reflect the addition of tools.execute and servers.use
permissions. Update RBAC documentation to include admin.overview,
tools.execute, and servers.use in the built-in roles table, permission
categories, and available permissions reference.

Signed-off-by: Mihai Criveti <[email protected]>

* fix(rbac): correct migration docstrings to include servers.use

The module docstring and upgrade/downgrade docstrings only mentioned
admin.overview and tools.execute, but ROLE_PERMISSION_ADDITIONS also
includes servers.use for all four roles. Align documentation with code.

Signed-off-by: Mihai Criveti <[email protected]>

* fix(rbac): safe downgrade, realistic test fixtures, e2e test alignment

Fix migration downgrade regression: remove servers.use from developer and
team_admin entries in ROLE_PERMISSION_ADDITIONS since those roles already
have it in their baseline definitions. Without this, a downgrade would
strip a pre-existing permission, breaking transport access.

Update migration test fixtures with realistic baselines (developer and
team_admin include servers.use) and add a round-trip test that verifies
upgrade->downgrade restores exact original permissions for all roles.

Update e2e RBAC tests: since all non-admin users auto-receive
platform_viewer (global) which now includes tools.execute, the tests
that expected denial on the default /mcp endpoint now correctly expect
success. This aligns with the intent of issue #3329.

Fix remaining stale "read-only" text in rbac.md migration info box
for platform_viewer.

Signed-off-by: Mihai Criveti <[email protected]>

* remove tools.execute

Signed-off-by: Rakhi Dutta <[email protected]>

* fix(rbac): remove stale tools.execute references and fix test consistency

The previous commit removed tools.execute from the migration and
bootstrap_db.py but left it in docs, test constants, and e2e tests.
This commit completes the cleanup:

- Fix migration docstring formatting artifacts (double commas, extra spaces)
- Revert viewer/platform_viewer description to "Read-only access"
- Remove tools.execute from rbac.md viewer/platform_viewer permission tables
- Remove tools.execute from test_rbac_permission_matrix.py constants
- Replace hardcoded stale permission lists in migration backfill tests
  with ROLE_PERMISSION_ADDITIONS references
- Restore original e2e deny assertions for tool execution (non-admin
  users lack global tools.execute)
- Add integration tests for upgrade()/downgrade() via public entry points

Signed-off-by: Mihai Criveti <[email protected]>

* fix: rename alembic migration file to reflect servers.use instead of tools.execute

Signed-off-by: Madhav Kandukuri <[email protected]>

* down_revision

Signed-off-by: Rakhi Dutta <[email protected]>

* down revision in test

Signed-off-by: Rakhi Dutta <[email protected]>

* test case fix

Signed-off-by: Rakhi Dutta <[email protected]>

* fix(rbac): update migration down_revision to current head

Point migration abf8ac3b6008 down_revision from e1f2a3b4c5d6 to
64acf94cb7f2 (the actual current Alembic head on main) to eliminate
the multiple-heads condition that would break alembic upgrade.

Update the corresponding test constant to match.

Signed-off-by: Mihai Criveti <[email protected]>

* fix(rbac): restore e2e denial helper and add downgrade edge-case test

Restore _assert_access_denied_tool_call() in the e2e test — the
replacement inline assertions were broken (checked result.isError
but the actual response uses the error key with JSON-RPC code -32003)
and weaker (did not verify "access denied" message or error code).

Add a migration test documenting the known downgrade limitation: if a
role already had a backfilled permission before the migration ran,
downgrade() will remove it. This is an accepted trade-off for a simple
data migration targeting system-bootstrapped roles.

Signed-off-by: Mihai Criveti <[email protected]>

---------

Signed-off-by: Rakhi Dutta <[email protected]>
Signed-off-by: Mihai Criveti <[email protected]>
Signed-off-by: Madhav Kandukuri <[email protected]>
Co-authored-by: Mihai Criveti <[email protected]>
Co-authored-by: Madhav Kandukuri <[email protected]>
kamath-a pushed a commit to kamath-a/mcp-context-forge that referenced this pull request Jun 26, 2026
…wer roles (IBM#3390)

* fix(rbac): backfill admin.overview and tools.execute permissions to viewer roles

Add Alembic migration to backfill missing permissions into existing role
records and update bootstrap_db.py so new deployments receive the correct
permissions from first boot.

Roles updated:
- viewer: admin.overview, tools.execute
- platform_viewer: admin.overview, tools.execute
- developer: admin.overview
- team_admin: admin.overview

The migration is idempotent, supports both PostgreSQL (JSONB) and SQLite,
and includes a symmetric downgrade.

Closes IBM#3329

Signed-off-by: Rakhi Dutta <[email protected]>
Signed-off-by: Mihai Criveti <[email protected]>

* lint

Signed-off-by: Mihai Criveti <[email protected]>

* alembic

Signed-off-by: Rakhi Dutta <[email protected]>

* test case fix

Signed-off-by: Rakhi Dutta <[email protected]>

* fix(rbac): add missing servers.use to viewer bootstrap and improve test coverage

Add servers.use permission to viewer and platform_viewer role definitions
in bootstrap_db.py to match what the Alembic migration backfills. Without
this, new deployments would lack servers.use for viewer roles while migrated
deployments would have it, causing inconsistent tool-testing behavior.

Also adds migration tests covering servers.use addition/removal for all
roles and reverts unrelated uv.lock dependency bumps.

Signed-off-by: Mihai Criveti <[email protected]>

* docs(rbac): update role descriptions and permission tables for viewer roles

Update viewer and platform_viewer role descriptions from "Read-only" to
"Read and test" to reflect the addition of tools.execute and servers.use
permissions. Update RBAC documentation to include admin.overview,
tools.execute, and servers.use in the built-in roles table, permission
categories, and available permissions reference.

Signed-off-by: Mihai Criveti <[email protected]>

* fix(rbac): correct migration docstrings to include servers.use

The module docstring and upgrade/downgrade docstrings only mentioned
admin.overview and tools.execute, but ROLE_PERMISSION_ADDITIONS also
includes servers.use for all four roles. Align documentation with code.

Signed-off-by: Mihai Criveti <[email protected]>

* fix(rbac): safe downgrade, realistic test fixtures, e2e test alignment

Fix migration downgrade regression: remove servers.use from developer and
team_admin entries in ROLE_PERMISSION_ADDITIONS since those roles already
have it in their baseline definitions. Without this, a downgrade would
strip a pre-existing permission, breaking transport access.

Update migration test fixtures with realistic baselines (developer and
team_admin include servers.use) and add a round-trip test that verifies
upgrade->downgrade restores exact original permissions for all roles.

Update e2e RBAC tests: since all non-admin users auto-receive
platform_viewer (global) which now includes tools.execute, the tests
that expected denial on the default /mcp endpoint now correctly expect
success. This aligns with the intent of issue IBM#3329.

Fix remaining stale "read-only" text in rbac.md migration info box
for platform_viewer.

Signed-off-by: Mihai Criveti <[email protected]>

* remove tools.execute

Signed-off-by: Rakhi Dutta <[email protected]>

* fix(rbac): remove stale tools.execute references and fix test consistency

The previous commit removed tools.execute from the migration and
bootstrap_db.py but left it in docs, test constants, and e2e tests.
This commit completes the cleanup:

- Fix migration docstring formatting artifacts (double commas, extra spaces)
- Revert viewer/platform_viewer description to "Read-only access"
- Remove tools.execute from rbac.md viewer/platform_viewer permission tables
- Remove tools.execute from test_rbac_permission_matrix.py constants
- Replace hardcoded stale permission lists in migration backfill tests
  with ROLE_PERMISSION_ADDITIONS references
- Restore original e2e deny assertions for tool execution (non-admin
  users lack global tools.execute)
- Add integration tests for upgrade()/downgrade() via public entry points

Signed-off-by: Mihai Criveti <[email protected]>

* fix: rename alembic migration file to reflect servers.use instead of tools.execute

Signed-off-by: Madhav Kandukuri <[email protected]>

* down_revision

Signed-off-by: Rakhi Dutta <[email protected]>

* down revision in test

Signed-off-by: Rakhi Dutta <[email protected]>

* test case fix

Signed-off-by: Rakhi Dutta <[email protected]>

* fix(rbac): update migration down_revision to current head

Point migration abf8ac3b6008 down_revision from e1f2a3b4c5d6 to
64acf94cb7f2 (the actual current Alembic head on main) to eliminate
the multiple-heads condition that would break alembic upgrade.

Update the corresponding test constant to match.

Signed-off-by: Mihai Criveti <[email protected]>

* fix(rbac): restore e2e denial helper and add downgrade edge-case test

Restore _assert_access_denied_tool_call() in the e2e test — the
replacement inline assertions were broken (checked result.isError
but the actual response uses the error key with JSON-RPC code -32003)
and weaker (did not verify "access denied" message or error code).

Add a migration test documenting the known downgrade limitation: if a
role already had a backfilled permission before the migration ran,
downgrade() will remove it. This is an accepted trade-off for a simple
data migration targeting system-bootstrapped roles.

Signed-off-by: Mihai Criveti <[email protected]>

---------

Signed-off-by: Rakhi Dutta <[email protected]>
Signed-off-by: Mihai Criveti <[email protected]>
Signed-off-by: Madhav Kandukuri <[email protected]>
Co-authored-by: Mihai Criveti <[email protected]>
Co-authored-by: Madhav Kandukuri <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working ica ICA related issues MUST P1: Non-negotiable, critical requirements without which the product is non-functional or unsafe rbac Role-based Access Control release-fix Critical bugfix required for the release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants