mirror of
https://github.com/hanzoai/ai.git
synced 2026-11-20 14:13:23 +00:00
util.IsSuperAdmin compared the resolved user's owner to "admin", a second predicate beside the one the host boundary decides, and the two disagreed. An admin-org application (no orgs, owner claim admin), an admin-org person's sk- key, and an org spelled "admin " (the parse trimmed orgs[0]) were each SuperAdmin here and refused by the boundary. The host now states the verdict: object.SetSuper, which hanzo-inc/cloud fills with principal.Super, the X-User-IsAdmin its boundary deletes from every request and re-mints from authz.Claims.Sudo. Every HTTP seam that turns a token into a principal goes through object.Verify, which stamps it on iam.User.Sudo (never decoded); IsSuperAdmin and ScopeOwner read that and compare no org. util.AdminOrg is gone; the rows that are the platform's own are named by authz.AdminOrg. With no host there is no SuperAdmin, and a ZAP door is not the host: target deletes X-User-IsAdmin from a ZAP-built request, and zapPrincipal carries a verdict only when the HTTP bridge vouched for the request it was handed. A key is never the SuperAdmin, as at the host.
81 lines
3.2 KiB
Go
81 lines
3.2 KiB
Go
// Copyright 2026 Hanzo AI Inc. All Rights Reserved.
|
|
|
|
package controllers
|
|
|
|
import (
|
|
"testing"
|
|
|
|
iam "github.com/hanzoai/ai/internal/iam"
|
|
|
|
"github.com/hanzoai/ai/util"
|
|
)
|
|
|
|
// SUPER-ADMIN IS ORG MEMBERSHIP AND NOTHING ELSE.
|
|
//
|
|
// There are two admin scopes and conflating them is a privilege escalation, not
|
|
// a naming quibble: an ORG admin administers their own tenant, and the SuperAdmin
|
|
// is the platform's own sudo, the host boundary's verdict on a request. A
|
|
// gate that accepted the first for the second would hand every customer's org
|
|
// admin the cross-tenant surface.
|
|
//
|
|
// So the boundary is asserted from the side that would be the bug: an org admin,
|
|
// flagged as admin, in a tenant that is not the reserved one, is not a super
|
|
// admin — and holds no more of the platform than an anonymous caller does.
|
|
func TestAnOrgAdminIsNotAPlatformSuperAdmin(t *testing.T) {
|
|
for _, tc := range []struct {
|
|
what string
|
|
user *iam.User
|
|
want bool
|
|
}{
|
|
{"nobody", nil, false},
|
|
{"an ordinary member of a tenant", &iam.User{Owner: "acme", Name: "alice"}, false},
|
|
{"that tenant's own admin", &iam.User{Owner: "acme", Name: "boss", IsAdmin: true}, false},
|
|
{"a chat admin by type", &iam.User{Owner: "acme", Name: "mod", Type: util.UserTypeChatAdmin}, false},
|
|
{"a row of the reserved org with no host verdict", &iam.User{Owner: "admin", Name: "root"}, false},
|
|
{"the host's verdict", &iam.User{Owner: "admin", Name: "ops", Sudo: true}, true},
|
|
} {
|
|
t.Run(tc.what, func(t *testing.T) {
|
|
if got := util.IsSuperAdmin(tc.user); got != tc.want {
|
|
t.Errorf("IsSuperAdmin = %v, want %v", got, tc.want)
|
|
}
|
|
})
|
|
}
|
|
|
|
// And the two predicates genuinely differ, so this is a boundary rather than
|
|
// two names for one answer.
|
|
orgAdmin := &iam.User{Owner: "acme", Name: "boss", IsAdmin: true}
|
|
if !util.IsAdmin(orgAdmin) || util.IsSuperAdmin(orgAdmin) {
|
|
t.Error("an org admin must be an admin and must not be a super admin")
|
|
}
|
|
}
|
|
|
|
// The super-admin routes are gated in EVERY posture — preview mode relaxes reads,
|
|
// and it does not relax these. That is the whole point of the set: it is the
|
|
// group's slice of the endpoints that are never opened.
|
|
func TestTheSuperAdminRoutesAreNeverRelaxedByPreviewMode(t *testing.T) {
|
|
for _, preview := range []string{"true", "false"} {
|
|
t.Run("DISABLE_PREVIEW_MODE="+preview, func(t *testing.T) {
|
|
t.Setenv("DISABLE_PREVIEW_MODE", preview)
|
|
for name := range zapMiscSuperAdmin {
|
|
if deny := zapMiscAuthz(name, nil); deny == nil {
|
|
t.Errorf("%q let an anonymous caller through", name)
|
|
}
|
|
orgAdmin := &iam.User{Owner: "acme", Name: "boss", IsAdmin: true}
|
|
if deny := zapMiscAuthz(name, orgAdmin); deny == nil {
|
|
t.Errorf("%q let a tenant's own admin through; it is platform sudo", name)
|
|
}
|
|
// A raw ZAP door resolves no host verdict, so a row of the reserved org
|
|
// is refused here too; the SuperAdmin reaches these over HTTP.
|
|
root := &iam.User{Owner: "admin", Name: "root"}
|
|
if deny := zapMiscAuthz(name, root); deny == nil {
|
|
t.Errorf("%q let a reserved-org row through with no host verdict", name)
|
|
}
|
|
sudo := &iam.User{Owner: "admin", Name: "root", Sudo: true}
|
|
if deny := zapMiscAuthz(name, sudo); deny != nil {
|
|
t.Errorf("%q refused the host's verdict", name)
|
|
}
|
|
}
|
|
})
|
|
}
|
|
}
|