nothingworry commited on
Commit
db5de26
Β·
1 Parent(s): dc11950

update the readme file

Browse files
Files changed (1) hide show
  1. README.md +114 -1
README.md CHANGED
@@ -71,8 +71,10 @@ Then access:
71
  - **Gradio UI**: `http://localhost:7860`
72
  - **FastAPI Docs**: `http://localhost:8000/docs`
73
  - **Next.js Frontend** (optional): `cd frontend && npm install && npm run dev` β†’ `http://localhost:3000`
 
 
74
 
75
- > **Security Note:** REST requests that hit protected endpoints must include both `x-tenant-id` and `x-user-role` headers. Roles (`viewer`, `editor`, `admin`, `owner`) determine which actionsβ€”such as document ingestion, rule uploads, or analytics accessβ€”the caller may perform.
76
 
77
  ---
78
 
@@ -102,6 +104,7 @@ Then access:
102
  - LLM token logs and latency metrics
103
  - 🌐 **Live Web Search** – Google Programmable Search (Custom Search API) with tenant-aware MCP tooling
104
  - 🏒 **Multi-Tenant Isolation** – Complete tenant isolation with centralized tenant ID management; backend enforces strict isolation for chat, ingestion, and admin ops
 
105
  - πŸ”„ **Intelligent Multi-Tool Orchestration** – MCP agent orchestrator autonomously selects optimal tool chains (RAG + Web + LLM, etc.) based on query intent and context
106
  - ⚑ **Robust Error Handling** – Structured error responses, retry mechanisms, and graceful fallbacks (e.g., if RAG fails β†’ fallback to LLM-only)
107
  - πŸ“‘ **Streaming Responses** – Chat responses stream word-by-word using Server-Sent Events (SSE) for real-time user experience
@@ -147,6 +150,116 @@ Subsequent tool calls with the same `session_id` will receive a `memory` field c
147
 
148
  ---
149
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
150
  ## Installation & Setup
151
 
152
  ### Prerequisites
 
71
  - **Gradio UI**: `http://localhost:7860`
72
  - **FastAPI Docs**: `http://localhost:8000/docs`
73
  - **Next.js Frontend** (optional): `cd frontend && npm install && npm run dev` β†’ `http://localhost:3000`
74
+ - Use the role selector in the header to switch between viewer, editor, admin, or owner roles
75
+ - UI automatically shows/hides features based on selected role
76
 
77
+ > **Security Note:** REST requests that hit protected endpoints must include both `x-tenant-id` and `x-user-role` headers. Roles (`viewer`, `editor`, `admin`, `owner`) determine which actionsβ€”such as document ingestion, rule uploads, or analytics accessβ€”the caller may perform. The Next.js frontend automatically sends the selected role in all API requests.
78
 
79
  ---
80
 
 
104
  - LLM token logs and latency metrics
105
  - 🌐 **Live Web Search** – Google Programmable Search (Custom Search API) with tenant-aware MCP tooling
106
  - 🏒 **Multi-Tenant Isolation** – Complete tenant isolation with centralized tenant ID management; backend enforces strict isolation for chat, ingestion, and admin ops
107
+ - πŸ” **Fine-Grained Role-Based Access Control (RBAC)** – Four-tier role system (viewer, editor, admin, owner) with dynamic UI visibility and backend permission enforcement; frontend automatically shows/hides features based on role
108
  - πŸ”„ **Intelligent Multi-Tool Orchestration** – MCP agent orchestrator autonomously selects optimal tool chains (RAG + Web + LLM, etc.) based on query intent and context
109
  - ⚑ **Robust Error Handling** – Structured error responses, retry mechanisms, and graceful fallbacks (e.g., if RAG fails β†’ fallback to LLM-only)
110
  - πŸ“‘ **Streaming Responses** – Chat responses stream word-by-word using Server-Sent Events (SSE) for real-time user experience
 
150
 
151
  ---
152
 
153
+ ## Role-Based Access Control (RBAC)
154
+
155
+ IntegraChat implements fine-grained role-based access control (RBAC) for both backend API endpoints and frontend UI. This ensures that users only see and can access features appropriate for their role level.
156
+
157
+ ### Roles
158
+
159
+ The system supports four roles with increasing privileges:
160
+
161
+ 1. **viewer** (default) - Basic read-only access
162
+ - Can use chat functionality
163
+ - Cannot ingest documents
164
+ - Cannot delete documents
165
+ - Cannot view analytics
166
+ - Cannot manage admin rules
167
+
168
+ 2. **editor** - Content management access
169
+ - Can use chat functionality
170
+ - βœ… Can ingest documents (upload, paste, URLs, files)
171
+ - ❌ Cannot delete documents
172
+ - ❌ Cannot view analytics
173
+ - ❌ Cannot manage admin rules
174
+
175
+ 3. **admin** - Administrative access
176
+ - Can use chat functionality
177
+ - βœ… Can ingest documents
178
+ - βœ… Can delete documents
179
+ - βœ… Can view analytics
180
+ - βœ… Can manage admin rules
181
+
182
+ 4. **owner** - Full system access
183
+ - Same permissions as admin (highest privilege level)
184
+
185
+ ### Permission Matrix
186
+
187
+ | Action | viewer | editor | admin | owner |
188
+ |--------|--------|--------|-------|-------|
189
+ | Chat Bot | βœ… | βœ… | βœ… | βœ… |
190
+ | Ingest Documents | ❌ | βœ… | βœ… | βœ… |
191
+ | Delete Documents | ❌ | ❌ | βœ… | βœ… |
192
+ | View Analytics | ❌ | ❌ | βœ… | βœ… |
193
+ | Manage Rules | ❌ | ❌ | βœ… | βœ… |
194
+
195
+ ### Backend RBAC
196
+
197
+ Backend API endpoints enforce RBAC through the `x-user-role` header:
198
+
199
+ ```python
200
+ # Permission matrix in backend/mcp_server/common/access_control.py
201
+ PERMISSIONS = {
202
+ "manage_rules": {"owner", "admin"},
203
+ "ingest_documents": {"owner", "admin", "editor"},
204
+ "delete_documents": {"owner", "admin"},
205
+ "view_analytics": {"owner", "admin"},
206
+ }
207
+ ```
208
+
209
+ **Protected Endpoints:**
210
+ - `/admin/rules` - Requires `admin` or `owner` role
211
+ - `/rag/ingest*` - Requires `editor`, `admin`, or `owner` role
212
+ - `/rag/delete*` - Requires `admin` or `owner` role
213
+ - `/analytics/*` - Requires `admin` or `owner` role
214
+
215
+ **Example Request:**
216
+ ```bash
217
+ curl -X POST "http://localhost:8000/admin/rules" \
218
+ -H "Content-Type: application/json" \
219
+ -H "x-tenant-id: tenant123" \
220
+ -H "x-user-role: admin" \
221
+ -d '{"rule": "Do not share passwords"}'
222
+ ```
223
+
224
+ If the role lacks permission, the API returns `403 Forbidden` with a descriptive error message.
225
+
226
+ ### Frontend RBAC
227
+
228
+ The frontend UI dynamically shows/hides features based on the selected role:
229
+
230
+ **Role Selector:**
231
+ - Located in the header navigation
232
+ - Dropdown to switch between roles (viewer, editor, admin, owner)
233
+ - Role is persisted in localStorage
234
+ - Changes take effect immediately across all pages
235
+
236
+ **Conditional UI Visibility:**
237
+ - **Navigation Links**: Only relevant links shown (e.g., editor doesn't see "Analytics" or "Admin Rules")
238
+ - **Page Sections**: Entire sections hidden if user lacks permission
239
+ - **Action Buttons**: Delete buttons hidden for editor role
240
+ - **Access Denied Pages**: Friendly error messages when accessing restricted routes
241
+
242
+ **Protected Routes:**
243
+ - `/ingestion` - Editor, Admin, Owner only
244
+ - `/analytics` - Admin, Owner only
245
+ - `/admin-rules` - Admin, Owner only
246
+
247
+ **Implementation:**
248
+ - Permission utilities in `frontend/lib/permissions.ts`
249
+ - Conditional rendering in components based on role
250
+ - Access denied pages with clear messaging
251
+
252
+ ### Using RBAC
253
+
254
+ 1. **Change Role**: Use the role dropdown in the header to switch roles
255
+ 2. **Verify Permissions**: UI automatically updates to show only permitted features
256
+ 3. **API Requests**: Role is automatically sent as `x-user-role` header
257
+ 4. **Error Handling**: Access denied pages guide users on required roles
258
+
259
+ **Note**: Role changes are immediate and affect both UI visibility and API permissions. The role persists across page refreshes via localStorage.
260
+
261
+ ---
262
+
263
  ## Installation & Setup
264
 
265
  ### Prerequisites