feat(authz): the new bundles are assignable (RBAC step 4)
ci / shared (pull_request) Successful in 12s
ci / test (pull_request) Successful in 6m6s
ci / image (pull_request) Skipped

PSIRT, DEVELOPMENT, QUALITY, PRIVACY, PURCHASING, AUDITOR and EXTERNAL
can be given to a member (catalogue 2026-11-11.1). Invitations and role
changes accept exactly the catalogue's assignable bundles.

The registry's own checks read the catalogue instead of role lists:
notification recipients, managed services and Prüfwerk settings. For
today's six bundles nothing changes (pinned against the 2026-11-10
tables); AUDITOR now reads managed services, and the new bundles get
the mails their capabilities name. Individual capabilities still do not
count in the registry.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_014aRnCGqELxoix5TfpX8Ejf
This commit is contained in:
Sharang ParnerkarandClaude Opus 5.5 committed 2026-11-11 21:29:33 +01:00
1 parent c18f0dc945
commit dc44eb22bb
13 files changed
+224 -110

No files matched your search

+45 -16
View File
@@ -13,16 +13,17 @@
// that usually go with it, for a small company (variant S) or a larger
// one (variant L). It grants nothing itself.
//
// Step 1 of the plan: the catalogue only. Nothing reads it to decide access
// yet; the today's bundles reproduce the role checks of the registry, the
// portal and Werkmeister as they stand (pinned in tests), so moving the
// services onto it (step 2) changes nobody's rights. The new bundles are
// defined but not assignable until step 4.
// 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-10.1"
const Version = "2026-11-11.1"
// Products a capability belongs to.
const (
@@ -45,8 +46,7 @@ type Capability struct {
type Bundle struct {
Code string `json:"code"`
Label string `json:"label"`
// Assignable: a person may be given it. The new bundles become
// assignable with the team and setup UI (step 4).
// Assignable: a person may be given it.
Assignable bool `json:"assignable"`
Capabilities []string `json:"capabilities"`
}
@@ -165,31 +165,31 @@ var Bundles = []Bundle{
"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 with step 4) ─────────────────
{Code: "PSIRT", Label: "Produktsicherheit (PSIRT)", Capabilities: join(member, []string{
// ── 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", Capabilities: join(member, []string{
{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", Capabilities: join(member, []string{
{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", Capabilities: join(member, []string{
{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", Capabilities: join(member, []string{
{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", Capabilities: join(member, []string{
{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",
@@ -197,7 +197,7 @@ var Bundles = []Bundle{
// 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", Capabilities: []string{"portal:security.view", "portal:support.view", "registry:intake.report"}},
{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
@@ -267,6 +267,35 @@ func Grants(bundle, capability string) bool {
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 {
+9 -7
View File
@@ -46,16 +46,18 @@ func TestTheCatalogueHoldsTogether(t *testing.T) {
}
}
}
// Today's six are assignable; the new ones wait for step 4.
for _, code := range []string{"IT_ADMIN", "OWNER", "CXO", "FINANCE", "LEGAL", "USER"} {
if b, _ := BundleByCode(code); !b.Assignable {
// All thirteen are assignable since step 4, in catalogue order.
all := []string{"IT_ADMIN", "OWNER", "CXO", "FINANCE", "LEGAL", "USER", "PSIRT", "DEVELOPMENT", "QUALITY", "PRIVACY", "PURCHASING", "AUDITOR", "EXTERNAL"}
if got := Assignable(); !slices.Equal(got, all) {
t.Errorf("assignable %v", got)
}
for _, code := range all {
if !IsAssignable(code) {
t.Errorf("%s is not assignable", code)
}
}
for _, code := range []string{"PSIRT", "DEVELOPMENT", "QUALITY", "PRIVACY", "PURCHASING", "AUDITOR", "EXTERNAL"} {
if b, ok := BundleByCode(code); !ok || b.Assignable {
t.Errorf("%s: missing, or assignable before step 4", code)
}
if IsAssignable("NOBODY") || IsAssignable("") {
t.Error("an unknown bundle is assignable")
}
}
+4 -8
View File
@@ -5,11 +5,11 @@ import (
"errors"
"net/http"
"net/mail"
"regexp"
"strings"
"time"
"git.breakpilot.com/platform/tenant-registry/internal/authn"
"git.breakpilot.com/platform/tenant-registry/internal/authz"
"git.breakpilot.com/platform/tenant-registry/internal/keycloak"
"git.breakpilot.com/platform/tenant-registry/internal/store"
)
@@ -23,11 +23,6 @@ import (
// exists. Service clients are gated per route group by AUTHZ_RULES
// (members = tenants.read, invites = tenants.write).
// roleRE bounds the org_roles value written for a new user. It is a
// Keycloak user attribute the portal projects into the token, not a role
// model the registry owns — any upper-snake identifier is accepted.
var roleRE = regexp.MustCompile(`^[A-Z][A-Z0-9_]{1,31}$`)
// defaultInviteRole is written when the invite carries no role. The first
// admin gets IT_ADMIN from CreateOrgAndInvite; everyone else is a USER
// unless the portal says otherwise.
@@ -151,8 +146,9 @@ func (s *Server) inviteTenantMember(w http.ResponseWriter, r *http.Request) {
if in.Role == "" {
in.Role = defaultInviteRole
}
if !roleRE.MatchString(in.Role) {
writeError(w, http.StatusBadRequest, "invalid_role", "role must match ^[A-Z][A-Z0-9_]{1,31}$")
// The role is a bundle of the rights catalogue a person may be given.
if !authz.IsAssignable(in.Role) {
writeError(w, http.StatusBadRequest, "invalid_role", "role must be one of "+strings.Join(authz.Assignable(), ", "))
return
}
+19
View File
@@ -1,7 +1,9 @@
package server_test
import (
"fmt"
"net/http"
"strings"
"testing"
"git.breakpilot.com/platform/tenant-registry/internal/keycloak"
@@ -157,6 +159,7 @@ func TestInviteTenantMember_validation(t *testing.T) {
{"missing email", map[string]any{}, http.StatusBadRequest, "invalid_email"},
{"display-name email", map[string]any{"email": "Bob <bob@acme.test>"}, http.StatusBadRequest, "invalid_email"},
{"bad role", map[string]any{"email": "x@acme.test", "role": "not a role"}, http.StatusBadRequest, "invalid_role"},
{"no bundle of the catalogue", map[string]any{"email": "x@acme.test", "role": "PROJECT_LEAD"}, http.StatusBadRequest, "invalid_role"},
{"long name", map[string]any{"email": "x@acme.test", "first_name": string(make([]byte, 101))}, http.StatusBadRequest, "invalid_name"},
}
for _, c := range cases {
@@ -223,3 +226,19 @@ func TestCreateTenant_storesAdminEmail(t *testing.T) {
}
})
}
// RBAC step 4: the new bundles can be given on invitation.
func TestInviteTenantMember_newBundles(t *testing.T) {
eachStore(t, func(t *testing.T, h *testHarness) {
h.kcMock.Members["acme"] = []keycloak.OrgMember{}
for i, role := range []string{"psirt", "AUDITOR", "EXTERNAL"} {
email := fmt.Sprintf("new%d@acme.test", i)
if resp, raw := h.do(http.MethodPost, "/v1/tenants/"+h.tenant.ID+"/invites", map[string]any{"email": email, "role": role}); resp.StatusCode != http.StatusAccepted {
t.Fatalf("%s: %d %s", role, resp.StatusCode, raw)
}
if got := h.kcMock.Invites[len(h.kcMock.Invites)-1].Role; got != strings.ToUpper(role) {
t.Errorf("%s: written as %q", role, got)
}
}
})
}
+12 -20
View File
@@ -7,6 +7,7 @@ import (
"strings"
"time"
"git.breakpilot.com/platform/tenant-registry/internal/authz"
"git.breakpilot.com/platform/tenant-registry/internal/keycloak"
"git.breakpilot.com/platform/tenant-registry/internal/mail"
"git.breakpilot.com/platform/tenant-registry/internal/store"
@@ -20,11 +21,11 @@ import (
var (
mailBackoff = []time.Duration{time.Minute, 5 * time.Minute, 30 * time.Minute, 2 * time.Hour, 6 * time.Hour}
mailMaxAttempts = 12
// Who is told about what: document readers about documents, the people
// who run the workspace about findings.
notifyRoles = map[string][]string{
mail.KindDocumentPublished: {"IT_ADMIN", "OWNER", "CXO", "FINANCE", "LEGAL"},
mail.KindFindingsNew: {"IT_ADMIN", "OWNER", "CXO", "LEGAL"},
// Who is told about what: the members whose bundle grants the
// capability (RBAC catalogue).
notifyCapability = map[string]string{
mail.KindDocumentPublished: "registry:notify.documents",
mail.KindFindingsNew: "registry:notify.findings",
}
)
@@ -36,8 +37,8 @@ func (s *Server) portalURL() string {
return u
}
// notifyTenant queues kind for every enabled member of t whose org role is
// allowed to receive it. Demo tenants get nothing. Returns how many rows were
// notifyTenant queues kind for every enabled member of t whose bundle grants
// the kind's capability. Demo tenants get nothing. Returns how many rows were
// queued (0 for a repeat of the same key).
func (s *Server) notifyTenant(ctx context.Context, t *store.Tenant, kind, key string, data map[string]interface{}) (int, error) {
if t.Kind == "demo" || t.Status == store.StatusDemo {
@@ -53,9 +54,9 @@ func (s *Server) notifyTenant(ctx context.Context, t *store.Tenant, kind, key st
}
return 0, err
}
allowed := map[string]bool{}
for _, r := range notifyRoles[kind] {
allowed[r] = true
capability, known := notifyCapability[kind]
if !known {
return 0, errors.New("no recipients defined for " + kind)
}
if data == nil {
data = map[string]interface{}{}
@@ -63,7 +64,7 @@ func (s *Server) notifyTenant(ctx context.Context, t *store.Tenant, kind, key st
data["tenant_name"] = t.Name
queued := 0
for _, m := range members {
if !m.Enabled || m.Email == "" || !hasAnyRole(m.OrgRoles, allowed) {
if !m.Enabled || m.Email == "" || !authz.AnyGrants(m.OrgRoles, capability) {
continue
}
ok, err := s.Store.EnqueueMail(ctx, store.MailItem{
@@ -80,15 +81,6 @@ func (s *Server) notifyTenant(ctx context.Context, t *store.Tenant, kind, key st
return queued, nil
}
func hasAnyRole(roles []string, allowed map[string]bool) bool {
for _, r := range roles {
if allowed[strings.ToUpper(r)] {
return true
}
}
return false
}
// documentPublished tells the workspace about a newly published document.
func (s *Server) documentPublished(ctx context.Context, d *store.Document) {
t, err := s.Store.GetTenant(ctx, d.TenantID)
+37
View File
@@ -4,6 +4,7 @@ import (
"context"
"encoding/json"
"errors"
"slices"
"strings"
"testing"
"time"
@@ -136,3 +137,39 @@ func TestNotify_retriesWithBackoff(t *testing.T) {
}
})
}
// RBAC step 4: recipients follow the catalogue, so the new bundles hear
// what their capabilities say: PSIRT about findings, AUDITOR about
// documents, EXTERNAL about neither.
func TestNotify_newBundles(t *testing.T) {
eachStore(t, func(t *testing.T, h *testHarness) {
h.app.Objects = storage.NewMemory()
rec := &mail.Recorder{}
h.app.Mail = rec
h.kcMock.Members["acme"] = []keycloak.OrgMember{
{UserID: "p", Email: "psirt@acme.test", OrgRoles: []string{"PSIRT"}, Enabled: true},
{UserID: "a", Email: "audit@acme.test", OrgRoles: []string{"AUDITOR"}, Enabled: true},
{UserID: "x", Email: "ext@acme.test", OrgRoles: []string{"EXTERNAL"}, Enabled: true},
}
body := map[string]any{"tenant_id": h.tenant.ID, "kind": "findings.new", "idempotency_key": "scan-1",
"data": map[string]any{"target_name": "Pumpstation", "new_count": 1, "critical": 0, "high": 1, "url": "https://pruefwerk-stage.breakpilot.com/targets/t1"}}
if resp, raw := h.do("POST", "/v1/notifications", body); resp.StatusCode != 202 || !strings.Contains(string(raw), `"queued":1`) {
t.Fatalf("findings: %d %s", resp.StatusCode, raw)
}
_, raw := upload(t, h, h.tenant.ID, map[string]string{"title": "CRA-Dossier"}, "dossier.pdf", "%PDF")
var d store.Document
_ = json.Unmarshal(raw, &d)
h.do("POST", "/v1/admin/documents/"+d.ID+"/publish", nil)
if _, err := h.app.DrainMail(context.Background()); err != nil {
t.Fatal(err)
}
got := []string{}
for _, m := range rec.Messages() {
got = append(got, m.To+" "+strings.Fields(m.Subject)[0])
}
slices.Sort(got)
if len(got) != 2 || !strings.HasPrefix(got[0], "audit@acme.test") || !strings.HasPrefix(got[1], "psirt@acme.test 1") {
t.Fatalf("recipients: %v", got)
}
})
}
+3 -4
View File
@@ -10,6 +10,7 @@ import (
"time"
"git.breakpilot.com/platform/tenant-registry/internal/authn"
"git.breakpilot.com/platform/tenant-registry/internal/authz"
"git.breakpilot.com/platform/tenant-registry/internal/store"
)
@@ -151,8 +152,6 @@ func (s *Server) pruefwerkPlanOf(ctx context.Context, tenantID string) (pruefwer
return pruefwerkPlans[0], nil
}
var pruefwerkSettingsRole = map[string]bool{authn.RoleITAdmin: true, authn.RoleOwner: true, "FINANCE": true}
type pruefwerkSettingsResp struct {
TenantID string `json:"tenant_id"`
Product string `json:"product"`
@@ -180,8 +179,8 @@ func pruefwerkSettingsAnswer(tenantID string, set pruefwerkSettings, row *store.
// pruefwerkSettingsRoleOK checks the org role of a user token; on false the
// response is written.
func pruefwerkSettingsRoleOK(w http.ResponseWriter, r *http.Request) bool {
if p, _ := authn.PrincipalFrom(r.Context()); p.IsUser() && !hasAnyRole(p.OrgRoles, pruefwerkSettingsRole) {
writeError(w, http.StatusForbidden, "FORBIDDEN_ROLE", "Prüfwerk settings require the IT_ADMIN, OWNER or FINANCE org role")
if p, _ := authn.PrincipalFrom(r.Context()); p.IsUser() && !authz.AnyGrants(p.OrgRoles, capPruefwerkSettings) {
writeError(w, http.StatusForbidden, "FORBIDDEN_ROLE", "Prüfwerk settings require the registry:pruefwerk.settings right")
return false
}
return true
@@ -98,6 +98,8 @@ func TestPruefwerkSettings_roles(t *testing.T) {
{"cxo", []string{"CXO"}, http.StatusForbidden},
{"legal", []string{"LEGAL"}, http.StatusForbidden},
{"plain user", []string{"USER"}, http.StatusForbidden},
{"auditor", []string{"AUDITOR"}, http.StatusForbidden},
{"quality", []string{"QUALITY"}, http.StatusForbidden},
{"no roles", nil, http.StatusForbidden},
} {
t.Run(c.name, func(t *testing.T) {
+59 -32
View File
@@ -6,47 +6,74 @@ import (
"strings"
"testing"
"git.breakpilot.com/platform/tenant-registry/internal/authn"
"git.breakpilot.com/platform/tenant-registry/internal/authz"
"git.breakpilot.com/platform/tenant-registry/internal/mail"
)
// RBAC step 1: the catalogue's bundles grant exactly what the registry's
// role checks grant today, read from the live variables, so the handlers
// can move onto capabilities (step 2) without changing anybody's rights.
func TestTheBundlesReproduceTheRegistrysRoleChecks(t *testing.T) {
// The roles a member can be given are today's assignable bundles.
assignable := []string{}
for _, b := range authz.Bundles {
if b.Assignable {
assignable = append(assignable, b.Code)
}
}
if !slices.Equal(assignable, teamRoles) {
t.Fatalf("assignable bundles %v, team roles %v", assignable, teamRoles)
}
for _, role := range teamRoles {
pin := map[string]bool{
"registry:members.manage": isAdminRole([]string{role}),
"registry:api-keys.manage": isAdminRole([]string{role}),
"registry:pruefwerk.settings": pruefwerkSettingsRole[role],
"registry:services.read": serviceReadRole[role],
"registry:notify.documents": slices.Contains(notifyRoles[mail.KindDocumentPublished], role),
"registry:notify.findings": slices.Contains(notifyRoles[mail.KindFindingsNew], role),
"registry:intake.report": true, // every member reports (A1 AS-5)
}
for capability, want := range pin {
if got := authz.Grants(role, capability); got != want {
t.Errorf("%s %s: catalogue %v, registry %v", role, capability, got, want)
// The registry's role checks as they stood on 2026-11-10, before they read
// the catalogue. Today's six bundles must keep granting exactly this, so
// moving the checks onto capabilities (step 4) changed nobody's rights.
var registryChecks20261110 = map[string]map[string]bool{
"registry:members.manage": {"IT_ADMIN": true, "OWNER": true},
"registry:api-keys.manage": {"IT_ADMIN": true, "OWNER": true},
"registry:pruefwerk.settings": {"IT_ADMIN": true, "OWNER": true, "FINANCE": true},
"registry:services.read": {"IT_ADMIN": true, "OWNER": true, "CXO": true},
"registry:notify.documents": {"IT_ADMIN": true, "OWNER": true, "CXO": true, "FINANCE": true, "LEGAL": true},
"registry:notify.findings": {"IT_ADMIN": true, "OWNER": true, "CXO": true, "LEGAL": true},
"registry:intake.report": {"IT_ADMIN": true, "OWNER": true, "CXO": true, "FINANCE": true, "LEGAL": true, "USER": true},
}
func TestTodaysBundlesKeepTheRegistrysRoleChecks(t *testing.T) {
for _, role := range []string{"IT_ADMIN", "OWNER", "CXO", "FINANCE", "LEGAL", "USER"} {
for capability, holders := range registryChecks20261110 {
if got := authz.AnyGrants([]string{role}, capability); got != holders[role] {
t.Errorf("%s %s: catalogue %v, registry on 2026-11-10 %v", role, capability, got, holders[role])
}
}
// The last-admin guard and the tenant-admin check of a user token
// still agree with the catalogue.
if isAdminRole([]string{role}) != registryChecks20261110["registry:members.manage"][role] {
t.Errorf("%s: isAdminRole disagrees", role)
}
p := &authn.Principal{Subject: "u", TenantID: "t", OrgRoles: []string{role}}
if p.IsTenantAdmin() != authz.AnyGrants(p.OrgRoles, "registry:members.manage") {
t.Errorf("%s: IsTenantAdmin disagrees with the catalogue", role)
}
}
for _, c := range authz.Capabilities {
if c.Product == authz.Registry {
if _, ok := map[string]bool{"registry:members.manage": true, "registry:api-keys.manage": true, "registry:pruefwerk.settings": true,
"registry:services.read": true, "registry:notify.documents": true, "registry:notify.findings": true, "registry:intake.report": true}[c.Code]; !ok {
t.Errorf("%s: not pinned against a registry check", c.Code)
if _, ok := registryChecks20261110[c.Code]; c.Product == authz.Registry && !ok {
t.Errorf("%s: not pinned against a registry check", c.Code)
}
}
}
// The new bundles (§3a): what the registry now gives them, and that none of
// them administers the workspace.
func TestTheNewBundlesInTheRegistry(t *testing.T) {
want := map[string][]string{
"PSIRT": {"registry:notify.findings", "registry:intake.report"},
"DEVELOPMENT": {"registry:notify.findings", "registry:intake.report"},
"QUALITY": {"registry:notify.documents", "registry:intake.report"},
"PRIVACY": {"registry:notify.documents", "registry:intake.report"},
"PURCHASING": {"registry:notify.documents", "registry:intake.report"},
"AUDITOR": {"registry:services.read", "registry:notify.documents", "registry:intake.report"},
"EXTERNAL": {"registry:intake.report"},
}
for role, caps := range want {
if !authz.IsAssignable(role) {
t.Errorf("%s is not assignable", role)
}
for capability := range registryChecks20261110 {
if got := authz.AnyGrants([]string{role}, capability); got != slices.Contains(caps, capability) {
t.Errorf("%s %s: %v", role, capability, got)
}
}
if isAdminRole([]string{role}) {
t.Errorf("%s administers the workspace", role)
}
}
if authz.AnyGrants([]string{"psirt"}, "registry:notify.findings") != true || authz.AnyGrants([]string{"NOBODY"}, "registry:intake.report") {
t.Error("claims are matched case-insensitively and unknown bundles grant nothing")
}
}
+8 -8
View File
@@ -10,6 +10,7 @@ import (
"time"
"git.breakpilot.com/platform/tenant-registry/internal/authn"
"git.breakpilot.com/platform/tenant-registry/internal/authz"
"git.breakpilot.com/platform/tenant-registry/internal/store"
)
@@ -22,10 +23,9 @@ import (
// and CXO; the portal makes CXO read-only).
var (
gitSKURE = regexp.MustCompile(`^INF-GIT-(CLD|OPR)-(STD|BUS|ENT)$`)
ciRunnerSKURE = regexp.MustCompile(`^INF-CI-(CLD|OPR)-(STD|BUS|ENT)$`)
instanceIDRE = regexp.MustCompile(`^[a-z0-9-]*$`)
serviceReadRole = map[string]bool{authn.RoleITAdmin: true, authn.RoleOwner: true, "CXO": true}
gitSKURE = regexp.MustCompile(`^INF-GIT-(CLD|OPR)-(STD|BUS|ENT)$`)
ciRunnerSKURE = regexp.MustCompile(`^INF-CI-(CLD|OPR)-(STD|BUS|ENT)$`)
instanceIDRE = regexp.MustCompile(`^[a-z0-9-]*$`)
)
// managedServiceView is the tenant's view of a service: no instance id, no
@@ -50,11 +50,11 @@ func tenantServiceView(ms store.ManagedService) managedServiceView {
}
// listTenantManagedServices is GET /v1/tenants/{id}/managed-services (a {sub}
// of tenantSubresource). Users need IT_ADMIN, OWNER or CXO; service clients
// read with tenants.read.
// of tenantSubresource). Users need registry:services.read (IT_ADMIN, OWNER,
// CXO, AUDITOR); service clients read with tenants.read.
func (s *Server) listTenantManagedServices(w http.ResponseWriter, r *http.Request) {
if p, _ := authn.PrincipalFrom(r.Context()); p.IsUser() && !hasAnyRole(p.OrgRoles, serviceReadRole) {
writeError(w, http.StatusForbidden, "FORBIDDEN_ROLE", "managed services require the IT_ADMIN, OWNER or CXO org role")
if p, _ := authn.PrincipalFrom(r.Context()); p.IsUser() && !authz.AnyGrants(p.OrgRoles, capServicesRead) {
writeError(w, http.StatusForbidden, "FORBIDDEN_ROLE", "managed services require the registry:services.read right")
return
}
ctx, cancel := context.WithTimeout(r.Context(), 10*time.Second)
+4
View File
@@ -36,6 +36,10 @@ func TestManagedServices_tenantRoles(t *testing.T) {
{"cxo lower case", []string{"cxo"}, http.StatusOK},
{"plain user", []string{"USER"}, http.StatusForbidden},
{"finance", []string{"FINANCE"}, http.StatusForbidden},
{"auditor reads (step 4)", []string{"AUDITOR"}, http.StatusOK},
{"psirt", []string{"PSIRT"}, http.StatusForbidden},
{"external", []string{"EXTERNAL"}, http.StatusForbidden},
{"unknown bundle", []string{"NOBODY"}, http.StatusForbidden},
{"legal", []string{"LEGAL"}, http.StatusForbidden},
{"no roles", nil, http.StatusForbidden},
}
+11 -5
View File
@@ -10,6 +10,7 @@ import (
"time"
"git.breakpilot.com/platform/tenant-registry/internal/authn"
"git.breakpilot.com/platform/tenant-registry/internal/authz"
"git.breakpilot.com/platform/tenant-registry/internal/keycloak"
"git.breakpilot.com/platform/tenant-registry/internal/store"
)
@@ -42,11 +43,16 @@ import (
const headerPortalUserSubject = "X-Portal-User-Subject"
// teamRoles are the org roles a member can be given.
var teamRoles = []string{authn.RoleITAdmin, authn.RoleOwner, "CXO", "FINANCE", "LEGAL", "USER"}
// Capabilities the registry checks itself (RBAC catalogue).
const (
capServicesRead = "registry:services.read"
capPruefwerkSettings = "registry:pruefwerk.settings"
)
// isAdminRole: the bundle lets its holder manage the team (IT_ADMIN,
// OWNER). The last one of a workspace is never demoted, blocked or removed.
func isAdminRole(roles []string) bool {
return slices.Contains(roles, authn.RoleITAdmin) || slices.Contains(roles, authn.RoleOwner)
return authz.AnyGrants(roles, capManage)
}
type memberPatchReq struct {
@@ -223,8 +229,8 @@ func (s *Server) patchMember(w http.ResponseWriter, r *http.Request, resolve ten
role := ""
if in.Role != nil {
role = strings.ToUpper(strings.TrimSpace(*in.Role))
if !slices.Contains(teamRoles, role) {
writeError(w, http.StatusBadRequest, "invalid_role", "role must be one of "+strings.Join(teamRoles, ", "))
if !authz.IsAssignable(role) {
writeError(w, http.StatusBadRequest, "invalid_role", "role must be one of "+strings.Join(authz.Assignable(), ", "))
return
}
}
+11 -10
View File
@@ -711,8 +711,9 @@ paths:
get:
summary: The workspace's Prüfwerk settings (the monthly Prüftag cap).
description: |
User tokens reach their own tenant only and need the org role
IT_ADMIN, OWNER or FINANCE (else 403 FORBIDDEN_ROLE); service
User tokens reach their own tenant only and need a bundle granting
registry:pruefwerk.settings (IT_ADMIN, OWNER, FINANCE; else 403
FORBIDDEN_ROLE); service
clients read with tenants.read. Nothing saved yet is
`prueftag_cap: null`. Kept apart from the ERP-derived entitlement
config, so a recompute never resets it.
@@ -809,8 +810,8 @@ paths:
summary: A tenant's managed services (Verwaltete Infrastruktur), oldest first.
description: |
Served by the `{id}/{sub}` route; user tokens reach their own tenant
only and need the org role IT_ADMIN, OWNER or CXO (else 403
FORBIDDEN_ROLE). Service clients read with tenants.read. Never
only and need a bundle granting registry:services.read (IT_ADMIN,
OWNER, CXO, AUDITOR; else 403 FORBIDDEN_ROLE). Service clients read with tenants.read. Never
carries instance_id or notes.
parameters:
- { in: path, name: id, required: true, schema: { type: string, format: uuid } }
@@ -879,9 +880,9 @@ paths:
last_name: { type: string, maxLength: 100 }
role:
type: string
pattern: '^[A-Z][A-Z0-9_]{1,31}$'
enum: [IT_ADMIN, OWNER, CXO, FINANCE, LEGAL, USER, PSIRT, DEVELOPMENT, QUALITY, PRIVACY, PURCHASING, AUDITOR, EXTERNAL]
default: USER
description: "org_roles attribute written for the user"
description: "an assignable bundle of GET /v1/authz/catalogue, written as the org_roles attribute; case-insensitive"
responses:
"202":
description: Invited; the mail is on its way.
@@ -920,7 +921,7 @@ paths:
schema:
type: object
properties:
role: { type: string, enum: [IT_ADMIN, OWNER, CXO, FINANCE, LEGAL, USER] }
role: { type: string, enum: [IT_ADMIN, OWNER, CXO, FINANCE, LEGAL, USER, PSIRT, DEVELOPMENT, QUALITY, PRIVACY, PURCHASING, AUDITOR, EXTERNAL] }
blocked: { type: boolean }
responses:
"200":
@@ -1244,7 +1245,7 @@ paths:
schema:
type: object
properties:
role: { type: string, enum: [IT_ADMIN, OWNER, CXO, FINANCE, LEGAL, USER] }
role: { type: string, enum: [IT_ADMIN, OWNER, CXO, FINANCE, LEGAL, USER, PSIRT, DEVELOPMENT, QUALITY, PRIVACY, PURCHASING, AUDITOR, EXTERNAL] }
blocked: { type: boolean }
responses:
"200":
@@ -1696,8 +1697,8 @@ paths:
summary: Ask the platform to tell a workspace something (route group notify).
description: |
Products report news for a workspace; the platform mails the members
whose org role should hear it (findings.new: IT_ADMIN, OWNER, CXO,
LEGAL), in the BreakPilot layout, through an outbox. Demo tenants and
whose bundle grants the kind's capability (findings.new:
registry:notify.findings), in the BreakPilot layout, through an outbox. Demo tenants and
tenants without an organization get nothing. Idempotent per
idempotency_key.
requestBody: