Admin Dashboard with OIDC Group-Based RBAC
Date: 2026-01-30
Status: Implemented
Type: Feature Addition
Summary​
Added a comprehensive admin dashboard with role-based access control (RBAC) using dual authorization methods:
- OIDC Group Membership: Users in
OIDC_REQUIRED_ADMIN_GROUPare automatically admins - MongoDB Profile: Users with
metadata.role = 'admin'in their MongoDB user document
Admin users can access platform metrics, user management, and usage statistics. Admins can also promote/demote other users via the dashboard.
Motivation​
The CAIPE platform needed administrative capabilities to:
- Monitor platform usage (DAU, MAU, conversation counts)
- Manage users and view activity
- Track system health and metrics
- Provide insights for capacity planning
Previously, there was no way to distinguish admin users from regular users, and no centralized dashboard for platform management.
Testing Strategy​
Method 1: OIDC Group Admin (Recommended)​
- Set
OIDC_REQUIRED_ADMIN_GROUP=backstage-adminsin.env - Ensure your OIDC user belongs to the admin group
- Log in via SSO
- Admin tab should appear in header
- Navigate to
/adminto view dashboard - API calls to
/api/admin/*should succeed
Method 2: MongoDB Profile Admin (Manual Promotion)​
- Start with a regular user (not in OIDC admin group)
- Manually update MongoDB:
db.users.updateOne(
{ email: "user@example.com" },
{ $set: { "metadata.role": "admin" } }
) - Log out and log back in (to refresh session)
- Admin tab should now appear
- Can now promote other users via the dashboard
Method 3: Admin-Promoted User​
- Log in as an existing admin
- Navigate to
/admin - Find the user to promote in the user list
- Click "Make Admin" button
- Confirm the action
- User will have admin access on next login
Testing Non-Admin Access​
- Log in with user NOT in admin group and NOT in MongoDB admin role
- Admin tab should be hidden
- Direct navigation to
/adminshould work (UI loads) - API calls to
/api/admin/*should return 403
Related​
- Admin Dashboard:
ui/src/app/(app)/admin/page.tsx - Admin API Routes:
ui/src/app/api/admin/ - Auth Config:
ui/src/lib/auth-config.ts - API Middleware:
ui/src/lib/api-middleware.ts - Header Component:
ui/src/components/layout/AppHeader.tsx
Conventional Commit​
feat(admin): add admin dashboard with dual RBAC (OIDC + MongoDB)
- Add OIDC_REQUIRED_ADMIN_GROUP environment variable
- Implement isAdminUser() helper for OIDC group checking
- Add MongoDB profile fallback for admin role in api-middleware
- Add session.role to NextAuth session and JWT with MongoDB check
- Create /api/admin/stats, /api/admin/users, and role management endpoints
- Build admin dashboard UI with metrics and user management
- Add role management buttons (promote/demote users)
- Show Admin tab only for admin users (OIDC or MongoDB)
- Add 403 checks on all admin routes with MongoDB fallback
Admin access is granted via OIDC group membership OR MongoDB
user.metadata.role === 'admin'. Platform metrics include DAU,
MAU, daily activity, top users, and shared conversation stats.
Admins can promote/demote other users via the dashboard.
Signed-off-by: Sri Aradhyula <sraradhy@cisco.com>
- Architecture: architecture.md