Skip to content

feat(rbac): add data_source and mcp_tool OpenFGA types + BFF list filter#1575

Closed
sriaradhyula wants to merge 2 commits into
prebuild/feat/rbac-kb-share-with-teamsfrom
prebuild/feat/rbac-data-source-mcp-tool-types
Closed

feat(rbac): add data_source and mcp_tool OpenFGA types + BFF list filter#1575
sriaradhyula wants to merge 2 commits into
prebuild/feat/rbac-kb-share-with-teamsfrom
prebuild/feat/rbac-data-source-mcp-tool-types

Conversation

@sriaradhyula
Copy link
Copy Markdown
Member

Summary

PR 4 of the 2026-05-27 fine-grained KB ReBAC plan (see docs/docs/specs/2026-05-27-fine-grained-rbac-for-withauth-routes/plan.md).

Introduces two new per-resource OpenFGA types so per-KB ingest and per-tool invoke can be granted independently of knowledge_base:<id> reads.

OpenFGA model

deploy/openfga/model.fga adds:

type data_source     # 1:1 with knowledge_base for now, but lets us grant
                     # ingest-only access without leaking read on KB content
type mcp_tool        # RAG custom MCP tools (PUT /v1/mcp/custom-tools/<id>),
                     # distinct from the existing tool:<id> used by AgentGateway

Both expose manager: [..., organization#admin] so org admins are an explicit edge on the model (not just a runtime bypass). mcp_tool additionally exposes user and caller relations so team members get can_call. knowledge_base#manager also gains organization#admin for parity.

Reconcilers

buildDataSourceRelationshipTupleDiff and buildMcpToolRelationshipTupleDiff mirror the shared-teams diff that PR 3 added for KBs. A shared helper buildOwnedResourceWithSharedTeamsDiff now factors the diff logic for knowledge_base, data_source, and mcp_tool.

BFF integration

  • PUT /v1/mcp/custom-tools/<tool_id> (proxied via /api/rag/[...path]) writes mcp_tool:<tool_id> tuples after a 2xx response from the RAG server. Owner-team writes are gated by team:<slug>#can_use.
  • GET /v1/mcp/custom-tools responses are filtered by mcp_tool:<id>#can_read. Org admins bypass via PR 1's super-grant.

Backfill migrations

  • data_source_grants_backfill_v1 — strictly additive, mirrors every existing knowledge_base:<id> tuple as a parallel data_source:<id> tuple so day-zero KB readers stay data-source readers.
  • mcp_tool_grants_backfill_v1 — walks Mongo team_rag_tools and writes the canonical reader + user (member) and manager (admin) tuples for every team-owned tool.

Guardrails

schema-area-classifications.ts adds openfga_tuples so registry-guardrails.test.ts keeps passing.

Stacked on

This PR is stacked on:

Base branch is prebuild/feat/rbac-kb-share-with-teams. Merge order: 1 → 2 → 3 → 4.

Test plan

  • npx jest --testPathPatterns "openfga-data-source-mcp-tool|agent-organization-inheritance|mcp-tool-list-filter|registry-guardrails" — 33 passed.
  • npx eslint on all changed files — 0 errors.
  • Manual: apply the new authorization model to a dev OpenFGA, run data_source_grants_backfill_v1 and mcp_tool_grants_backfill_v1 in dry-run, compare planned tuples to existing KB grants and team_rag_tools rows.
  • Manual: create a custom MCP tool via the RAG admin UI as a non-admin owner, confirm only owner-team members can see it in the list endpoint.
  • Manual: verify org admins still see every tool / data source regardless of explicit tuples (PR 1 super-grant).

Assisted-by: Claude:claude-opus-4-7

PR 4 of the 2026-05-27 fine-grained KB ReBAC plan. Introduces two new
per-resource OpenFGA types so per-KB ingest and per-tool invoke can be
granted independently of `knowledge_base:<id>` reads.

OpenFGA model
- `deploy/openfga/model.fga` adds `type data_source` and `type mcp_tool`
  with the same shared-teams relation set as `knowledge_base`
  (`team#member reader`, `team#admin manager`). Both expose
  `manager: [..., organization#admin]` so org admins are an explicit
  model edge, not just a runtime bypass.
- `mcp_tool` additionally exposes `user` and `caller` relations so team
  members get `can_call` (mirrors how `mcp_server` invokers are modelled).
- `knowledge_base#manager` also gains `organization#admin` for parity.
- `deploy/openfga/init/authorization-model.json` regenerated.

Reconcilers
- `buildDataSourceRelationshipTupleDiff` and
  `buildMcpToolRelationshipTupleDiff` (with their
  `reconcileDataSourceRelationships` / `reconcileMcpToolRelationships`
  wrappers) mirror the shared-teams diff that PR 3 added for KBs.
- The shared helper `buildOwnedResourceWithSharedTeamsDiff` factors
  the diff logic for `knowledge_base`, `data_source`, and `mcp_tool`.

BFF integration
- `/api/rag/[...path]` writes `mcp_tool:<tool_id>` tuples on a successful
  `PUT /v1/mcp/custom-tools/<tool_id>` (owner subject + owner team slug
  from the request body). Owner-team writes are gated by
  `team:<slug>#can_use`.
- `GET /v1/mcp/custom-tools` responses are filtered by
  `mcp_tool:<id>#can_read`. Org admins bypass via PR 1's super-grant.

Migrations
- `data_source_grants_backfill_v1` — strictly additive, mirrors every
  existing `knowledge_base:<id>` tuple as a parallel `data_source:<id>`
  tuple so day-zero KB readers stay data-source readers.
- `mcp_tool_grants_backfill_v1` — walks Mongo `team_rag_tools` and
  writes the canonical `reader` + `user` (member) and `manager` (admin)
  tuples for every team-owned tool.
- `schema-area-classifications.ts` adds `openfga_tuples` so
  `registry-guardrails.test.ts` keeps passing.

Docs
- RBAC architecture / file-map / pdp-coverage-audit updated to describe
  the new types, BFF integration, and backfill migrations.

Tests
- `openfga-data-source-mcp-tool.test.ts` exercises the new reconcilers.
- `mcp-tool-list-filter.test.ts` exercises the BFF list filter.
- `agent-organization-inheritance.test.ts` covers both backfill
  migrations.

Assisted-by: Claude:claude-opus-4-7
Signed-off-by: Sri Aradhyula <sraradhy@cisco.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 27, 2026

🧪 CAIPE UI Test Results

All tests passed

🟠 Overall Coverage: 55%

Coverage
lines
statements
functions
branches

📊 Detailed Coverage

Metric Covered Total Percentage
Lines 24555 41402 59.30%
Statements 26140 45458 57.50%
Functions 4404 8319 52.93%
Branches 15763 32533 48.45%

✅ Test Suites

  • ✅ auth-guard.test.tsx - Route protection & authorization
  • ✅ token-expiry-guard.test.tsx - Token expiry handling
  • ✅ a2a-sdk-client.test.ts - A2A streaming SDK
  • ✅ auth-utils.test.ts - Authentication utilities (100% coverage)
  • ✅ auth-config.test.ts - OIDC configuration
📈 Coverage Thresholds
Threshold Target Current Status
Minimum 40% 55% ✅ Pass
Good 60% 55% ⚠️ Below target
Excellent 80% 55% ⚠️ Below target
⚠️ Areas Needing Tests

High Priority:

  • hooks/use-a2a-streaming.ts - Core streaming functionality
  • store/chat-store.ts - Chat state management
  • store/agent-skills-store.ts - Agent skills
  • lib/api-client.ts - API communication
  • lib/storage-mode.ts - MongoDB/localStorage switching

Medium Priority:

  • components/chat/ChatPanel.tsx - Main chat interface
  • components/agent-builder/* - Agent builder UI
  • lib/mongodb.ts - MongoDB integration

💡 Run locally: make caipe-ui-tests
📦 Full report: Check workflow artifacts

@caipe-ci-build
Copy link
Copy Markdown

caipe-ci-build Bot commented May 27, 2026

Prebuild Artifacts for `1c84079` (archived)

Prebuild Artifacts for 1c84079

Branch: prebuild/feat/rbac-data-source-mcp-tool-types
Commit: 1c84079

Docker Images

Artifact Image Tag Status CI
caipe-ui - - Failed CI

These prebuild artifacts will be automatically cleaned up when the PR is closed or merged.

Two follow-on fixes for the new types introduced in this PR that were
missing from the original commit:

- `ui/src/types/rbac-universal.ts` now lists `data_source` and
  `mcp_tool` in `UniversalRebacResourceType`. Without this, callers
  that pass these types through the universal RBAC helpers
  (`reconcileTeamResourceTuples`, `requireResourcePermission`, etc.)
  hit a TS-level "type 'data_source' is not assignable to
  UniversalRebacResourceType" error.
- `ui/src/app/api/__tests__/rag-rbac.test.ts` now mocks
  `reconcileDataSourceRelationships` and `reconcileMcpToolRelationships`
  in the `@/lib/rbac/openfga-owned-resources` jest factory.
  Without these mocks the BFF tests pull in the real reconcilers and
  start hitting the production OpenFGA client.

Assisted-by: Claude:claude-opus-4-7
Signed-off-by: Sri Aradhyula <sraradhy@cisco.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
@caipe-ci-build
Copy link
Copy Markdown

Prebuild Artifacts for 31e5157

Branch: prebuild/feat/rbac-data-source-mcp-tool-types
Commit: 31e5157

Docker Images

Artifact Image Tag Status CI
caipe-ui ghcr.io/cnoe-io/prebuild/caipe-ui feat-rbac-data-source-mcp-tool-types-3 Published CI
Docker pull commands
docker pull ghcr.io/cnoe-io/prebuild/caipe-ui:feat-rbac-data-source-mcp-tool-types-3

These prebuild artifacts will be automatically cleaned up when the PR is closed or merged.

@sriaradhyula
Copy link
Copy Markdown
Member Author

Superseded by collapsed replacement PR #1584.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant