fix: the CXO sign-in role makes the first role dataset entry
ci / test (pull_request) Successful in 24m34s
ci / shared (pull_request) Successful in 14s
ci / image (pull_request) Skipped

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 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_014aRnCGqELxoix5TfpX8Ejf
This commit is contained in:
Sharang ParnerkarandClaude Opus 5.5 committed 2026-10-26 23:21:29 +01:00
1 parent 1b9e2f1183
commit 6ab437154a
4 files changed
+24 -15

No files matched your search

+7 -5
View File
@@ -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",
+8 -6
View File
@@ -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" {
+8 -3
View File
@@ -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)
+1 -1
View File
@@ -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.