Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ contain breaking changes; [UPGRADING.md](UPGRADING.md) lists them).

### Added

- Roles: five new roles for release teams and AI agents — `RELEASE_MANAGER`, `PROJECT_MANAGER`, `PRODUCT_MANAGER`, `DEVELOPER` and `AGENT` — and a permission catalogue behind them (`backend/app/core/permissions.py`, 46 permissions). The five existing roles keep exactly what they could do: their permission sets are computed from their rank. The new roles are not ranks; on every route that names no permission they count as VIEWER. A person may hold extra job roles (`users.additional_roles`, `project_members.additional_roles`, migration `0266`), and on a project write their instance and project permissions intersect, the rule "the lower of the two roles decides" applied to permissions. Routes admit a new role with `require_permission(Permission.X)` or `require_role(UserRole.X, permission=Permission.X)`; no route does yet. A members-route grant needs every permission of the role granted, and only an administrator gives `RELEASE_MANAGER`, `PROJECT_MANAGER` or `PRODUCT_MANAGER` (owner decision D-17, `permissions.ADMIN_ONLY_GRANTS`); nobody is given `AGENT` through the user or member routes. An MFA policy from QA_LEAD up covers release and product managers. Branch `feat/roles-e00-foundation`; `backend/tests/test_permission_catalogue.py`, `backend/tests/regression/test_permission_guards_hold_both_roles.py`, `backend/tests/regression/test_job_role_assignment_and_mfa.py`, the reworked `backend/tests/regression/test_role_hierarchy_is_five_tiers.py` (five ranks, ten roles), and `backend/tests/test_security_role_access_matrix.py` with the tracked `security_role_access_matrix.json`, which lists the roles each role-gated route admits.
- Roles, assigning them: Settings › Users (Edit, Add User, Invite User) and Members & access (**Extra roles** under a member) offer the ten roles with a one-line description each and an **Extra roles** picker; the users, members and invitation APIs carry `additional_roles` (an invitation's extra roles, globally and per project, apply on accept; migration `0266` adds `user_invitations.additional_roles`). A members-route refusal names the permissions the granter lacks (or says only an administrator gives a manager role), a project role caps what its holder may hand out in that project, and Members & access offers a QA lead only the roles they may give. An SSO group or a SCIM group mapped to a job role adds it as an extra role (the highest rank still sets the role; the SSO preview lists the extra roles and their groups). The MFA policy gains **Also require it from** (`required_roles`); its floor must be a rank. A feature flag's role list matches extra roles. `GET /api/v1/me/permissions?project_id=` answers what the caller may read and write in a project, and the SPA's `useMyPermissions().can(...)` reads it. Dev-login and the dev seed gain the four job roles (one developer is also a release manager); `seed_data.py` seeds a TESTER too (D-8). `backend/tests/regression/test_extra_roles_assignment.py`, `backend/tests/regression/test_job_roles_through_sso_scim_mfa_flags.py`, `backend/tests/test_me_permissions.py`, `backend/tests/test_role_access_runtime.py` (real requests as each role against the access matrix), `backend/tests/test_spa_permission_parity.py`, `backend/tests/regression/test_migration_0266_additional_roles.py`; `test_mfa.py` and `test_sso_role_preview.py` expect the two new response fields; `test_timeline_note_routes.py` expects the one rank helper (`rank_index`) where it pinned `_ROLE_ORDER.index`; the role crawl (`role-crawl-tester-viewer.spec.ts`) covers the job roles, `every-role-wording.spec.ts` checks the backend-unreachable banner as every role a person can hold and the viewer sentences as each job role, and `integration/test_scim_groups_postgres.py` and `integration/test_invitations_postgres.py` cover job-role groups and invited extra roles; frontend `UserManagementPage.extraRoles`, `ProjectMembersTab.extraRoles`, `lib/roles` tests.
- Quality gate: `backend.single-role-rank-helper` fails on `_ROLE_ORDER.index(...)`, a literal list of three or more roles, or a role compared with VIEWER outside `app/core/permissions.py` and `app/core/deps.py`; every rank lookup goes through `permissions.rank_index`. The write-route guard accepts `require_permission(`.
- JSON and report uploads persist a PostgreSQL receipt before writing the queued payload or publishing a task. Clients can recover the same upload through `Idempotency-Key`, status polling, or an authorized retry of the retained receipt.
- Delivery verification checks mounted rule inventories, targeted source security, rendered infrastructure and all Kubernetes application image identities. An optional disposable release gate verifies both worker roles, durable completion and correlated telemetry.
- Optional API objectives report scoped availability, latency, error budgets and measurement coverage. Retained SQL cohorts expose downstream and AI completion, including missed deadlines, and a disposable benchmark measures telemetry capacity.
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ Nothing to install? Replay real screens in the browser with the [guided tours](h
- **Test management**: authored test cases, plans and strategies with a reviewed lifecycle, linked to the executions they describe.
- **Reports and sharing**: summary reports, PDF and Excel exports, evidence bundles, share links and compliance packs, with an optional human-review gate before AI-generated content is distributed.
- **Integrations**: Jira, GitHub and GitLab (checks and merge-request notes), Slack, Microsoft Teams and email notifications, outbound webhooks, and knowledge sources for retrieval.
- **Access control**: five roles (`VIEWER`, `TESTER`, `QA_ENGINEER`, `QA_LEAD`, `ADMIN`) plus project membership, API keys, MFA, SAML and OpenID Connect single sign-on, and SCIM provisioning.
- **Access control**: five ranked roles (`VIEWER`, `TESTER`, `QA_ENGINEER`, `QA_LEAD`, `ADMIN`), job roles for release teams (`RELEASE_MANAGER`, `PROJECT_MANAGER`, `PRODUCT_MANAGER`, `DEVELOPER`) and an `AGENT` role for AI agents, each a set of permissions; plus project membership, API keys, MFA, SAML and OpenID Connect single sign-on, and SCIM provisioning.

Some features are off by default and are turned on per installation or project with feature flags; the in-app guide (`/docs` on your instance) describes each one.

Expand Down
1 change: 1 addition & 0 deletions THREAT_MODEL.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ absent from the table above, which is how it went unnoticed.
| **JWT** | Per-user session, short-lived (configurable expiry) | Signed with `JWT_SECRET_KEY`, refresh tokens in Postgres (hashes only); in the browser, `localStorage` (see below) |
| **API keys** | Per-user or per-project, long-lived | SHA-256 hash stored in Postgres, raw key shown once at creation |
| **Role hierarchy** | VIEWER < TESTER < QA_ENGINEER < QA_LEAD < ADMIN | Stored as `String(20)` on `users` and `project_members` |
| **Job roles** | RELEASE_MANAGER, PROJECT_MANAGER, PRODUCT_MANAGER, DEVELOPER, AGENT | Not ranks: each counts as VIEWER on a guard that names no permission (fail closed) and holds an explicit permission set (`backend/app/core/permissions.py`); extra job roles in `additional_roles`; on a project write the instance and project permissions intersect |
| **Project scope** | Every data query is filtered by project membership | `require_project_access()` dependency, `get_accessible_project_ids()` returns None for ADMIN (no filter) |
| **Dual auth** | Endpoints accept either JWT or API key | `get_current_user_or_api_key()` tries JWT first, then API key |
| **MFA** | Optional per user, enforceable by policy | TOTP (RFC 6238) seed per user with one-time recovery codes; enrolling, disabling and reissuing codes are audited |
Expand Down
6 changes: 4 additions & 2 deletions architecture/DEVELOPER_GUIDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@ API endpoint, a pipeline agent, a UI page and a migration.

## 1. Quality gates — the invariant ratchets

`make quality-gate` runs `scripts/quality_gate.py`, which enforces **68 guards**.
`make quality-gate` runs `scripts/quality_gate.py`, which enforces **70 guards**.
26 are *ratchets*: pre-existing violations are baselined in
`scripts/quality-gate-baselines/` and the count can only shrink. New violations
fail CI. The other 42 ship at zero with **no baseline file at all** — those are
fail CI. The other 44 ship at zero with **no baseline file at all** — those are
absolute rules, not ratchets, and are marked **†** in the tables below. Know
these before you write code.

Expand All @@ -68,6 +68,7 @@ and `scripts/test_quality_gate.py` fails if the two drift apart.
| `backend.analytics-epoch-bump` † | a function that commits an analytics mutation — a registered base writer in `_ANALYTICS_MUTATION_BASES` (run/release/live/deletion/reset writers, plus the defect, active release-gate policy, quarantine-request, AI-analysis and failure-cluster writers the cached dashboard and hours-saved model read; the canonical case lifecycle the coverage map reads: suite move, bulk move, retirement, restore on re-sighting, suite rename; and the systemic cluster sweep `/analytics/systemic-clusters` reads), a source-discovered write (`update`/`delete`/`insert` of `TestRun`/`TestCase`, a new `TestRun`/`TestCase` row, an assignment to `status`/`primary_release_id`/`primary_suite_name`/`is_active` on such a row or `Project`, to `status`/`test_suite_id` on a `CanonicalTestCase`, or to `name` on a `TestSuite`), or a caller that reaches one without committing — and does not `await` `bump_analytics_epoch` / `bump_analytics_epochs` / `invalidate_analytics_cache` (resolved by import to `app.services.cache_service`) **after** the commit; or bumps before it, in `except`/`finally`, in a dead branch, or through `create_task`. A `get_db` route handler commits again when it returns, so it must commit explicitly before its bump. backend/scripts is not scanned | Analytics cache keys carry a per-project epoch (VIZ-212); a mutation that commits without bumping it leaves every cached report stale until TTL. After the commit: `await bump_analytics_epoch(project_id)`, or `bump_analytics_epochs(ids)` once per project for a sweep. A new primitive writer of what analytics read goes in the registry. A path that changes nothing analytics reads opts out with `# analytics-epoch: none — <reason>` |
| `backend.project-scope-guard-placement` † | an access check nested inside an `if not project_id` branch — the caller who *does* name a project skips it | Call `resolve_project_scope(db, user, project_id)` unconditionally; it 403s a non-admin naming a project they cannot reach |
| `backend.write-routes-state-a-role` † | a POST/PUT/PATCH/DELETE route in `backend/app/routers` with no role: no `require_role` / `require_project_role` / `require_instance_admin` in its decorator, signature or router, and no `holds_role_for_project_write` check in its body, so a VIEWER can write through it | Add `Depends(require_role(UserRole.X))`; only when no role applies (the caller's own data, a read-shaped POST, a machine credential, a sign-in step) list it in `_ROLE_FREE_WRITE_ROUTES` with the reason |
| `backend.single-role-rank-helper` † | outside `app/core/permissions.py` and `app/core/deps.py`: `_ROLE_ORDER.index(...)`, a literal list of three or more `UserRole` members, or a role compared with VIEWER — another copy of the ladder, where a job role (RELEASE_MANAGER, PROJECT_MANAGER, PRODUCT_MANAGER, DEVELOPER, AGENT) would rank differently or slip past a deny check | Rank with `app.core.permissions.rank_index(role)` (job roles count as VIEWER), use `permissions.LADDER` for the order, compare `rank_index(role) == 0` instead of `role == VIEWER` |
| `backend.model-imports-resolve` † | `from app.models.postgres import X` where `X` is not a real class | Fix the class name (`perf_baselines` is `PerfBaseline`, not `PerformanceBaseline`). A function-local import of a typo'd model is invisible until it runs, and a broad `except` turns it into a warning |
| `backend.managed-test-case-status-single-writer` † | writing `ManagedTestCase.status` outside `services/test_case_lifecycle_service.py`, including status-capable generic `setattr` helpers | Call the lifecycle `transition(...)` owner so role/reason checks, immutable versions, audit rows and metrics remain one atomic unit. Constructors may set only the initial state |
| `backend.status-enum-vocab` † | filtering an enum-backed string column — any column whose `Mapped[...]` or default names an enum (`status`, `role`, `channel`, `schedule`, ...) — with hand-written string literals | Build the filter from the enum (`FlakyQuarantineStatus.QUARANTINED.value`). A mismatched vocabulary matches nothing, silently and forever — FIX-002 had the Fixer selecting zero candidates on every run while reporting success |
Expand Down Expand Up @@ -121,6 +122,7 @@ fails if a *second* deleter appears.
| `frontend.ai-word-allowlisted` † | a hard-coded "AI" (the word, case-sensitive) in a string literal or JSX text of `frontend/src/**/*.tsx` (tests excluded) that is not on the reviewed allow-list. "AI" claims a language model answered; the default install has no model (D-13) | Say what produced the result: `producedByWord()` / `engineLabel()` from `components/ai/AISuggestion` for an engine-dependent label, or a neutral word ("Triage result", "Verdict"). A true use (shown only when a model answered, or a feature only a model can do) goes in `_AI_WORD_ALLOWED` as (relpath, the whole text) with a one-line reason; an entry that matches nothing fails. `.ts` copy models are not scanned |
| `frontend.ingest-formats-match-backend` † | the upload dropdown (`reportUploadService.ts::SUPPORTED_FORMATS`) advertising a format `/ingest/file` rejects, the backend accepting a parser the UI never offers, or either registry becoming unparseable by the guard | Add or remove the format on **both** sides of the language boundary — the `SUPPORTED_FORMATS` array (value + label) and the `ReportFormat` union in `reportUploadService.ts`, and `_SUPPORTED_FORMATS` in `routers/ingest.py` (a new backend parser also needs `_detect_format` wired). If a refactor changes a registry's source shape, update the guard parser in the same change; otherwise CI fails instead of silently disabling parity enforcement |
| `frontend.sdk-symbols-fresh` † | `frontend/src/components/live/sdkSymbols.json` differing from what `scripts/gen_sdk_symbols.py` reads out of `client/go` and `client/js` (the `/live` "Connect a test runner" snippet test checks every Go and JavaScript identifier against it) | Run `python scripts/gen_sdk_symbols.py` after an SDK change and commit the JSON, then `npx vitest run src/components/live/sdkSnippets.test.ts` in `frontend/` and fix any snippet that names a symbol the SDK no longer has |
| `frontend.single-role-order` † | outside `src/lib/roles.ts`, `src/types/permissions.ts` and `src/hooks/usePermissions.ts` (the shell's rank-only hook): `ROLE_ORDER.indexOf(...)` or a literal list of the five ranks — another copy of the ladder, where a job role ranks below VIEWER and the SPA offers or hides controls differently from the server | Rank with `roleRank` / `roleAtLeast` from `@/lib/roles` (job roles count as VIEWER); use `RANK_ROLES` from `@/types/permissions` for the order |

**Details and forms open in the page** (`frontend.no-page-modals`, W27). An
item's detail docks beside its list (`MasterDetail` + `DetailPane`); a form
Expand Down
41 changes: 41 additions & 0 deletions architecture/SECURITY.md
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,47 @@ Deploy this change to **all read-serving replicas before relying on the new
authorization path**; until then, an older replica can still accept its legacy
Redis membership cache.

### Roles, ranks and permissions (enterprise roles E00)

`backend/app/core/permissions.py` separates **rank** from **role**:

- **Five ranks**, `VIEWER < TESTER < QA_ENGINEER < QA_LEAD < ADMIN`. Every
`require_role(X)` compares ranks, and `rank_index` is the only code that
indexes the ladder (the `backend.single-role-rank-helper` and
`frontend.single-role-order` quality-gate guards keep it that way).
- **Job roles** (`RELEASE_MANAGER`, `PROJECT_MANAGER`, `PRODUCT_MANAGER`,
`DEVELOPER`) and `AGENT` are not rungs. Each has a **base rank of VIEWER**:
on a guard that names no permission it gets exactly what a viewer gets, so a
new role never gains a write through an old guard by accident (fail closed).
- A **permission catalogue** (46 permissions, each with the rank that grants it
on the ladder and the most an agent may ever hold). Ladder roles' permission
sets are computed from rank, so moving a route from `require_role(X)` to
`require_permission(P)` (with `P`'s rank equal to `X`) answers every ladder
role exactly as before. Job roles' sets are explicit. A permission an agent
may never hold (`AGENT_FORBIDDEN`: sign, decide, override, administer,
delete, mint keys) is refused to an `AGENT` whatever it was granted.
- **Extra roles** (`users.additional_roles`, `project_members.additional_roles`)
add a job role's permissions; only the primary role gives the rank.
- **The lower of the two decides**: on a write into a project the caller's
instance permissions and project permissions **intersect**; a read uses the
project permissions. `enforce_project_role_floor` records every
`(rank, permission)` pair a route's guards name and holds a member to all of
them.
- **Grant ceiling**: a non-admin may give a project role or extra role only
when every permission of it is in their own effective permissions on that
project; `RELEASE_MANAGER`, `PROJECT_MANAGER` and `PRODUCT_MANAGER`
(`ADMIN_ONLY_GRANTS`) are given only by an administrator whatever the
granter holds; only an administrator changes instance roles; nobody changes
their own; `AGENT` is never given through the user or member routes.

What each of the ten roles may do on every route is a reviewed file,
`backend/tests/security_role_access_matrix.json`, computed from each route's
guards; a pull request that changes any role's access shows as a diff there.
`tests/test_role_access_runtime.py` sends real requests as each role to a
sample of write routes and checks the answers match the file.
`GET /api/v1/me/permissions` tells the SPA what the caller may do in a project
(`useMyPermissions().can(...)`); the server stays the authority.


### The ratchet's blind spot — ids that don't arrive in the path

Expand Down
2 changes: 2 additions & 0 deletions backend/app/bootstrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@
test_management,
timeline_notes,
insights,
me_permissions,
run_cadences,
users,
value_metric_assumptions,
Expand Down Expand Up @@ -254,6 +255,7 @@
subject_erasure_requests.router,
users.router,
users.projects_router,
me_permissions.router, # Enterprise roles E00-S04: GET /api/v1/me/permissions
api_keys.router,
value_metrics.router,
value_metric_assumptions.router, # PMF US-12.1: per-project hours-saved assumptions
Expand Down
Loading
Loading