authzseed

package
v1.1.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 29, 2026 License: AGPL-3.0 Imports: 6 Imported by: 0

Documentation

Overview

Package authzseed populates the RBAC engine's relation tuples out-of-band: pure constructors (single source of truth) + idempotent Backfill/BootstrapAdmins writers. Write-only; wiring tuples into decisions is Pass 2.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func APIKeySubjectID

func APIKeySubjectID(k models.APIKey) string

APIKeySubjectID resolves an API key's authz subject: explicit subject_id when set, else the tenant service principal. Mirrors the auth layer so backfill membership matches request-time subjects.

func Backfill

func Backfill(ctx context.Context, store authz.Store, db *gorm.DB) error

Backfill derives the full tuple set from existing rows and writes it via store. Idempotent: re-running produces the same set. Reads use db, writes use store, so it can run inside the migration tx (pass authz.PostgresStore(tx), tx).

  • each tenant -> system parent edge + svc:<tenant> membership
  • each tenant_user -> membership (+ admin when role == admin, + owner when role == owner)
  • admin tenant_user -> system#admin for its tenant's svc principal
  • each document -> document#tenant parent edge
  • each api_key -> its subject's membership
  • common/bootstrap pool -> viewer@user:* wildcard (public read)

func BootstrapAdmins

func BootstrapAdmins(ctx context.Context, store authz.Store, db *gorm.DB, emails []string, logger *slog.Logger) error

BootstrapAdmins seeds system:memory#admin for each email with a tenant_users row (verified email -> tenant_users.id); unknown emails are skipped, never invented. Also grants system#admin to every admin tenant's svc principal (operator API-key admin gap; see seedAdminServicePrincipals), independent of the allowlist. Idempotent. Pass the parsed ADMIN_ALLOWED_EMAILS list here.

func CommonPoolViewerWildcard

func CommonPoolViewerWildcard() authz.Tuple

CommonPoolViewerWildcard returns tenant:<bootstrap>#viewer@user:*, the public read grant on the common/bootstrap pool.

func DocumentEditor

func DocumentEditor(docID uuid.UUID, subjectID string) authz.Tuple

DocumentEditor returns document:<D>#editor@user:<subjectID>, a per-document guest write grant (also confers read via the editor⇒viewer rewrite).

func DocumentTenantEdge

func DocumentTenantEdge(docID, tenantID uuid.UUID) authz.Tuple

DocumentTenantEdge returns document:<D>#tenant@tenant:<T>, set at document create; routes document viewer/editor through the owning tenant's membership.

func DocumentViewer

func DocumentViewer(docID uuid.UUID, subjectID string) authz.Tuple

DocumentViewer returns document:<D>#viewer@user:<subjectID>, a per-document guest read grant.

func SystemAdmin

func SystemAdmin(subjectID string) authz.Tuple

SystemAdmin returns system:memory#admin@user:<subjectID>, the global-admin grant seeded from ADMIN_ALLOWED_EMAILS.

func TenantAdmin

func TenantAdmin(tenantID uuid.UUID, subjectID string) authz.Tuple

TenantAdmin returns tenant:<T>#admin@user:<subjectID>.

func TenantManager

func TenantManager(tenantID uuid.UUID, subjectID string) authz.Tuple

TenantManager returns tenant:<T>#manager@user:<subjectID>.

func TenantMember

func TenantMember(tenantID uuid.UUID, subjectID string) authz.Tuple

TenantMember returns tenant:<T>#member@user:<subjectID>.

func TenantOwner

func TenantOwner(tenantID uuid.UUID, subjectID string) authz.Tuple

TenantOwner returns tenant:<T>#owner@user:<subjectID>, the personal-tenant owner grant. An owner folds up into manager (owner ⇒ manager) but not admin, so it confers full self-management without system-admin reach.

func TenantSystemEdge

func TenantSystemEdge(tenantID uuid.UUID) authz.Tuple

TenantSystemEdge returns tenant:<T>#system@system:memory, seeded at tenant create; lets global admins reach admin on every tenant via the "admin from system" rewrite.

func TenantViewer

func TenantViewer(tenantID uuid.UUID, subjectID string) authz.Tuple

TenantViewer returns tenant:<T>#viewer@user:<subjectID>.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL