Files
tenant-registry/internal/authz/catalogue.go
Sharang ParnerkarandClaude Opus 5.5 f4a9f937fb
ci / shared (pull_request) Successful in 11s
ci / test (pull_request) Failing after 6m10s
ci / image (pull_request) Skipped
fix(authz): bundle labels as the portal names them; last admin message
The catalogue named CXO "Geschäftsleitung" and OWNER "Inhaber des
Arbeitsbereichs", while the portal shows "Geschäftsführung" and
"Inhaberschaft". The catalogue now takes the portal's names (version
2026-11-12.1), which also keeps the role "Geschäftsführung" apart from
the company function "Geschäftsleitung" of the role dataset.

The last-admin refusal named only IT_ADMIN; the guard holds for OWNER
too, so the message now says "the last administrator (IT_ADMIN or
OWNER)".

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_014aRnCGqELxoix5TfpX8Ejf
2026-11-12 10:59:15 +01:00

330 lines
18 KiB
Go

// Package authz is the catalogue of rights of the platform (RBAC plan,
// approved 2026-11-10): capabilities, the bundles that grant them and the
// position presets of the two company variants.
//
// - A capability is what the software lets someone do, named like an API
// key scope: "<product>:<resource>.<action>" (internal/scopes). Each
// service checks capabilities, never role names.
// - A bundle is the one sign-in role a person holds (org_roles). It grants
// a set of capabilities. A person holds exactly one bundle and may be
// given individual capabilities on top; custom bundles are an
// enterprise feature for later.
// - A position proposes a bundle and the company functions (internal/roles)
// that usually go with it, for a small company (variant S) or a larger
// one (variant L). It grants nothing itself.
//
// The registry, the portal and Werkmeister decide access from it (steps 2
// to 4). Today's six bundles reproduce the role checks those services had
// on 2026-11-10 (pinned in tests); the seven new ones are assignable since
// step 4.
package authz
import "strings"
// Version names this catalogue; it changes with every change of a
// capability, bundle or position.
const Version = "2026-11-12.1"
// Products a capability belongs to.
const (
Portal = "portal"
Werkmeister = "werkmeister"
Registry = "registry"
)
// Capability is one right.
type Capability struct {
Code string `json:"code"`
Product string `json:"product"`
Label string `json:"label"`
// Admin: granting it on its own needs a second person (four-eyes), and
// nobody grants a capability they do not hold.
Admin bool `json:"admin,omitempty"`
}
// Bundle is a sign-in role.
type Bundle struct {
Code string `json:"code"`
Label string `json:"label"`
// Assignable: a person may be given it.
Assignable bool `json:"assignable"`
Capabilities []string `json:"capabilities"`
}
// Variants of company positions.
const (
VariantSmall = "S" // few people, each covering many functions
VariantLarge = "L" // one position per function, with deputies
)
// Position is a preset: a bundle and the functions that usually go with it.
type Position struct {
Code string `json:"code"`
Variant string `json:"variant"`
Label string `json:"label"`
Bundle string `json:"bundle"`
Functions []string `json:"functions"`
}
// The capabilities. Portal surfaces are "portal:<surface>.view"; what the
// portal lets one change on a surface has its own capability.
var Capabilities = []Capability{
// ── Portal: surfaces (src/lib/session.ts surfaceRoles) ────────────────
{Code: "portal:dashboard.view", Product: Portal, Label: "Übersicht ansehen"},
{Code: "portal:products.view", Product: Portal, Label: "Produkte ansehen"},
{Code: "portal:projects.view", Product: Portal, Label: "Projekte ansehen"},
{Code: "portal:profile.view", Product: Portal, Label: "Unternehmensprofil ansehen"},
{Code: "portal:roles.view", Product: Portal, Label: "Verantwortliche und Befugnisse ansehen"},
{Code: "portal:security.view", Product: Portal, Label: "Sicherheitsereignis melden"},
{Code: "portal:settings.view", Product: Portal, Label: "Organisation verwalten", Admin: true},
{Code: "portal:users.view", Product: Portal, Label: "Team verwalten", Admin: true},
{Code: "portal:api-keys.view", Product: Portal, Label: "API-Schlüssel verwalten", Admin: true},
{Code: "portal:integrations.view", Product: Portal, Label: "Integrationen verwalten", Admin: true},
{Code: "portal:billing.view", Product: Portal, Label: "Abrechnung ansehen"},
{Code: "portal:audit.view", Product: Portal, Label: "Audit-Log ansehen"},
{Code: "portal:support.view", Product: Portal, Label: "Hilfe und Support"},
{Code: "portal:catalog.view", Product: Portal, Label: "Produktkatalog ansehen"},
{Code: "portal:documents.view", Product: Portal, Label: "Dokumente ansehen"},
{Code: "portal:store.view", Product: Portal, Label: "Dokumentenablage ansehen"},
{Code: "portal:contracts.view", Product: Portal, Label: "Vertragsunterlagen ansehen"},
{Code: "portal:infra.view", Product: Portal, Label: "Verwaltete Infrastruktur ansehen"},
{Code: "portal:studio.view", Product: Portal, Label: "Studio"},
// ── Portal: changes ─────────────────────────────────────────────────────
{Code: "portal:products.write", Product: Portal, Label: "In den Produkten arbeiten"},
{Code: "portal:infra.write", Product: Portal, Label: "Änderungen an der verwalteten Infrastruktur beantragen", Admin: true},
{Code: "portal:profile.edit", Product: Portal, Label: "Unternehmensprofil bearbeiten"},
{Code: "portal:store.upload", Product: Portal, Label: "Dokumente in die Ablage hochladen"},
{Code: "portal:projects.edit", Product: Portal, Label: "Projekte anlegen und ändern"},
{Code: "portal:documents.chunks", Product: Portal, Label: "Gelesene Abschnitte eines Dokuments ansehen"},
{Code: "portal:documents.reread", Product: Portal, Label: "Dokument erneut lesen lassen"},
// ── Werkmeister (internal/rbac) ─────────────────────────────────────────
{Code: "werkmeister:process.view", Product: Werkmeister, Label: "Vorgänge ansehen"},
{Code: "werkmeister:run.start", Product: Werkmeister, Label: "Vorgänge starten"},
{Code: "werkmeister:task.work", Product: Werkmeister, Label: "Schritte bearbeiten"},
{Code: "werkmeister:process.edit", Product: Werkmeister, Label: "Abläufe bearbeiten"},
{Code: "werkmeister:process.publish", Product: Werkmeister, Label: "Abläufe veröffentlichen"},
{Code: "werkmeister:connection.manage", Product: Werkmeister, Label: "Verbindungen verwalten", Admin: true},
{Code: "werkmeister:documents.read", Product: Werkmeister, Label: "Gelesene Produktdokumente ansehen"},
// ── Registry (internal/server) ──────────────────────────────────────────
{Code: "registry:members.manage", Product: Registry, Label: "Mitglieder einladen und verwalten", Admin: true},
{Code: "registry:api-keys.manage", Product: Registry, Label: "API-Schlüssel anlegen und widerrufen", Admin: true},
{Code: "registry:pruefwerk.settings", Product: Registry, Label: "Prüfwerk-Einstellungen ändern"},
{Code: "registry:services.read", Product: Registry, Label: "Verwaltete Dienste ansehen"},
{Code: "registry:notify.documents", Product: Registry, Label: "Benachrichtigung über veröffentlichte Dokumente"},
{Code: "registry:notify.findings", Product: Registry, Label: "Benachrichtigung über neue Befunde"},
{Code: "registry:intake.report", Product: Registry, Label: "Sicherheitsereignisse melden und eigene Meldungen sehen"},
}
// Capability groups the bundles share.
var (
adminPortal = []string{"portal:dashboard.view", "portal:products.view", "portal:projects.view", "portal:profile.view", "portal:roles.view",
"portal:security.view", "portal:settings.view", "portal:users.view", "portal:api-keys.view", "portal:integrations.view", "portal:billing.view",
"portal:audit.view", "portal:support.view", "portal:catalog.view", "portal:documents.view", "portal:store.view", "portal:contracts.view",
"portal:infra.view", "portal:studio.view", "portal:products.write", "portal:infra.write", "portal:profile.edit", "portal:store.upload",
"portal:projects.edit", "portal:documents.chunks", "portal:documents.reread"}
adminWerkmeister = []string{"werkmeister:process.view", "werkmeister:run.start", "werkmeister:task.work", "werkmeister:process.edit",
"werkmeister:process.publish", "werkmeister:connection.manage", "werkmeister:documents.read"}
adminRegistry = []string{"registry:members.manage", "registry:api-keys.manage", "registry:pruefwerk.settings", "registry:services.read",
"registry:notify.documents", "registry:notify.findings", "registry:intake.report"}
// Everyone in a workspace sees the overview, who decides what, help,
// and reports security events (A1 AS-5).
member = []string{"portal:dashboard.view", "portal:roles.view", "portal:security.view", "portal:support.view", "registry:intake.report"}
)
func join(groups ...[]string) []string {
out := []string{}
for _, g := range groups {
out = append(out, g...)
}
return out
}
// Bundles: today's six first, as the registry, the portal and Werkmeister
// grant them on 2026-11-10; then the new ones of variant L and EXTERNAL.
var Bundles = []Bundle{
{Code: "IT_ADMIN", Label: "IT-Administration", Assignable: true, Capabilities: join(adminPortal, adminWerkmeister, adminRegistry)},
// OWNER has IT_ADMIN's rights; the portal shows it like IT_ADMIN (decided
// 2026-11-10). Bundle labels are the portal's German role names, so the
// role "Geschäftsführung" (CXO) stays apart from the company function
// "Geschäftsleitung" (r1.geschaeftsleitung) of the role dataset.
{Code: "OWNER", Label: "Inhaberschaft", Assignable: true, Capabilities: join(adminPortal, adminWerkmeister, adminRegistry)},
{Code: "CXO", Label: "Geschäftsführung", Assignable: true, Capabilities: join(member, []string{
"portal:products.view", "portal:projects.view", "portal:profile.view", "portal:billing.view", "portal:audit.view", "portal:catalog.view",
"portal:documents.view", "portal:store.view", "portal:contracts.view", "portal:infra.view", "portal:studio.view",
"portal:profile.edit", "portal:store.upload", "portal:projects.edit",
"werkmeister:process.view",
"registry:services.read", "registry:notify.documents", "registry:notify.findings"})},
// FINANCE stays a portal-only bundle (decided 2026-11-10).
{Code: "FINANCE", Label: "Finanzen", Assignable: true, Capabilities: join(member, []string{
"portal:projects.view", "portal:profile.view", "portal:billing.view", "portal:documents.view", "portal:store.view", "portal:contracts.view",
"registry:pruefwerk.settings", "registry:notify.documents"})},
{Code: "LEGAL", Label: "Recht", Assignable: true, Capabilities: join(member, []string{
"portal:products.view", "portal:projects.view", "portal:profile.view", "portal:audit.view", "portal:documents.view", "portal:store.view",
"portal:contracts.view", "portal:studio.view", "portal:profile.edit", "portal:store.upload", "portal:projects.edit",
"werkmeister:process.view",
"registry:notify.documents", "registry:notify.findings"})},
{Code: "USER", Label: "Mitarbeitende", Assignable: true, Capabilities: join(member, []string{
"portal:products.view", "portal:projects.view", "portal:studio.view", "portal:products.write",
"werkmeister:process.view", "werkmeister:run.start", "werkmeister:task.work"})},
// ── New (all taken 2026-11-10; assignable since step 4) ────────────────
{Code: "PSIRT", Label: "Produktsicherheit (PSIRT)", Assignable: true, Capabilities: join(member, []string{
"portal:products.view", "portal:projects.view", "portal:documents.view", "portal:studio.view",
"werkmeister:process.view", "werkmeister:run.start", "werkmeister:task.work",
"registry:notify.findings"})},
{Code: "DEVELOPMENT", Label: "Entwicklung", Assignable: true, Capabilities: join(member, []string{
"portal:products.view", "portal:projects.view", "portal:studio.view", "portal:products.write",
"werkmeister:process.view", "werkmeister:run.start", "werkmeister:task.work",
"registry:notify.findings"})},
{Code: "QUALITY", Label: "Qualität und Konformität", Assignable: true, Capabilities: join(member, []string{
"portal:products.view", "portal:projects.view", "portal:profile.view", "portal:documents.view", "portal:store.view", "portal:contracts.view",
"portal:audit.view", "portal:studio.view", "portal:profile.edit", "portal:projects.edit", "portal:store.upload",
"werkmeister:process.view", "werkmeister:task.work",
"registry:notify.documents"})},
{Code: "PRIVACY", Label: "Datenschutz", Assignable: true, Capabilities: join(member, []string{
"portal:profile.view", "portal:documents.view", "portal:store.view", "portal:contracts.view", "portal:audit.view", "portal:studio.view",
"portal:profile.edit",
"werkmeister:process.view",
"registry:notify.documents"})},
{Code: "PURCHASING", Label: "Einkauf und Lieferanten", Assignable: true, Capabilities: join(member, []string{
"portal:products.view", "portal:projects.view", "portal:documents.view", "portal:contracts.view", "portal:studio.view",
"werkmeister:process.view", "werkmeister:task.work",
"registry:notify.documents"})},
// AUDITOR reads everything a CXO reads, changes nothing.
{Code: "AUDITOR", Label: "Revision", Assignable: true, Capabilities: join(member, []string{
"portal:products.view", "portal:projects.view", "portal:profile.view", "portal:billing.view", "portal:audit.view", "portal:catalog.view",
"portal:documents.view", "portal:store.view", "portal:contracts.view", "portal:infra.view", "portal:studio.view",
"werkmeister:process.view",
"registry:services.read", "registry:notify.documents"})},
// EXTERNAL: only what the functions they hold bring (step 5); until
// Werkmeister scopes cases to functions, no Werkmeister access at all,
// since process.view would show every case of the workspace.
{Code: "EXTERNAL", Label: "Externer Dienstleister", Assignable: true, Capabilities: []string{"portal:security.view", "portal:support.view", "registry:intake.report"}},
}
// Positions: the presets of the two variants. Proposals, changed per
// person when they are added.
var Positions = []Position{
{Code: "s.geschaeftsfuehrung", Variant: VariantSmall, Label: "Geschäftsführung", Bundle: "CXO",
Functions: []string{"r1.geschaeftsleitung", "r1.freigabestelle", "r1.freigabe_produktaenderung", "r1.vorfallkontakt", "r1.meldeberechtigt", "r1.abschlussverantwortung"}},
{Code: "s.it_technik", Variant: VariantSmall, Label: "IT und Technik", Bundle: "IT_ADMIN",
Functions: []string{"r1.produkt_cybersecurity", "r1.technischer_ansprechpartner", "r1.technischer_produktverantwortlicher", "r1.produktsicherheit", "r1.dokumentenlenkung", "r1.aenderungskoordination"}},
{Code: "s.mitarbeitende", Variant: VariantSmall, Label: "Mitarbeitende", Bundle: "USER", Functions: []string{"r1.massnahmenausfuehrer"}},
{Code: "s.buchhaltung", Variant: VariantSmall, Label: "Buchhaltung", Bundle: "FINANCE", Functions: []string{}},
{Code: "s.externe_beratung", Variant: VariantSmall, Label: "Externe Beratung", Bundle: "EXTERNAL", Functions: []string{"r1.externer_cybersecurity_dienstleister", "r1.fachpruefung"}},
{Code: "l.geschaeftsleitung", Variant: VariantLarge, Label: "Geschäftsleitung", Bundle: "CXO", Functions: []string{"r1.geschaeftsleitung", "r1.freigabestelle", "r1.freigabe_produktaenderung"}},
{Code: "l.it_administration", Variant: VariantLarge, Label: "IT-Administration", Bundle: "IT_ADMIN", Functions: []string{"r1.technischer_ansprechpartner"}},
{Code: "l.produktsicherheit", Variant: VariantLarge, Label: "Produktsicherheit (PSIRT)", Bundle: "PSIRT", Functions: []string{"r1.produkt_cybersecurity", "r1.vorfallkontakt", "r1.meldeberechtigt"}},
{Code: "l.entwicklung", Variant: VariantLarge, Label: "Entwicklung", Bundle: "DEVELOPMENT", Functions: []string{"r1.technischer_produktverantwortlicher", "r1.produktverantwortung", "r1.massnahmenausfuehrer"}},
{Code: "l.qualitaet", Variant: VariantLarge, Label: "Qualität und Konformität", Bundle: "QUALITY",
Functions: []string{"r1.konformitaet", "r1.produktsicherheit", "r1.dokumentenlenkung", "r1.prueffunktion", "r1.abschlussverantwortung"}},
{Code: "l.datenschutz", Variant: VariantLarge, Label: "Datenschutz", Bundle: "PRIVACY", Functions: []string{}},
{Code: "l.einkauf", Variant: VariantLarge, Label: "Einkauf und Lieferanten", Bundle: "PURCHASING", Functions: []string{}},
{Code: "l.recht", Variant: VariantLarge, Label: "Recht", Bundle: "LEGAL", Functions: []string{}},
{Code: "l.revision", Variant: VariantLarge, Label: "Revision", Bundle: "AUDITOR", Functions: []string{}},
{Code: "l.buchhaltung", Variant: VariantLarge, Label: "Buchhaltung", Bundle: "FINANCE", Functions: []string{}},
{Code: "l.mitarbeitende", Variant: VariantLarge, Label: "Mitarbeitende", Bundle: "USER", Functions: []string{"r1.massnahmenausfuehrer"}},
{Code: "l.extern", Variant: VariantLarge, Label: "Externer Dienstleister", Bundle: "EXTERNAL", Functions: []string{"r1.externer_cybersecurity_dienstleister", "r1.fachpruefung"}},
}
var (
capIndex = map[string]Capability{}
bundleIndex = map[string]Bundle{}
)
func init() {
for _, c := range Capabilities {
capIndex[c.Code] = c
}
for _, b := range Bundles {
bundleIndex[b.Code] = b
}
}
// BundleByCode looks a bundle up.
func BundleByCode(code string) (Bundle, bool) {
b, ok := bundleIndex[code]
return b, ok
}
// CapabilityByCode looks a capability up.
func CapabilityByCode(code string) (Capability, bool) {
c, ok := capIndex[code]
return c, ok
}
// Grants reports whether bundle code grants capability cap. An unknown
// bundle grants nothing (fail closed).
func Grants(bundle, capability string) bool {
b, ok := bundleIndex[bundle]
if !ok {
return false
}
for _, c := range b.Capabilities {
if c == capability {
return true
}
}
return false
}
// Assignable lists the codes of the bundles a person may be given, in
// catalogue order.
func Assignable() []string {
out := []string{}
for _, b := range Bundles {
if b.Assignable {
out = append(out, b.Code)
}
}
return out
}
// IsAssignable reports whether a person may be given bundle code.
func IsAssignable(code string) bool {
b, ok := bundleIndex[code]
return ok && b.Assignable
}
// AnyGrants reports whether one of the bundles in roles (as the org_roles
// claim carries them) grants capability.
func AnyGrants(roles []string, capability string) bool {
for _, r := range roles {
if Grants(strings.ToUpper(strings.TrimSpace(r)), capability) {
return true
}
}
return false
}
// Effective is what a person may do: their bundle's capabilities and their
// individual ones that the catalogue knows; nothing else.
func Effective(bundle string, extra []string) map[string]bool {
out := map[string]bool{}
if b, ok := bundleIndex[bundle]; ok {
for _, c := range b.Capabilities {
out[c] = true
}
}
for _, c := range extra {
if _, ok := capIndex[c]; ok {
out[c] = true
}
}
return out
}
// Catalogue is the answer of GET /v1/authz/catalogue.
type Catalogue struct {
Version string `json:"version"`
Capabilities []Capability `json:"capabilities"`
Bundles []Bundle `json:"bundles"`
Positions []Position `json:"positions"`
}
// Current is the catalogue as served.
func Current() Catalogue {
return Catalogue{Version: Version, Capabilities: Capabilities, Bundles: Bundles, Positions: Positions}
}