- Date: 2025-11-15
- Status: ✅ Complete
TelemetryFlow implements a 5-tier Role-Based Access Control (RBAC) system with hierarchical permissions and organizational scoping. This document provides comprehensive visualization and comparison of all roles, permissions, and access patterns.
graph TD
A[Tier 1: Super Administrator] --> B[Tier 2: Administrator]
B --> C[Tier 3: Developer]
C --> D[Tier 4: Viewer]
C --> E[Tier 5: Demo]
A1[Global Scope<br/>All Organizations<br/>All Regions] -.-> A
B1[Organization Scope<br/>Single Organization<br/>Multiple Regions] -.-> B
C1[Organization Scope<br/>Single Organization] -.-> C
D1[Organization Scope<br/>Read-Only] -.-> D
E1[Demo Org Only<br/>Auto-cleanup 6h] -.-> E
style A fill:#ff6b6b,stroke:#c92a2a,stroke-width:3px,color:#fff
style B fill:#fa5252,stroke:#e03131,stroke-width:2px,color:#fff
style C fill:#ffd43b,stroke:#fab005,stroke-width:2px,color:#000
style D fill:#51cf66,stroke:#37b24d,stroke-width:2px,color:#fff
style E fill:#74c0fc,stroke:#339af0,stroke-width:2px,color:#fff
mindmap
root((5-Tier RBAC))
Super Admin
Global Scope
Platform Management
All Permissions
System Admin
Administrator
Organization Scope
Full CRUD
User Management
No Platform Access
Developer
Organization Scope
Create/Read/Update
No Delete
No User Management
Viewer
Organization Scope
Read-Only
No Modifications
Audit Access
Demo
Demo Org Only
Developer Access
Auto-Cleanup
Isolated Data
| Attribute | Details |
|---|---|
| Scope | Global (all organizations, regions, workspaces, tenants) |
| Description | Can manage all the SaaS Platform across all organizations and regions |
| Permission Count | 60+ |
| Key Permissions | • Platform management • All IAM operations • System administration • Audit log access |
| Use Cases | • Platform administrators • DevOps team managing infrastructure • System maintenance |
| Restrictions | None |
| Attribute | Details |
|---|---|
| Scope | Organization-scoped (single organization, multiple regions) |
| Description | Can manage all permissions within their organization across multiple regions |
| Permission Count | 55+ |
| Key Permissions | • Organization read/update • Full user management (CRUD) • Full role management (CRUD) • Full tenant/workspace management • Audit log read/export |
| Use Cases | • Organization administrators • Team leads • Department managers |
| Restrictions | • No platform management • No system administration • Cannot create/delete organizations |
| Attribute | Details |
|---|---|
| Scope | Organization-scoped (single organization) |
| Description | Can create and update resources within their organization, but cannot delete |
| Permission Count | 40+ |
| Key Permissions | • User create/read/update • Tenant/workspace create/read/update • Dashboard/alert create/read/update • Agent management • Audit log read-only |
| Use Cases | • Software developers • DevOps engineers • QA engineers |
| Restrictions | • No delete operations • No user/role management • No export operations • Read-only for roles/permissions |
| Attribute | Details |
|---|---|
| Scope | Organization-scoped (single organization) |
| Description | Read-only access to resources within their organization |
| Permission Count | 17 |
| Key Permissions | • All resources read-only • Audit log read-only • Uptime check access |
| Use Cases | • Business analysts • Stakeholders • External auditors • Read-only monitoring |
| Restrictions | • No write operations • No create/update/delete operations |
| Attribute | Details |
|---|---|
| Scope | Demo Organization ONLY (org-demo, ws-demo, tn-demo) |
| Description | Developer access limited to Demo Organization, Demo Workspace, and Demo Tenant only |
| Permission Count | 40+ (same as Developer) |
| Key Permissions | • All Developer permissions • User create/read/update • Dashboard/alert create/read/update • Agent management |
| Use Cases | • Product demonstrations • Trial accounts • Training environments • Customer evaluations |
| Restrictions | • Limited to Demo Organization only • Cannot access production data • Data auto-deleted every 6 hours • No delete operations |
iam:users:read- View usersiam:users:create- Create usersiam:users:update- Update usersiam:users:delete- Delete users
iam:roles:read- View rolesiam:roles:create- Create rolesiam:roles:update- Update rolesiam:roles:delete- Delete roles
iam:permissions:read- View permissions
iam:organizations:read- View organizationsiam:organizations:create- Create organizationsiam:organizations:update- Update organizationsiam:organizations:delete- Delete organizations
iam:tenants:read- View tenantsiam:tenants:create- Create tenantsiam:tenants:update- Update tenantsiam:tenants:delete- Delete tenants
iam:workspaces:read- View workspacesiam:workspaces:create- Create workspacesiam:workspaces:update- Update workspacesiam:workspaces:delete- Delete workspaces
iam:regions:read- View regionsiam:regions:create- Create regionsiam:regions:update- Update regionsiam:regions:delete- Delete regions
iam:groups:read- View groupsiam:groups:create- Create groupsiam:groups:update- Update groupsiam:groups:delete- Delete groups
platform:manage- Platform management (Super Admin only)system:admin- System administration (Super Admin only)
| Permission Category | Super Admin | Administrator | Developer | Viewer | Demo |
|---|---|---|---|---|---|
| Scope | 🌍 Global | 🏢 Organization | 🏢 Organization | 🏢 Organization | 🎭 Demo Org |
| Permission Count | 60+ | 55+ | 40+ | 17 | 40+ |
| Platform Management | ✅ | ❌ | ❌ | ❌ | ❌ |
| System Admin | ✅ | ❌ | ❌ | ❌ | ❌ |
| Delete Operations | ✅ | ✅ | ❌ | ❌ | ❌ |
| Data Retention | ♾️ Permanent | ♾️ Permanent | ♾️ Permanent | ♾️ Permanent | ⏱️ 6 hours |
| Resource | Super Admin | Administrator | Developer | Viewer | Demo |
|---|---|---|---|---|---|
| Organizations | 🔴 CRUD | 🟡 R/U | 🟢 R | 🟢 R | 🟢 R |
| Users | 🔴 CRUD | 🔴 CRUD | 🟡 CRU | 🟢 R | 🟡 CRU |
| Roles | 🔴 CRUD | 🔴 CRUD | 🟢 R | 🟢 R | 🟢 R |
| Permissions | 🔴 CRUD | 🟢 R | 🟢 R | 🟢 R | 🟢 R |
| Tenants | 🔴 CRUD | 🔴 CRUD | 🟡 CRU | 🟢 R | 🟡 CRU |
| Workspaces | 🔴 CRUD | 🔴 CRUD | 🟡 CRU | 🟢 R | 🟡 CRU |
| Regions | 🔴 CRUD | 🟢 R | 🟢 R | 🟢 R | 🟢 R |
| Groups | 🔴 CRUD | 🔴 CRUD | 🟡 CRU | 🟢 R | 🟡 CRU |
| Audit Logs | 🔴 R/Export | 🔴 R/Export | 🟢 R | 🟢 R | 🟢 R |
Legend:
- 🔴 CRUD = Create, Read, Update, Delete (Full Access)
- 🟡 CRU = Create, Read, Update (No Delete)
- 🟡 R/U = Read, Update (No Create/Delete)
- 🟢 R = Read Only
- 🔴 R/Export = Read + Export capabilities
| User | Password | Role | Organization | Tenant | |
|---|---|---|---|---|---|
| Super Administrator | superadmin.telemetryflow@telemetryflow.id | SuperAdmin@123456 | super_administrator | All | All |
| Administrator TelemetryFlow | administrator.telemetryflow@telemetryflow.id | Admin@123456 | administrator | TelemetryFlow | TelemetryFlow |
| Developer TelemetryFlow | developer.telemetryflow@telemetryflow.id | Developer@123456 | developer | TelemetryFlow | TelemetryFlow |
| Viewer TelemetryFlow | viewer.telemetryflow@telemetryflow.id | Viewer@123456 | viewer | TelemetryFlow | TelemetryFlow |
| Demo TelemetryFlow | demo.telemetryflow@telemetryflow.id | Demo@123456 | demo | Demo Org | Demo Tenant |
graph LR
A[Request] --> B{Authentication}
B -->|Valid JWT| C{Authorization}
B -->|Invalid| X[401 Unauthorized]
C --> D{Role Check}
D -->|Has Role| E{Permission Check}
D -->|No Role| Y[403 Forbidden]
E -->|Has Permission| F{Scope Check}
E -->|No Permission| Y
F -->|Organization Match| G{Tenant Filter}
F -->|No Match| Y
G -->|Allowed| H[Execute Query]
G -->|Denied| Y
H --> I[Audit Log]
I --> J[Response]
style A fill:#e3f2fd
style B fill:#fff3e0
style C fill:#fff3e0
style D fill:#f3e5f5
style E fill:#f3e5f5
style F fill:#e8f5e9
style G fill:#e8f5e9
style H fill:#e1f5fe
style I fill:#fce4ec
style J fill:#e8f5e9
style X fill:#ffebee
style Y fill:#ffebee
| Feature | Description | Implementation |
|---|---|---|
| Organization-level | Data isolated by organization | Query filters: WHERE organizationId = :orgId |
| Tenant-level | Query filtering per tenant | Automatic tenant scoping in repositories |
| Workspace-level | Resource scoping per workspace | Workspace-based access control |
| Demo isolation | Complete separation from production | Separate organization with auto-cleanup |
| Feature | Description | Status |
|---|---|---|
| Auto-cleanup | Data deleted every 6 hours | ✅ Implemented |
| Production isolation | Cannot access production orgs | ✅ Enforced |
| Workspace isolation | Cannot access production workspaces | ✅ Enforced |
| Tenant isolation | Cannot access production tenants | ✅ Enforced |
| Separate domain | demo.telemetryflow.id |
✅ Configured |
| Layer | Mechanism | Description |
|---|---|---|
| Authentication | JWT tokens | Validates user identity |
| Authorization | @RequirePermissions() decorator |
Checks user permissions before execution |
| Scoping | Query filters | Automatically filters by organization/tenant |
| Audit | ClickHouse audit_logs | Logs all actions with user context |
| Validation | Guards & Interceptors | Validates request data and permissions |
flowchart TB
subgraph Database["Database Layer"]
PG[("PostgreSQL IAM Data")]
CH[("ClickHouse Audit Logs")]
end
subgraph Seeds["Seed Data"]
S1["1. IAM Roles & Permissions"]
S2["2. Auth Test Users"]
S3["3. Groups"]
end
subgraph Application["Application Layer"]
G1["Guards RequirePermissions"]
D1["Decorators CurrentUser"]
R1["Repositories Auto-scoping"]
end
Seeds --> PG
PG --> Application
Application --> CH
S1 --> S2
S2 --> S3
style PG fill:#4dabf7
style CH fill:#ffd43b
style S1 fill:#51cf66
style S2 fill:#51cf66
style S3 fill:#51cf66
style G1 fill:#ff6b6b
style D1 fill:#ff6b6b
style R1 fill:#ff6b6b
| Database | Purpose | Tables |
|---|---|---|
| PostgreSQL | IAM data storage | users, roles, permissions, role_permissions, user_roles, organizations, tenants, workspaces, regions, groups |
| ClickHouse | Audit log storage | audit_logs, audit_logs_stats, audit_logs_user_activity |
| Order | File | Purpose | Records |
|---|---|---|---|
| 1 | 1704240000001-seed-iam-roles-permissions.ts |
Create 5 roles with explicit permissions | 5 roles, 22+ permissions |
| 2 | 1704240000002-seed-auth-test-users.ts |
Create test users for each role | 5 users |
| 3 | 1704240000003-seed-groups.ts |
Create user groups | 4 groups |
| Component | Location | Purpose |
|---|---|---|
| Guards | @RequirePermissions() decorator |
Checks user permissions before controller execution |
| Decorators | @CurrentUser() |
Extracts authenticated user from request |
| Repositories | Auto-scoping queries | Automatically filters by organization/tenant |
| Audit | ClickHouse service | Logs all actions to audit_logs table |
| Level | Implementation | Example |
|---|---|---|
| Organization | Query filter | WHERE organizationId = :orgId |
| Tenant | Repository scoping | findByTenant(tenantId) |
| Workspace | Resource filtering | WHERE workspaceId = :wsId |
| Demo | Separate organization | organizationId = 'org-demo' |
# Super Administrator
Email: superadmin.telemetryflow@telemetryflow.id
Password: SuperAdmin@123456
# Administrator
Email: administrator.telemetryflow@telemetryflow.id
Password: Admin@123456
# Developer
Email: developer.telemetryflow@telemetryflow.id
Password: Developer@123456
# Viewer
Email: viewer.telemetryflow@telemetryflow.id
Password: Viewer@123456
# Demo
Email: demo.telemetryflow@telemetryflow.id
Password: Demo@123456All users can access the API at: http://localhost:3000/api
Use Swagger UI to test different permission levels and see which endpoints are accessible for each role.
- Login with different roles to see permission differences
- Try CRUD operations to verify access control
- Check Swagger UI for available endpoints per role
- Review audit logs to track all actions
The 5-tier RBAC system is automatically seeded when running:
# Seed IAM data only
pnpm db:seed:iam
# Seed all data (PostgreSQL + ClickHouse)
pnpm db:seed
# Run migrations + seeds
pnpm db:migrate:seed
# Full bootstrap (dependencies, Docker, migrations, seeds)
bash scripts/bootstrap.sh --dev- Principle of Least Privilege: Assign minimum required permissions
- Role Separation: Use appropriate role for each user type
- Demo Isolation: Keep demo users in demo organization only
- Regular Audits: Review role assignments periodically
- Password Security: Enforce strong passwords (12+ chars, uppercase, special char)
- MFA Enforcement: Enable MFA for Super Admin and Administrator roles
- Last Updated: 2025-12-05
- Status: ✅ 5-Tier RBAC System Complete