fix(auth): OWNER has IT_ADMIN's rights in Prüfwerk (#982)
CI / Check (push) Skipped
CI / Detect Changes (pull_request) Skipped
CI / Agent integration (pull_request) Successful in 4m41s
CI / Deploy Agent (pull_request) Skipped
CI / Deploy Dashboard (pull_request) Skipped
CI / Deploy Docs (pull_request) Skipped
CI / Deploy MCP (pull_request) Skipped
CI / Check (pull_request) Successful in 20m36s

OrgRole::parse knew only IT_ADMIN, CXO, FINANCE, LEGAL and USER, so an
OWNER got no access at all. OWNER now parses to its own role with full
access, and what only an administrator may do (manual findings, the git
source, licence decisions) asks OrgRole::is_admin (IT_ADMIN or OWNER).
The other new RBAC bundles still get no access.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Sharang ParnerkarandClaude Opus 5.5 committed 2026-11-12 09:48:24 +01:00
1 parent f5697ff21d
commit ca39450774
11 files changed
+54 -29

No files matched your search

@@ -6,15 +6,15 @@ use axum::http::StatusCode;
use axum::Json;
use compliance_core::models::GitSourceView;
use compliance_core::tenant::OrgRole;
use compliance_core::tenant_ctx::TenantCtx;
use super::dto::{tenant_db, AgentExt};
use super::ApiResponse;
/// Whether the caller may see the git source: IT administrators and support.
/// Whether the caller may see the git source: administrators (IT_ADMIN,
/// OWNER) and support.
fn may_view(tenant: &TenantCtx) -> bool {
tenant.0.staff.is_some() || tenant.0.org_roles.contains(&OrgRole::ItAdmin)
tenant.0.staff.is_some() || tenant.0.is_admin()
}
/// The source without secrets, plus the webhook URL; `data: null` when the
@@ -292,12 +292,12 @@ pub async fn withdraw(
}
/// Whether the requester may change the policy and decide reviews: LEGAL,
/// IT_ADMIN, or BreakPilot support. USER confirms licences but does not
/// an administrator (IT_ADMIN, OWNER), or BreakPilot support. USER confirms licences but does not
/// decide whether they may be used.
fn may_decide(tenant: &TenantCtx) -> bool {
let ctx = &tenant.0;
ctx.api_key.is_none()
&& (ctx.staff.is_some() || ctx.has_any_role(&[OrgRole::Legal, OrgRole::ItAdmin]))
&& (ctx.staff.is_some() || ctx.is_admin() || ctx.has_any_role(&[OrgRole::Legal]))
}
fn refuse_role() -> Refusal {
@@ -306,7 +306,7 @@ fn refuse_role() -> Refusal {
Json(serde_json::json!({
"error": crate::api::role_gate::FORBIDDEN_ROLE,
"access": "read_only",
"needs": ["LEGAL", "IT_ADMIN"],
"needs": ["LEGAL", "IT_ADMIN", "OWNER"],
})),
)
}
@@ -912,6 +912,7 @@ mod tests {
fn legal_and_it_admin_decide_users_do_not() {
assert!(may_decide(&with_roles(vec![OrgRole::Legal])));
assert!(may_decide(&with_roles(vec![OrgRole::ItAdmin])));
assert!(may_decide(&with_roles(vec![OrgRole::Owner])));
assert!(!may_decide(&with_roles(vec![OrgRole::User])));
assert!(!may_decide(&with_roles(vec![OrgRole::Cxo])));
}
@@ -4,7 +4,7 @@
//!
//! Writing findings into a tenant's record is an administrator's action: the
//! tester is given an account in the customer's organisation with the
//! `IT_ADMIN` role.
//! `IT_ADMIN` (or `OWNER`) role.
use std::sync::Arc;
@@ -16,7 +16,6 @@ use mongodb::bson::{doc, oid::ObjectId};
use serde::{Deserialize, Serialize};
use compliance_core::models::{Finding, ScanType};
use compliance_core::tenant::OrgRole;
use compliance_core::tenant_ctx::TenantCtx;
use super::dto::tenant_db;
@@ -84,9 +83,10 @@ pub struct ImportSummary {
pub duplicates: usize,
}
/// Only an organisation's IT administrator writes findings by hand.
/// Only an organisation's administrator (IT_ADMIN, OWNER) writes findings by
/// hand.
fn require_admin(tenant: &TenantCtx) -> Result<(), StatusCode> {
if tenant.0.org_roles.contains(&OrgRole::ItAdmin) {
if tenant.0.is_admin() {
Ok(())
} else {
Err(StatusCode::FORBIDDEN)
@@ -221,7 +221,7 @@ pub async fn import_findings(
#[cfg(test)]
mod tests {
use super::*;
use compliance_core::tenant::{TenantContext, TenantStatus};
use compliance_core::tenant::{OrgRole, TenantContext, TenantStatus};
fn tenant(roles: Vec<OrgRole>) -> TenantCtx {
TenantCtx(TenantContext {
@@ -241,6 +241,7 @@ mod tests {
#[test]
fn only_an_it_admin_writes_findings() {
assert_eq!(require_admin(&tenant(vec![OrgRole::ItAdmin])), Ok(()));
assert_eq!(require_admin(&tenant(vec![OrgRole::Owner])), Ok(()));
assert_eq!(
require_admin(&tenant(vec![OrgRole::User, OrgRole::Cxo])),
Err(StatusCode::FORBIDDEN)
+3 -2
View File
@@ -2,7 +2,7 @@
//!
//! One middleware for every tenant-scoped route, so no handler can forget it:
//!
//! * `IT_ADMIN`, `USER` — read and write.
//! * `OWNER`, `IT_ADMIN`, `USER` — read and write.
//! * `CXO`, `LEGAL` — read only: `GET` / `HEAD` / `OPTIONS`, plus the few
//! `POST` routes that only read ([`READ_ONLY_POSTS`]). `LEGAL` also
//! decides about licences: the licence policy and the legal review
@@ -18,7 +18,8 @@
//! Werkbank runner and admin APIs (their own token middleware), the health
//! check, and support staff who have not chosen a tenant yet.
//!
//! Handlers may still be stricter (manual findings stay `IT_ADMIN`-only).
//! Handlers may still be stricter (manual findings stay for administrators:
//! `IT_ADMIN` and `OWNER`).
//!
//! API keys (tenant-registry ADR 0001) hold no role. They reach only the
//! routes in [`KEY_SCOPES`], each with the scope it names; every other route
@@ -19,6 +19,7 @@ use tower::ServiceExt;
/// Who is calling.
#[derive(Debug, Clone, Copy)]
enum Caller {
Owner,
ItAdmin,
User,
Cxo,
@@ -35,6 +36,7 @@ enum Caller {
fn ctx(caller: Caller) -> Option<TenantContext> {
let roles = match caller {
Caller::Owner => vec![OrgRole::Owner],
Caller::ItAdmin => vec![OrgRole::ItAdmin],
Caller::User => vec![OrgRole::User],
Caller::Cxo => vec![OrgRole::Cxo],
@@ -196,6 +198,7 @@ fn routes() -> Vec<(Method, String, bool)> {
async fn roles_decide_reads_and_writes() {
// (caller, may read, may write)
let matrix = [
(Caller::Owner, true, true),
(Caller::ItAdmin, true, true),
(Caller::User, true, true),
(Caller::Cxo, true, false),
+21 -2
View File
@@ -93,6 +93,9 @@ impl std::fmt::Display for TenantStatus {
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "UPPERCASE")]
pub enum OrgRole {
/// The organisation's owner: in Prüfwerk the same rights as `IT_ADMIN`,
/// as on the rest of the platform.
Owner,
ItAdmin,
Cxo,
Finance,
@@ -108,6 +111,7 @@ impl OrgRole {
/// `CXO`, etc.). Round-trips with the JSON layer.
pub fn parse(s: &str) -> Self {
match s {
"OWNER" => OrgRole::Owner,
"IT_ADMIN" => OrgRole::ItAdmin,
"CXO" => OrgRole::Cxo,
"FINANCE" => OrgRole::Finance,
@@ -116,12 +120,20 @@ impl OrgRole {
_ => OrgRole::Unknown,
}
}
/// Whether the role administers the organisation: `IT_ADMIN` or `OWNER`.
/// What only an administrator may do (manual findings, the git source)
/// asks this, not for `IT_ADMIN` alone.
pub fn is_admin(&self) -> bool {
matches!(self, OrgRole::Owner | OrgRole::ItAdmin)
}
}
/// What an organisation member may do in Prüfwerk, by their org roles
/// (decided 2026-09-30):
///
/// * `IT_ADMIN`, `USER` — [`ProductAccess::Full`]: read and write.
/// * `OWNER`, `IT_ADMIN`, `USER` — [`ProductAccess::Full`]: read and write
/// (`OWNER` added 2026-11-12: it has `IT_ADMIN`'s rights platform-wide).
/// * `CXO`, `LEGAL` — [`ProductAccess::ReadOnly`]: findings, reports, SBOM,
/// evidence and exports, but no change of any kind.
/// * `FINANCE`, or none of these roles — [`ProductAccess::None`].
@@ -145,7 +157,7 @@ impl ProductAccess {
pub fn for_roles(roles: &[OrgRole]) -> Self {
if roles
.iter()
.any(|r| matches!(r, OrgRole::ItAdmin | OrgRole::User))
.any(|r| r.is_admin() || matches!(r, OrgRole::User))
{
Self::Full
} else if roles
@@ -293,6 +305,11 @@ impl TenantContext {
ProductAccess::for_roles(&self.org_roles)
}
/// True if the caller holds `IT_ADMIN` or `OWNER`.
pub fn is_admin(&self) -> bool {
self.org_roles.iter().any(OrgRole::is_admin)
}
/// True if the caller holds at least one of the listed roles.
pub fn has_any_role(&self, roles: &[OrgRole]) -> bool {
self.org_roles.iter().any(|r| roles.contains(r))
@@ -306,6 +323,7 @@ mod tests {
#[test]
fn org_role_parses_known_values() {
assert_eq!(OrgRole::parse("IT_ADMIN"), OrgRole::ItAdmin);
assert_eq!(OrgRole::parse("OWNER"), OrgRole::Owner);
assert_eq!(OrgRole::parse("CXO"), OrgRole::Cxo);
assert_eq!(OrgRole::parse("USER"), OrgRole::User);
}
@@ -338,6 +356,7 @@ mod tests {
use OrgRole::*;
let cases: &[(&[OrgRole], ProductAccess)] = &[
(&[ItAdmin], ProductAccess::Full),
(&[Owner], ProductAccess::Full),
(&[User], ProductAccess::Full),
(&[Cxo], ProductAccess::ReadOnly),
(&[Legal], ProductAccess::ReadOnly),
+6 -6
View File
@@ -5043,8 +5043,8 @@ pub mod license_review {
en: "No licence is known for this component. Confirm its licence first; then it can be approved or rejected.",
};
pub const CONFIRM_FIRST_OTHERS: Text = Text {
de: "Lizenz zuerst bestätigen (IT_ADMIN oder USER)",
en: "Licence to be confirmed first (IT_ADMIN or USER)",
de: "Lizenz zuerst bestätigen (OWNER, IT_ADMIN oder USER)",
en: "Licence to be confirmed first (OWNER, IT_ADMIN or USER)",
};
pub const IN_TARGETS: Text = Text {
de: "in {n} Prüfobjekten",
@@ -5143,12 +5143,12 @@ pub mod license_review {
en: "Licence policy",
};
pub const POLICY_HINT: Text = Text {
de: "Was eine Lizenz braucht, bevor die Komponente verwendet wird. Ändern dürfen LEGAL und IT_ADMIN.",
en: "What a licence needs before the component is used. LEGAL and IT_ADMIN may change it.",
de: "Was eine Lizenz braucht, bevor die Komponente verwendet wird. Ändern dürfen LEGAL, IT_ADMIN und OWNER.",
en: "What a licence needs before the component is used. LEGAL, IT_ADMIN and OWNER may change it.",
};
pub const POLICY_READ_ONLY: Text = Text {
de: "Nur LEGAL und IT_ADMIN können die Richtlinie ändern.",
en: "Only LEGAL and IT_ADMIN can change the policy.",
de: "Nur LEGAL, IT_ADMIN und OWNER können die Richtlinie ändern.",
en: "Only LEGAL, IT_ADMIN and OWNER can change the policy.",
};
pub const POLICY_CATEGORY: Text = Text {
de: "Art der Lizenz",
+2 -2
View File
@@ -35,11 +35,11 @@ What you can do in Prüfwerk depends on your role in the workspace:
| Role | Prüfwerk |
| --- | --- |
| `IT_ADMIN`, `USER` | everything: add targets, run scans, triage findings |
| `OWNER`, `IT_ADMIN`, `USER` | everything: add targets, run scans, triage findings |
| `CXO`, `LEGAL` | read only: view and export findings, reports, SBOM, evidence |
| `FINANCE`, or none of these | no access |
Only `IT_ADMIN` can add or import findings by hand.
Only `IT_ADMIN` and `OWNER` can add or import findings by hand.
## Quick Walkthrough
+1 -1
View File
@@ -38,7 +38,7 @@ Was Sie in Prüfwerk tun können, hängt von Ihrer Rolle im Arbeitsbereich ab:
| Rolle | Prüfwerk |
| --- | --- |
| IT-Administration (`IT_ADMIN`), Benutzer (`USER`) | alles: Prüfobjekte anlegen, prüfen, Befunde bewerten |
| Inhaber (`OWNER`), IT-Administration (`IT_ADMIN`), Benutzer (`USER`) | alles: Prüfobjekte anlegen, prüfen, Befunde bewerten |
| Geschäftsführung (`CXO`), Recht (`LEGAL`) | nur lesen: Befunde, Berichte, Stückliste, Nachweise ansehen und exportieren |
| Finanzen (`FINANCE`) oder keine dieser Rollen | kein Zugriff |
+2 -2
View File
@@ -10,7 +10,7 @@ Two ways to add them, both on a target's details under **Targets**:
- **Import a report**: a tool's report as a whole, in SARIF 2.1.0 or OWASP
ZAP's JSON report.
Only the organisation's administrators (`IT_ADMIN`) can add or import findings.
Only the organisation's administrators (`IT_ADMIN`, `OWNER`) can add or import findings.
A tester working for a customer is invited into that customer's organisation
with that role.
@@ -59,4 +59,4 @@ curl -X POST "$AGENT/api/v1/targets/$TARGET/findings/import?format=sarif&kind=pe
`format` is `sarif` or `zap`; `kind` is `pentest` or `dast`. The import answers
with `{"total": …, "imported": …, "duplicates": …}`. A document that is not
the named format is refused with 422, and a user without `IT_ADMIN` with 403.
the named format is refused with 422, and a user without `IT_ADMIN` or `OWNER` with 403.
+3 -3
View File
@@ -231,7 +231,7 @@ Copyleft-licensed dependencies can require you to release your source code under
### Confirming a license
Where the scan finds no license (**Unknown**) or a wrong one, people with the
IT_ADMIN or USER role can confirm the license themselves; CXO and LEGAL can
OWNER, IT_ADMIN or USER role can confirm the license themselves; CXO and LEGAL can
read the confirmations (LEGAL decides about them in the
[legal review](#license-policy-and-legal-review)).
@@ -285,9 +285,9 @@ announced period (60 days unless changed) is listed in advance.
The default policy forbids nothing: copyleft, bought and unknown licenses
of shipped components need a review, everything else is allowed. Only the
LEGAL and IT_ADMIN roles can change the policy; everyone else can read it.
LEGAL, IT_ADMIN and OWNER roles can change the policy; everyone else can read it.
**The review.** People with the **LEGAL** role (and IT_ADMIN) decide the
**The review.** People with the **LEGAL** role (and IT_ADMIN or OWNER) decide the
components *Zur Prüfung*:
1. Click **Freigeben** in a row, or tick several rows and click