mirror of
https://github.com/hanzoai/iam.git
synced 2026-11-21 02:59:42 +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
74 lines
2.9 KiB
Go
74 lines
2.9 KiB
Go
// Copyright 2026 Hanzo AI, Inc.
|
||
// SPDX-License-Identifier: MIT OR Apache-2.0
|
||
|
||
package store
|
||
|
||
import (
|
||
"testing"
|
||
|
||
policy "github.com/hanzoai/authz"
|
||
)
|
||
|
||
// THE RESERVED SET IS EXACT, AND EXACTNESS IS THE WHOLE SECURITY. A signing cert
|
||
// is trusted only under a reserved owner, and the `kid` a token names is resolved
|
||
// under those owners in order — so if any spelling a tenant can self-serve
|
||
// ("Admin", "admin ", a Cyrillic look-alike) were folded to a reserved owner, that
|
||
// tenant could file a cert under the colliding name, have it published in the
|
||
// JWKS, and forge tokens the whole estate verifies. The predicates compare
|
||
// VERBATIM for exactly this reason; this pins that they never start folding.
|
||
//
|
||
// It supersedes the owner-spelling half of the deleted reserved_org_test.go: the
|
||
// predicates moved to hanzoai/authz, but the boundary they draw is IAM's to hold,
|
||
// so IAM tests it.
|
||
func TestKidCollisionAcrossOwnerSpellings(t *testing.T) {
|
||
// The real reserved owners, and what each is.
|
||
if !policy.IsSigningOwner("admin") || !policy.IsSigningOwner("built-in") {
|
||
t.Fatal("a real signing owner is not recognized — every token would fail to verify")
|
||
}
|
||
if !policy.IsReservedOrg("admin") || !policy.IsReservedOrg("built-in") || !policy.IsReservedOrg("app") {
|
||
t.Fatal("a real reserved org is not recognized")
|
||
}
|
||
// "app" is reserved (no self-service principal lands there) but is NOT a signing
|
||
// owner (it holds no token-signing cert), and that distinction must hold.
|
||
if policy.IsSigningOwner("app") {
|
||
t.Error(`"app" must not be a signing owner`)
|
||
}
|
||
|
||
// Near-misses of a reserved owner. Every one is a DISTINCT identifier a tenant
|
||
// could try to register under, and every one must be neither a signing owner
|
||
// nor a reserved org — otherwise it shadows the platform.
|
||
nearMisses := []struct {
|
||
name, spelling string
|
||
}{
|
||
{"capitalized", "Admin"},
|
||
{"upper", "ADMIN"},
|
||
{"trailing space", "admin "},
|
||
{"leading space", " admin"},
|
||
{"tab", "admin\t"},
|
||
{"newline", "admin\n"},
|
||
{"zero-width space", "admin"},
|
||
{"cyrillic a", "аdmin"}, // U+0430 CYRILLIC SMALL LETTER A
|
||
{"dotless i", "admın"}, // U+0131 LATIN SMALL LETTER DOTLESS I
|
||
{"fullwidth", "admin"}, // U+FF41 FULLWIDTH LATIN SMALL A
|
||
{"trailing null", "admin\x00"},
|
||
{"nbsp", "admin "},
|
||
{"builtin no dash", "builtin"},
|
||
{"builtin underscore", "built_in"},
|
||
{"builtin capitalized", "Built-In"},
|
||
{"builtin trailing space", "built-in "},
|
||
{"app trailing space", "app "},
|
||
{"app capitalized", "App"},
|
||
{"empty", ""},
|
||
}
|
||
for _, tc := range nearMisses {
|
||
t.Run(tc.name, func(t *testing.T) {
|
||
if policy.IsSigningOwner(tc.spelling) {
|
||
t.Errorf("IsSigningOwner(%q) = true — a tenant could shadow a platform signing kid", tc.spelling)
|
||
}
|
||
if policy.IsReservedOrg(tc.spelling) {
|
||
t.Errorf("IsReservedOrg(%q) = true — a customer flow would be refused, or a platform org impersonated", tc.spelling)
|
||
}
|
||
})
|
||
}
|
||
}
|