mirror of
https://github.com/hanzoai/iam.git
synced 2026-11-19 18:37:16 +00:00
The document could declare an org owner and nothing ever applied it —
provision.Owners had no caller, no test, and no path to the upsert. So the
one thing the document said about humans was inert, and there was no way at
all to declare the machine identity privileged automation needs.
One vocabulary replaces it. An org declares `accounts:`, each with a `type`
that says what it IS — exactly as an app does — so the human superuser and
the service account are one shape with one validator, one derivation and one
apply loop. `owner:` is gone rather than kept beside it: two ways to declare
a user row is the duplication that drifts, and the old key applied nothing,
so nothing depended on it.
The reserved `admin` org is where this lands. Platform sudo is MEMBERSHIP of
that org (authz.Claims.PlatformSudo) and machines are refused by design — an
App principal or an empty membership set reads as a machine, and IAM never
mints `orgs` for a client_credentials token. So a platform-sudo automation
identity CANNOT be a `service` app; it has to be an account. Measured against
the real authz module: a user in `admin` with isAdmin=false is PlatformSudo,
not Machine, and not OrgAdmin — while a client_credentials machine for the
same org holds nothing.
Least privilege, in the parts actually available:
- `service` derives isAdmin=FALSE. PlatformSudo never reads the bit, so
withholding it drops the org-admin self-service grant and nothing else.
- a `service` account may not declare an email. An address is a second way
to RESOLVE an account (login identifier, emailed code, federated link),
and a machine has no mailbox to defend.
- the credential is a `kms://<path>` locator only. The reconciler resolves
it from MOUNTED material (KMS → KMSSecret → Secret → --credentials), never
an in-process KMS fetch — the estate's one secret path. Unset resolves
nothing and PRESERVES, so a shape-only converge needs no secret access.
Refusals are parse-time, ahead of any live mutation: an unknown type, a
password literal, a traversing or absolute ref, a name the store would
rewrite, a duplicate name, a second owner. The derived plan carries no
credential by construction, so --dry-run stays reviewable, and a resolver
error never carries the value it failed on.
The two upserts now share one authed post — the applications endpoint and
the accounts endpoint differ by path and body and nothing else.
60 lines
2.0 KiB
Go
60 lines
2.0 KiB
Go
package provision
|
|
|
|
import (
|
|
"os"
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
// TestShippedDocument derives a real org document from disk, so a change to a
|
|
// shipped provision.yaml is caught here instead of in production. Each org
|
|
// repo points this at its own file in CI:
|
|
//
|
|
// IAM_PROVISION_DOC=infra/k8s/iam/provision.yaml go test ./internal/provision/
|
|
func TestShippedDocument(t *testing.T) {
|
|
path := os.Getenv("IAM_PROVISION_DOC")
|
|
if path == "" {
|
|
t.Skip("set IAM_PROVISION_DOC to check a shipped document")
|
|
}
|
|
raw, err := os.ReadFile(path)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
d, err := Parse(raw)
|
|
if err != nil {
|
|
t.Fatalf("shipped document does not parse: %v", err)
|
|
}
|
|
cs, err := Derive(d)
|
|
if err != nil {
|
|
t.Fatalf("shipped document does not derive: %v", err)
|
|
}
|
|
for _, c := range cs {
|
|
t.Logf("%-16s %s", c.Name, strings.Join(c.RedirectUris, " "))
|
|
}
|
|
if len(cs) == 0 {
|
|
t.Fatal("shipped document derived no clients")
|
|
}
|
|
|
|
// Accounts are the other half of the document and get the same gate, or a
|
|
// change to them is caught in production instead of here. The plan is logged
|
|
// rather than asserted against a fixed list — the document owns WHICH
|
|
// accounts exist; this owns that they derive and that each one's authority is
|
|
// what its type says.
|
|
r := &Reconciler{}
|
|
for _, a := range Accounts(d) {
|
|
u, err := r.user(a)
|
|
if err != nil {
|
|
t.Fatalf("account %s/%s does not derive: %v", a.Org, a.Account.Name, err)
|
|
}
|
|
t.Logf("%-16s %-8s isAdmin=%v email=%q", u.Owner+"/"+u.Name, a.Account.Type, u.IsAdmin, u.Email)
|
|
// A platform-sudo account is one declared under the reserved admin org, and
|
|
// no shipped document may ship one carrying an interactive `owner` grant:
|
|
// automation is `service`, humans are `owner`, and a human superuser in the
|
|
// reserved org would be a shared login rather than a named one.
|
|
if u.Owner == "admin" && a.Account.Type != AccountService {
|
|
t.Errorf("account %s/%s is in the reserved admin org with type %q — platform automation is %q",
|
|
u.Owner, u.Name, a.Account.Type, AccountService)
|
|
}
|
|
}
|
|
}
|