ADR-014: Field-Level Group Gating + Role "Belongs" Inheritance¶
Status: Accepted Date: 2026-08
Context¶
Field visibility was either static (FieldDescriptor.readOnly/invisible) or data-conditional (states.visible). Neither could hide a field from some users but not others — the only identity-aware gate was the whole-route permission DSL. The ask: an Odoo-style security-groups model where a field declares groups: string[] and a user only receives it if one of their resolved roles' technical name — or a role they transitively "belong to" — matches.
Two gaps had to close first: roles had no stable, mutation-safe identifier separate from their display Name (reused for the JWT roles claim), and no role-to-role relationship existed at all.
Decision¶
Roles.TechnicalNameis a new, nullable column — the slug a field'sgroupslist matches against.Nameis untouched. Nullable because the ORM's struct-tag auto-migration has nouniquemodifier, so per-tenant uniqueness is a hand-written partial index (idx_roles_tenant_technical_name) — the first unique constraint in the codebase.role_belongsrides the generic CRUD surface, unlike every other auth table — deliberately, so the frontend's existing many-to-many tags widget drives the Roles form's "Belongs" tab with zero new endpoint or widget code.- Group resolution is a recursive CTE, resolved once at token-issue time.
UserRepository. FindGroupswalks direct roles plus every transitively-belongs_torole viaWITH RECURSIVE ... UNION(plainUNION, notUNION ALL, so Postgres's own dedup makes cycles self-terminating — no application-level cycle detection needed). Baked into a new JWTgroupsclaim. - Groups travel through a request via
core/orm/access, not an import ofcore/internal/auth—access.WithGroups/GroupsFromContextmirrors the existing tenant-context pattern, keepingcore/ormauth-agnostic. - Gating is a Go
Optionat registration time:WithFieldGroups(map[string][]string)(column → groups), read bycrud.BuildResponse, which omits a gated field's key entirely — never nulls it — when the caller's groups don't intersect. A field with noGroupsdeclared is completely unaffected. FieldDescriptor.groupson the frontend is a UX mirror, not the security boundary — the server omission already makes a gated field absent from the fetched draft; the client-side check just avoids rendering an empty slot for a field the caller was never sent.
Consequences¶
filter[col]=/search[col]=were not group-aware at first — a caller without a field's group could filter on it and infer values from which rows matched, without the column ever appearing in a response. This was later closed by ADR-015'sRepository.checkColumn.role_belongsis the one deliberate exception to "auth tables are excluded from generic CRUD" — judged acceptable because the edge itself (which role implies which group) is lower-stakes than the identity/credential data the other auth tables guard.- Groups are resolved at token-issue time, not per-request — a
role_belongsedge added mid-session doesn't affect an already-issued token until the next refresh, the same staleness windowpermissionsalready has.
Reference Implementation¶
core/internal/auth/models.go (Roles.TechnicalName, RoleBelongs), core/orm/access/groups.go, core/internal/auth/user_repository.go (FindGroups), core/orm/internal/registry (WithFieldGroups, FieldMeta.Groups), core/orm/internal/crud/dto.go (BuildResponse), core-front/packages/core-front/src/views/descriptor.ts (FieldDescriptor.groups).