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
125 lines
5.9 KiB
Go
125 lines
5.9 KiB
Go
// Copyright 2026 Hanzo AI, Inc.
|
|
// SPDX-License-Identifier: MIT OR Apache-2.0
|
|
|
|
package schema
|
|
|
|
import "github.com/hanzoai/orm"
|
|
|
|
// AuditLog is an append-only action record (v1 the legacy surface `record`, v2 kind
|
|
// "audit_logs"). One row captures a single request against the IAM surface:
|
|
// who acted (Organization, User, ClientIp), what they invoked (Method,
|
|
// RequestUri, Action), the request payload and the server's answer (Object,
|
|
// Response, StatusCode), and whether the row fired its registered webhooks
|
|
// (IsTriggered). It is written once at request time and is not mutated in
|
|
// normal operation; the CRUD update path exists only for administrative
|
|
// correction.
|
|
//
|
|
// Identity is the (Owner, Name) pair — Name is a generated unique id and Owner
|
|
// is the acting organization — so the orm string key is "owner/name". v1's
|
|
// integer autoincrement primary key (`id`) is a per-store surrogate with no
|
|
// cross-store meaning; it is superseded by the orm string key rather than
|
|
// carried as a colliding `id` field, since orm.Model already persists its own
|
|
// `id`. Every semantically meaningful v1 column is carried so no actor,
|
|
// endpoint, payload, or status is lost on migration.
|
|
//
|
|
// Object and Response are unbounded text in v1 (mediumtext): Object holds the
|
|
// password-masked request body and Response a compact status/message envelope.
|
|
// Both carry no orm index. The audit query dimensions — Organization, User, and
|
|
// Action — are indexed alongside the (Owner, Name) key and the CreatedTime sort
|
|
// column.
|
|
// The actions the PLATFORM writes about itself. A row carrying one of these is
|
|
// not a customer's own telemetry: it is the evidence that the platform did
|
|
// something accountable — recorded a consent answer, issued or revoked a
|
|
// credential. The generic audit-log CRUD refuses to create, alter or delete one,
|
|
// so the trail cannot be forged with an invented grant or quietly trimmed of a
|
|
// real one by the same org admin whose actions it records.
|
|
//
|
|
// They live here, beside the entity, because the WRITERS (internal/oidc) and the
|
|
// GATE (internal/auditlogs) are different packages and must name the same set. A
|
|
// writer that invents its own string writes a row anybody can then rewrite.
|
|
const (
|
|
ActionConsentTraining = "consent-training"
|
|
ActionIssueUserToken = "issue-user-token"
|
|
ActionMintUserKeys = "mint-user-keys"
|
|
ActionRevokeUserKeys = "revoke-user-keys"
|
|
ActionTokenExchange = "token-exchange"
|
|
|
|
// A server key acting FOR a user in its own org — the credential behind as().
|
|
// It is a privileged mint (one principal obtains a token bound to another), so
|
|
// every one is recorded: who acted (the org key), for whom (the target
|
|
// subject), in which org, and when.
|
|
ActionAs = "as"
|
|
|
|
// A platform operator stepping into an organization and back out, and reaching
|
|
// past their own memberships to enumerate the registry. All three are
|
|
// privileged cross-tenant acts, so all three are recorded — and so is a
|
|
// refusal, which is the row an auditor most wants to find.
|
|
ActionAssumeOrg = "assume-organization"
|
|
ActionReleaseOrg = "release-organization"
|
|
ActionListOrgs = "list-organizations"
|
|
|
|
// A request a SuperAdmin made with platform authority — every one the Guard
|
|
// admits for them, read or write, whatever its route and answer — and the
|
|
// platform acts IAM performs for one outside the Guard: unlinking another
|
|
// person's sign-in method, approving a device sign-in for another
|
|
// organization's application. Filed under the actor's own org, the admin org,
|
|
// so the whole trail of platform authority is one query; Organization names
|
|
// the org acted on when there is one.
|
|
ActionSuperAdmin = "superadmin"
|
|
|
|
// A workload in a Kubernetes namespace obtaining its application's token by
|
|
// presenting the ServiceAccount token its cluster minted for it (RFC 7523).
|
|
// The row names the service account that asked, so the trail reads the same
|
|
// whether a credential came from a stored secret or from the cluster.
|
|
ActionWorkloadToken = "workload-token"
|
|
// Invitations: an email sent about one, an account joining an org through one,
|
|
// and the refused attempts to use one — by a signed-in account, and at signup.
|
|
// They are the ledger the send quotas and the attempt limits count, which is
|
|
// why no request may create, alter or remove them.
|
|
ActionInviteSend = "invitation-send"
|
|
ActionInviteAccept = "invitation-accept"
|
|
ActionInviteRefused = "invitation-refused"
|
|
ActionInviteSignupRefused = "invitation-signup-refused"
|
|
// A code IAM sent a signed-in account to prove its address for joining.
|
|
ActionInviteCodeSent = "invitation-code-sent"
|
|
)
|
|
|
|
// PlatformWritten reports whether action names a record the platform writes
|
|
// about itself, and which therefore no request may create, alter, or remove.
|
|
//
|
|
// Read this; never compare the strings. A caller with its own comparison is a
|
|
// second copy of the reserved set, and the two will drift the moment one grows.
|
|
func PlatformWritten(action string) bool {
|
|
switch action {
|
|
case ActionConsentTraining, ActionIssueUserToken, ActionMintUserKeys,
|
|
ActionRevokeUserKeys, ActionTokenExchange, ActionAs,
|
|
ActionAssumeOrg, ActionReleaseOrg, ActionListOrgs, ActionSuperAdmin, ActionWorkloadToken,
|
|
ActionInviteSend, ActionInviteAccept, ActionInviteRefused, ActionInviteSignupRefused,
|
|
ActionInviteCodeSent:
|
|
return true
|
|
}
|
|
return false
|
|
}
|
|
|
|
type AuditLog struct {
|
|
orm.Model[AuditLog]
|
|
|
|
Owner string `json:"owner" orm:"index"`
|
|
Name string `json:"name" orm:"index"`
|
|
CreatedTime string `json:"createdTime" orm:"index"`
|
|
|
|
Organization string `json:"organization" orm:"index"`
|
|
ClientIp string `json:"clientIp"`
|
|
User string `json:"user" orm:"index"`
|
|
Method string `json:"method"`
|
|
RequestUri string `json:"requestUri"`
|
|
Action string `json:"action" orm:"index"`
|
|
Language string `json:"language"`
|
|
|
|
Object string `json:"object"`
|
|
Response string `json:"response"`
|
|
StatusCode int `json:"statusCode"`
|
|
|
|
IsTriggered bool `json:"isTriggered"`
|
|
}
|