# Permission Matrix — BitReport Error Reporting Admin > **Source of truth:** `api/src/types/auth.ts` → `ROLE_PERMISSIONS`. > This document is generated manually from that table. If they diverge, the code wins. ## Phase 1 Roles | Role | Description | |------|-------------| | `superadmin` | Full access. Can manage other admin users and all system settings. | | `admin` | Project and error management. Cannot manage other admin users. | | `viewer` | Read-only across all resources. Cannot mutate anything. | ## Permission Matrix | Permission | superadmin | admin | viewer | |------------|:----------:|:-----:|:------:| | **Projects** | | | | | `projects:read` | ✅ | ✅ | ✅ | | `projects:create` | ✅ | ✅ | ❌ | | `projects:update` | ✅ | ✅ | ❌ | | `projects:delete` | ✅ | ❌ | ❌ | | **Errors** | | | | | `errors:read` | ✅ | ✅ | ✅ | | `errors:triage` | ✅ | ✅ | ❌ | | `errors:delete` | ✅ | ✅ | ❌ | | **Ingest Tokens** | | | | | `ingest_tokens:read` | ✅ | ✅ | ✅ | | `ingest_tokens:create` | ✅ | ✅ | ❌ | | `ingest_tokens:revoke` | ✅ | ✅ | ❌ | | **Sources (Active Collectors)** | | | | | `sources:read` | ✅ | ✅ | ✅ | | `sources:create` | ✅ | ✅ | ❌ | | `sources:update` | ✅ | ✅ | ❌ | | `sources:delete` | ✅ | ✅ | ❌ | | **Admin Users** | | | | | `users:read` | ✅ | ❌ | ❌ | | `users:create` | ✅ | ❌ | ❌ | | `users:update` | ✅ | ❌ | ❌ | | `users:delete` | ✅ | ❌ | ❌ | | **Settings** | | | | | `settings:read` | ✅ | ✅ | ✅ | | `settings:update` | ✅ | ❌ | ❌ | | **Audit Logs** | | | | | `audit_logs:read` | ✅ | ✅ | ✅ | ## Design Notes ### Why admins cannot manage users Phase 1 keeps user management exclusive to `superadmin` to prevent privilege escalation: an `admin` cannot create another `admin` or grant themselves `superadmin`. ### Why viewers can read audit logs Transparency: all authenticated staff should be able to see what actions were taken, even if they cannot perform those actions. Audit logs contain no secrets. ### Why `projects:delete` requires superadmin Deleting a project is destructive and irreversible — it cascades to errors, tokens, and sources. Only the highest privilege level can trigger this. ### Future: per-project scoping (phase 2) In phase 2, a `project_members` table will add per-project roles: ```sql CREATE TABLE project_members ( user_id UUID REFERENCES admin_users(id), project_id UUID REFERENCES projects(id), role VARCHAR(20) CHECK (role IN ('admin', 'viewer')), PRIMARY KEY (user_id, project_id) ); ``` `superadmin` will retain global access; `admin` and `viewer` will be scoped per project. ## Audit Events The following operations MUST emit audit log entries (see `api/src/plugins/audit.ts`): | Action | Trigger | Key metadata | |--------|---------|--------------| | `auth.login` | Successful login | `role` | | `auth.login_failed` | Failed login attempt | `reason` (user_not_found / bad_password / inactive) | | `auth.logout` | Explicit logout | — | | `users.create` | New admin created | `new_role`, `new_email` | | `users.update` | Role/email changed | `old_role`, `new_role` | | `users.delete` | Admin deleted | `deleted_email`, `deleted_role` | | `projects.create` | Project registered | `project_id`, `name` | | `projects.update` | Project settings changed | `fields_changed` | | `projects.delete` | Project deleted | `project_id`, `name` | | `ingest_tokens.create` | Token issued | `project_id`, `token_id` | | `ingest_tokens.revoke` | Token revoked | `project_id`, `token_id` | | `sources.create` | Collector source added | `project_id`, `source_type` | | `sources.delete` | Source removed | `project_id`, `source_id` | | `errors.triage` | Error state changed | `from_status`, `to_status`, `error_id` | | `errors.delete` | Error deleted | `error_id`, `project_id` | | `settings.update` | System settings changed | `keys_changed` | ## Rate Limits | Endpoint | Limit | Window | Key | |----------|-------|--------|-----| | `POST /admin/auth/login` | 10 requests | 5 minutes | per IP | | `POST /api/ingest/*` | 1000 requests | 1 minute | per token (fallback: IP) | | All others | 500 requests | 1 minute | per IP | ## Payload Limits | Endpoint group | Max body size | |---------------|---------------| | `/api/ingest/*` | 512 KB | | Admin API (`/admin/*`) | 64 KB |