Skip to content

feat(rbac): share knowledge bases with teams via OpenFGA reconciler#1574

Closed
sriaradhyula wants to merge 1 commit into
prebuild/feat/ui-kb-tab-gatesfrom
prebuild/feat/rbac-kb-share-with-teams
Closed

feat(rbac): share knowledge bases with teams via OpenFGA reconciler#1574
sriaradhyula wants to merge 1 commit into
prebuild/feat/ui-kb-tab-gatesfrom
prebuild/feat/rbac-kb-share-with-teams

Conversation

@sriaradhyula
Copy link
Copy Markdown
Member

Summary

PR 3 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).

KB admins (knowledge_base:<id>#can_manage) and org admins can now share a Knowledge Base with additional teams from a dedicated panel that uses the existing TeamMultiPicker plus an Effective-Access callout.

  • UI: new /knowledge-bases/sharing/[id] page hosts KbSharingPanel. Picker mirrors how agents are shared.
  • API: new PUT /api/rag/kbs/[id]/sharing reconciles the team list through reconcileKnowledgeBaseRelationships. Gated by knowledge_base:<id>#can_manage with bypassForOrgAdmin: true so org admins (PR 1's super-grant) are always allowed.
  • Reconciler: buildKnowledgeBaseRelationshipTupleDiff now diffs nextSharedTeamSlugs vs previousSharedTeamSlugs and emits explicit deletes for teams the operator unchecks, mirroring how reconcileAgentRelationships handles shared agent teams. Unchecking a team revokes both the team:<slug>#member reader and team:<slug>#admin manager tuples in a single OpenFGA write.
  • Backfill migration: new knowledge_base_shared_team_grants_backfill_v1 walks the legacy team_kb_ownership Mongo collection and writes the canonical team:<slug>#member reader knowledge_base:<id> + team:<slug>#admin manager knowledge_base:<id> tuples for every existing (team, kb) row so admins can migrate without losing access.
  • Guardrails: schema-area-classifications.ts reclassifies team_kb_ownership as a migration schema area so registry-guardrails.test.ts keeps passing.
  • Docs: RBAC architecture / file-map / pdp-coverage-audit updated.

Stacked on

This PR is stacked on:

Base branch is prebuild/feat/ui-kb-tab-gates. Merge order: 1 → 2 → 3.

Test plan

  • npx jest --testPathPatterns "openfga-kb-shared-teams|agent-organization-inheritance|sharing-route" — 25 passed.
  • npx eslint on all changed files — 0 errors.
  • Manual: as a KB owner, open /knowledge-bases/sharing/<kb-id>, share with a second team, confirm a member of that team can now see the KB on /knowledge-bases.
  • Manual: unshare the team, confirm the member can no longer see it.
  • Manual: run the knowledge_base_shared_team_grants_backfill_v1 migration in dry-run, confirm the planned tuples match the existing team_kb_ownership Mongo rows.

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

PR 3 of the 2026-05-27 fine-grained KB ReBAC plan. KB admins (anyone
with `knowledge_base:<id>#can_manage`) and org admins can now share a
Knowledge Base with additional teams from a dedicated panel.

- New `/knowledge-bases/sharing/[id]` page hosts `KbSharingPanel`,
  which uses the existing `TeamMultiPicker` plus an Effective-Access
  callout listing reader/manager teams and org admins.
- `PUT /api/rag/kbs/[id]/sharing` reconciles the team list through
  `reconcileKnowledgeBaseRelationships` (gated by
  `knowledge_base:<id>#can_manage` with `bypassForOrgAdmin: true`).
- `buildKnowledgeBaseRelationshipTupleDiff` now diffs
  `nextSharedTeamSlugs` vs `previousSharedTeamSlugs` and emits explicit
  deletes for teams the operator unchecks (mirrors
  `reconcileAgentRelationships`).
- New `knowledge_base_shared_team_grants_backfill_v1` migration walks
  the legacy `team_kb_ownership` Mongo collection and writes the
  canonical `team:<slug>#member reader knowledge_base:<id>` plus
  `team:<slug>#admin manager knowledge_base:<id>` tuples for every
  existing (team, kb) row so admins can migrate without losing access.
- `schema-area-classifications.ts` reclassifies `team_kb_ownership` as
  a `migration` schema area to keep the registry guardrails passing.
- RBAC docs (architecture / file-map / pdp-coverage-audit) describe
  the new sharing panel, route, and backfill migration.

Tests added: `openfga-kb-shared-teams.test.ts` (reconciler diff),
`sharing-route.test.ts` (BFF route), and four new cases in
`agent-organization-inheritance.test.ts` for the backfill migration.

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

🧪 CAIPE UI Test Results

All tests passed

🟠 Overall Coverage: 55%

Coverage
lines
statements
functions
branches

📊 Detailed Coverage

Metric Covered Total Percentage
Lines 24446 41249 59.26%
Statements 26022 45291 57.45%
Functions 4391 8301 52.89%
Branches 15699 32420 48.42%

✅ 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

Prebuild Artifacts for 3bb5417

Branch: prebuild/feat/rbac-kb-share-with-teams
Commit: 3bb5417

Docker Images

Artifact Image Tag Status CI
caipe-ui ghcr.io/cnoe-io/prebuild/caipe-ui feat-rbac-kb-share-with-teams-2 Published CI
Docker pull commands
docker pull ghcr.io/cnoe-io/prebuild/caipe-ui:feat-rbac-kb-share-with-teams-2

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