mirror of
https://github.com/hanzoai/iam.git
synced 2026-11-19 18:37:16 +00:00
schema.User.SuperAdmin is the one predicate: a person whose row's owner is the admin org. The Guard sets Principal.Sudo from it when it loads the caller, and assume/release, device approval, unlink, the bootstrap credential freeze and the registry push gate ask the row directly. store.IsSuperAdmin, which also admitted a membership of the admin org, is gone. A brand org's user added to the admin org is an ordinary member of their own org, and a service account or program in the admin org is never SuperAdmin. hanzoai/authz v1.10.42 reads the same rule off a token (Claims.Sudo on orgs[0]) and lets a membership of the admin org open nothing, so such a member no longer reads or edits the admin org's registry row either. The token IAM mints is unchanged: orgs still opens with the row's owner. Two protective gates keep the whole admin org, machines and unheld names included: no secret key names an account there (store.SuperAdminKey), and only a SuperAdmin writes one (users.Authorize). Both read the owner as written, so neither reads the store. Every request the Guard admits for a SuperAdmin is recorded as a superadmin audit row, PlatformWritten, with its method, address, answer and client address; so is a SuperAdmin's unlink of someone else's sign-in method and a device approval into another org. TestEverySuperAdminGateAdmitsTheAdminOrgsPeopleOnly drives ten SuperAdmin-only requests through the router as two SuperAdmins, a brand admin holding an admin-org membership and two admin-org machines, and reads the trail row each one leaves. Claude-Session: https://claude.ai/code/session_01HuMDfgFssPUptYUzgZ6Cp8
46 lines
1.8 KiB
Go
46 lines
1.8 KiB
Go
// Copyright 2026 Hanzo AI, Inc.
|
||
// SPDX-License-Identifier: MIT OR Apache-2.0
|
||
|
||
package schema
|
||
|
||
import (
|
||
"testing"
|
||
|
||
policy "github.com/hanzoai/authz"
|
||
)
|
||
|
||
// SuperAdmin is a PERSON whose own org is the admin org. The row is the whole
|
||
// input: a membership cannot reach it, a machine is never one, and an owner that
|
||
// only looks like the admin org is an ordinary tenant.
|
||
func TestSuperAdminIsAPersonWhoseOrgIsAdmin(t *testing.T) {
|
||
for _, c := range []struct {
|
||
name string
|
||
u *User
|
||
want bool
|
||
}{
|
||
{"a person in the admin org", &User{Owner: policy.AdminOrg, Name: "z"}, true},
|
||
{"a person in the admin org who is not its org admin", &User{Owner: policy.AdminOrg, Name: "ops", IsAdmin: false}, true},
|
||
{"a brand org's admin", &User{Owner: "hanzo", Name: "z", IsAdmin: true}, false},
|
||
{"a service account in the admin org", &User{Owner: policy.AdminOrg, Name: "svc", Type: ServiceAccount}, false},
|
||
{"a program in the admin org", &User{Owner: policy.AdminOrg, Name: "kms", Type: Program}, false},
|
||
{"a program spelled with padding and case", &User{Owner: policy.AdminOrg, Name: "kms", Type: " Service-Account "}, false},
|
||
{"the signing owner", &User{Owner: "built-in", Name: "root"}, false},
|
||
{"the service org", &User{Owner: "app", Name: "root"}, false},
|
||
{"no row", nil, false},
|
||
} {
|
||
if got := c.u.SuperAdmin(); got != c.want {
|
||
t.Errorf("%s: SuperAdmin() = %v, want %v", c.name, got, c.want)
|
||
}
|
||
}
|
||
}
|
||
|
||
// The owner is compared verbatim, like every org comparison: folding case,
|
||
// space or script would make an org someone can self-serve the reserved one.
|
||
func TestSuperAdminRejectsNearMissOwners(t *testing.T) {
|
||
for _, owner := range []string{"Admin", "ADMIN", "admin ", " admin", "аdmin", "admin", ""} {
|
||
if (&User{Owner: owner, Name: "root"}).SuperAdmin() {
|
||
t.Errorf("owner %q read as the admin org", owner)
|
||
}
|
||
}
|
||
}
|