Skip to content

Role-Based Access Control

Madhyamas Enterprise includes a role-based access control (RBAC) system that restricts what authenticated users can do. Each user is assigned a role, and each role grants a set of permissions over resources.

Roles

Madhyamas defines four built-in roles:

RoleDescriptionTypical User
AdminFull access to all resources and admin panelsSystem administrator, DevOps
UserRead and write traffic data, sessions, mocks, rewrites, breakpoints, scriptsDeveloper, QA engineer
ViewerRead-only access to traffic data and intercept rulesStakeholder, manager
ReadOnlyRead-only access (same as Viewer)Automated reporting, auditors

Resources

ResourceDescription
TrafficCaptured HTTP/HTTPS traffic entries
SessionTraffic sessions (named groups)
MockMock response rules
RewriteRewrite rules
BreakpointBreakpoint rules
ScriptJavaScript scripts
PluginWASM plugins
ConfigSystem configuration

Permissions

PermissionDescription
ReadView/list entries
WriteCreate/modify entries
DeleteDelete entries
ExecuteExecute scripts or plugins

Permission Matrix

RoleTrafficSessionMockRewriteBreakpointScriptPluginConfig
AdminR/W/DR/W/DR/W/DR/W/DR/W/DR/W/D/ER/W/D/ER/W/D
UserR/WR/WR/WR/WR/WR/W/E
ViewerRRRRRRR
ReadOnlyRRRRRRR

R = Read, W = Write, D = Delete, E = Execute

How Enforcement Works

  1. Authentication — The auth middleware validates the JWT or API key and extracts the user's role
  2. Authorization — The require_permission_middleware checks the user's role against the required (resource, permission) pair for the endpoint
  3. Response — If the user lacks permission, the server returns 403 Forbidden
rust
// Example: Creating a mock requires (Mock, Write) permission
// A Viewer role user will get 403 Forbidden

RBAC Endpoints

List Roles

bash
curl -H "Authorization: Bearer <token>" \
  http://localhost:3001/api/rbac/roles

List Permissions

bash
curl -H "Authorization: Bearer <token>" \
  http://localhost:3001/api/rbac/permissions

Check Permission

bash
curl -X POST http://localhost:3001/api/rbac/check \
  -H "Authorization: Bearer <token>" \
  -H "Content-Type: application/json" \
  -d '{
    "user_id": "<user-id>",
    "resource": "Mock",
    "permission": "Write"
  }'

Response:

json
{
  "allowed": true
}

Assigning Roles

Via Web UI

  1. Navigate to Admin → Users
  2. Click the edit (pencil) icon next to a user
  3. Select the role from the dropdown
  4. Click Save

Via CLI

bash
madhyamas users update-role --id <user-id> --role admin

Via API

bash
curl -X PUT http://localhost:3001/api/users/<user-id> \
  -H "Authorization: Bearer <token>" \
  -H "Content-Type: application/json" \
  -d '{"role": "admin"}'

Common Scenarios

Developer (User Role)

A developer who needs to debug APIs, create mocks, and write scripts:

  • Role: User
  • Can: View traffic, create/edit sessions, create mocks and rewrites, set breakpoints, write and execute scripts
  • Cannot: Manage users, view audit logs, manage plugins, change system config

QA Engineer (User Role)

A QA engineer who tests APIs with mocks and rewrites:

  • Role: User
  • Can: Same as developer
  • Cannot: Same as developer

Stakeholder (Viewer Role)

A manager who needs to review traffic but not modify anything:

  • Role: Viewer
  • Can: View traffic, sessions, mocks, rewrites, breakpoints, scripts, plugins
  • Cannot: Create or modify any resource, manage users, view audit logs

Auditor (ReadOnly Role)

An external auditor who reviews captured traffic for compliance:

  • Role: ReadOnly
  • Can: View all traffic and intercept rules (read-only)
  • Cannot: Modify anything, export data, manage users

CI/CD Pipeline (API Key)

An automated pipeline that exports traffic for analysis:

  • API Key with scopes: traffic:read, traffic:export
  • Can: List and export traffic
  • Cannot: Modify anything, manage users

See Also

Released under the MIT OR Apache-2.0 License.