mirror of
https://github.com/hanzoai/iam.git
synced 2026-11-19 18:37:16 +00:00
The training answer was a bool, so "never asked" and "asked and declined" shared a value. Nothing could tell whether an answer had ever been given, which means no screen could know to ask and no data path could treat silence as refusal. Training becomes a tri-state Answer (unanswered/granted/refused) with the zero value being unanswered, so a missing record, an unparseable blob, a wrong JSON type and an unrecognized token all decode to silence. MayTrain admits exactly one value — an explicit "granted" — and is the ONE predicate; pkg/model aliases the type and re-exports the states so a consumer outside this module shares the same definition rather than re-deriving what granted means. The write path validates at the boundary, so an answer this version does not know is refused rather than persisted for a later reader to interpret, and a change to the answer writes an AuditLog row carrying the prior and new value — a grant and a later revocation are both attributable, which overwriting a JSON field is not. The preferences property is now defined once in schema, where the consent record nested in the same blob reads it, so the two cannot drift apart. scripts/mutants.py drives cloud's strict-scored mutation engine against these properties: 8 rows, 8 KILLED. Co-authored-by: Hanzo Dev <[email protected]>
57 lines
2.5 KiB
Go
57 lines
2.5 KiB
Go
// Copyright 2026 Hanzo AI, Inc.
|
|
// SPDX-License-Identifier: MIT OR Apache-2.0
|
|
|
|
// Package model exposes the iam core's identity value types to external feature
|
|
// modules (hanzoiam/*) WITHOUT leaking internal/. They are ALIASES of the core
|
|
// schema, so a module and the core share ONE type — no mapping, no drift.
|
|
package model
|
|
|
|
import "github.com/hanzoai/iam/pkg/schema"
|
|
|
|
type (
|
|
User = schema.User
|
|
Application = schema.Application
|
|
Organization = schema.Organization
|
|
Cert = schema.Cert
|
|
Provider = schema.Provider
|
|
|
|
// OrgRef is the (org, role) membership reference a token carries in its `orgs`
|
|
// claim. Exported here so a consumer (cloud) reads the tenancy set off a v2
|
|
// token WITHOUT importing the dead iam-v1 — the same shape and JSON tags, one
|
|
// canonical definition (schema.OrgRef), no drift.
|
|
OrgRef = schema.OrgRef
|
|
|
|
// Project is the org-scoped work container (owner-scoped by (Owner, Name),
|
|
// where Owner is the owning organization). Exported here so an embedder (cloud)
|
|
// reads/writes the SAME project rows the registered /v1/iam/projects surface serves
|
|
// via pkg/store — one canonical definition (schema.Project), no platform-local
|
|
// clone, replacing the dead iam-v1 object.Project.
|
|
Project = schema.Project
|
|
|
|
// Consent is a user's data-sharing answers, and Answer is the tri-state of one
|
|
// of them. Exported so a consumer outside this module (cloud, and any data path
|
|
// that must not act without an answer) reads the SAME record through the SAME
|
|
// predicate — Consent.MayTrain — instead of re-deriving what "granted" means.
|
|
// Two implementations of that question would eventually disagree, and the one
|
|
// that disagreed by admitting too much would be a consent violation.
|
|
Consent = schema.Consent
|
|
Answer = schema.Answer
|
|
)
|
|
|
|
// The three states of a consent answer, and the property that holds the record.
|
|
// Re-exported as values (not just types) because a caller comparing against a bare
|
|
// string literal is writing the policy a second time.
|
|
const (
|
|
Unanswered = schema.Unanswered
|
|
Granted = schema.Granted
|
|
Refused = schema.Refused
|
|
|
|
// PreferencesKey is the User.Properties entry the consent record nests inside.
|
|
PreferencesKey = schema.PreferencesKey
|
|
)
|
|
|
|
// ConsentOf decodes a consent record out of a preferences blob, failing closed on
|
|
// every malformed input (see schema.ConsentOf). Exposed as a variable bound to the
|
|
// core function so there is one implementation, not a wrapper that could drift.
|
|
var ConsentOf = schema.ConsentOf
|