From 6ab437154af5d1772038bcf0a6c5a75acf273c18 Mon Sep 17 00:00:00 2001 From: Sharang Parnerkar <30073382+mighty840@users.noreply.github.com> Date: Mon, 26 Oct 2026 23:21:29 +0100 Subject: [PATCH] fix: the CXO sign-in role makes the first role dataset entry Until a company has recorded its management, the first entry (the management holders and nothing else) was reserved to the OWNER sign-in role. No tenant has an OWNER user: every tenant's first admin is IT_ADMIN, and the portal cannot assign OWNER, so nobody could start the dataset. Decided by Sharang: the first entry belongs to CXO, the management sign-in role. IT_ADMIN, the technical admin, does not name management; every later change follows the dataset's own rule (B7). Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_014aRnCGqELxoix5TfpX8Ejf --- internal/roles/dataset.go | 12 +++++++----- internal/roles/dataset_test.go | 14 ++++++++------ internal/server/role_dataset_test.go | 11 ++++++++--- openapi.yaml | 2 +- 4 files changed, 24 insertions(+), 15 deletions(-) diff --git a/internal/roles/dataset.go b/internal/roles/dataset.go index 8664538..7dd394d 100644 --- a/internal/roles/dataset.go +++ b/internal/roles/dataset.go @@ -510,9 +510,11 @@ type Writer struct { OrgRoles []string } -// OwnerRole is the sign-in role that may make the first entry (S0 spec §6.3, -// owner question Q3). It is the only place a sign-in role counts here. -const OwnerRole = "OWNER" +// BootstrapRole is the sign-in role that may make the first entry (S0 spec §6.3, +// Q3): CXO, the management sign-in role (decided by Sharang 2026-10-26). Every +// tenant's first admin is IT_ADMIN, the technical admin, who does not name +// management. It is the only place a sign-in role counts here. +const BootstrapRole = "CXO" // Prepare checks a save against the current dataset and returns the dataset // to store, with the registry's stamps (S0 spec §5, §6). current is nil when @@ -525,11 +527,11 @@ func Prepare(current, incoming *Dataset, authorize []string, w Writer, now time. switch { case current.Holds(w.Sub, Management) || current.Holds(w.Sub, DocumentOwner): // B7: management and document owners maintain the dataset. - case !current.hasManagementHolder() && slices.Contains(w.OrgRoles, OwnerRole): + case !current.hasManagementHolder() && slices.Contains(w.OrgRoles, BootstrapRole): // First entry: only management assignments, nothing else. if len(authorize) > 0 || !onlyAddsManagement(current, incoming) { return nil, &Error{Status: http.StatusForbidden, Code: "bootstrap_only", - Message: "until management is recorded, the OWNER sign-in role may only record management"} + Message: "until management is recorded, the CXO sign-in role may only record management"} } default: return nil, &Error{Status: http.StatusForbidden, Code: "not_permitted", diff --git a/internal/roles/dataset_test.go b/internal/roles/dataset_test.go index 659192a..8e1b74c 100644 --- a/internal/roles/dataset_test.go +++ b/internal/roles/dataset_test.go @@ -22,7 +22,7 @@ func member(sub string) Holder { return Holder{Kind: HolderMember, Sub: sub} } func base(t *testing.T) *Dataset { t.Helper() ds, err := Prepare(nil, &Dataset{Assignments: []Assignment{{ID: "a-ceo", Function: Management, Holder: member(ceo)}}}, - nil, Writer{Sub: ceo, OrgRoles: []string{OwnerRole}}, now) + nil, Writer{Sub: ceo, OrgRoles: []string{BootstrapRole}}, now) if err != nil { t.Fatalf("bootstrap: %v", err) } @@ -106,8 +106,8 @@ func TestPrepare_whoMayWrite(t *testing.T) { if _, err := Prepare(ds, &next, nil, Writer{Sub: staff}, now); code(err) != "not_permitted" { t.Fatalf("a person without function: %v", err) } - if _, err := Prepare(ds, &next, nil, Writer{Sub: staff, OrgRoles: []string{OwnerRole}}, now); code(err) != "not_permitted" { - t.Fatalf("OWNER once management is recorded: %v", err) + if _, err := Prepare(ds, &next, nil, Writer{Sub: staff, OrgRoles: []string{BootstrapRole}}, now); code(err) != "not_permitted" { + t.Fatalf("CXO once management is recorded: %v", err) } if _, err := Prepare(ds, &next, nil, Writer{Sub: owner}, now); err != nil { t.Fatalf("document owner: %v", err) @@ -118,7 +118,7 @@ func TestPrepare_whoMayWrite(t *testing.T) { } func TestPrepare_bootstrapOnlyRecordsManagement(t *testing.T) { - w := Writer{Sub: "u-signup", OrgRoles: []string{OwnerRole}} + w := Writer{Sub: "u-signup", OrgRoles: []string{BootstrapRole}} other := &Dataset{Assignments: []Assignment{{ID: "a-1", Function: "r1.vorfallkontakt", Holder: member(staff)}}} if _, err := Prepare(nil, other, nil, w, now); code(err) != "bootstrap_only" { t.Fatalf("bootstrap with another function: %v", err) @@ -127,8 +127,10 @@ func TestPrepare_bootstrapOnlyRecordsManagement(t *testing.T) { if _, err := Prepare(nil, mgmt, []string{"a-1"}, w, now); code(err) != "bootstrap_only" { t.Fatalf("no authorizing in the bootstrap: %v", err) } - if _, err := Prepare(nil, mgmt, nil, Writer{Sub: "u-signup", OrgRoles: []string{"CXO"}}, now); code(err) != "not_permitted" { - t.Fatalf("bootstrap needs OWNER: %v", err) + for _, r := range []string{"IT_ADMIN", "OWNER", "LEGAL", "USER"} { + if _, err := Prepare(nil, mgmt, nil, Writer{Sub: "u-signup", OrgRoles: []string{r}}, now); code(err) != "not_permitted" { + t.Fatalf("bootstrap by %s: %v", r, err) + } } ds, err := Prepare(nil, mgmt, nil, w, now) if err != nil || ds.Assignments[0].RecordedBy != "u-signup" { diff --git a/internal/server/role_dataset_test.go b/internal/server/role_dataset_test.go index 036724b..2e4b186 100644 --- a/internal/server/role_dataset_test.go +++ b/internal/server/role_dataset_test.go @@ -38,10 +38,11 @@ func newRoleFixture(t *testing.T) *roleFixture { return &authn.Principal{Subject: sub, ClientID: "portal-stage", TenantID: tenantID, Email: sub + "@acme.test", OrgRoles: roles} } f := &roleFixture{tenant: tenant, as: map[string]*authn.Principal{ - "signup": user("u-signup", tenant.ID, "OWNER"), + "signup": user("u-signup", tenant.ID, "CXO"), + "itadmin": user("u-it", tenant.ID, "IT_ADMIN"), "ceo": user("u-ceo", tenant.ID, "CXO"), "staff": user("u-staff", tenant.ID, "USER"), - "stranger": user("u-x", other.ID, "OWNER"), + "stranger": user("u-x", other.ID, "CXO"), "portal": {Subject: "svc-portal", ClientID: "portal-svc"}, "werkmeister": {Subject: "svc-wm", ClientID: "werkmeister-svc"}, }} @@ -107,7 +108,11 @@ func TestRoleDataset_lifecycle(t *testing.T) { if code, _, raw := f.do(t, "signup", "PUT", f.path(""), strings.Replace(saveBody(mgmtOnly, 0), roles.CatalogueVersion, "r1-old", 1)); code != http.StatusConflict || !strings.Contains(raw, "catalogue_outdated") { t.Fatalf("old catalogue: %d %s", code, raw) } - // First entry by the OWNER sign-in role: management only. + // The technical admin does not name management. + if code, _, raw := f.do(t, "itadmin", "PUT", f.path(""), saveBody(mgmtOnly, 0)); code != http.StatusForbidden || !strings.Contains(raw, "not_permitted") { + t.Fatalf("IT_ADMIN bootstrap: %d %s", code, raw) + } + // First entry by the CXO sign-in role: management only. code, out, raw = f.do(t, "signup", "PUT", f.path(""), saveBody(mgmtOnly, 0)) if code != http.StatusOK || out["revision"].(float64) != 1 || out["updated_by"] != "u-signup" { t.Fatalf("bootstrap: %d %s", code, raw) diff --git a/openapi.yaml b/openapi.yaml index aab7076..8021ef4 100644 --- a/openapi.yaml +++ b/openapi.yaml @@ -517,7 +517,7 @@ paths: Only with the user token of the person saving (`user_token_required` otherwise); `X-Portal-User-*` headers are ignored. The writer must hold management or a document owner function; while no management - holder is recorded, the OWNER sign-in role may record management and + holder is recorded, the CXO sign-in role may record management and nothing else (`bootstrap_only`). `recorded_*` and `authorized_*` are set by the registry, never taken from the body; `authorize` lists deputies and standard releases management authorizes with this save. -- 2.54.1