operator

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Nov 1, 2026 License: MIT Imports: 11 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package operator is Cairn's operator profile (ADR-0029, SPEC-0023 REQ "Operator and User Profiles"): who runs the instance, and the small, audited set of things they may do to it.

The operator is configuration, not a role stored on a user. A signed-in user is an operator while their session's recorded provenance, written "<issuer>|<subject>", is listed in CAIRN_OPERATORS, or while CAIRN_OPERATOR_GROUP is set and the OIDC groups claim their session was minted from carried it. With neither variable set the instance has no operator and every operator route answers 404. An operator is also an ordinary user: they own their personal artifacts exactly as anyone does, and operator status never widens what they may read.

Operator surfaces bound tenant data and never read it (SPEC-0023 REQ "Operator Surfaces Bound Tenant Data and Never Read It"): the directory here returns counts, never an artifact's body, title, link, tags or annotations. Every action that affects a tenant writes an operator_audit row in the same transaction as the action itself.

Governing: ADR-0029, SPEC-0023 REQ "Operator and User Profiles", REQ "Operator Surfaces Bound Tenant Data and Never Read It".

Index

Constants

View Source
const (
	ActionSuspendUser   = "user.suspend"
	ActionUnsuspendUser = "user.unsuspend"
)

Audit actions. They are the stable vocabulary of operator_audit.action.

View Source
const MaxDirectoryPage = 500

MaxDirectoryPage caps one directory page.

View Source
const MaxReasonRunes = 1000

MaxReasonRunes caps an audit reason. The reason is required (the CHECK in 0024) and shown to the affected user, so it is prose, not a document.

Variables

View Source
var (
	ErrReason    = errs.New(errs.CodeValidation, "operator: a reason of 1 to 1000 characters is required")
	ErrSelf      = errs.New(errs.CodeValidation, "operator: an operator cannot suspend themselves")
	ErrProtected = errs.New(errs.CodeValidation, "operator: a CAIRN_OPERATORS identity cannot be suspended; remove it from the list first")
)

Refusals SetSuspended distinguishes, each a validation failure.

Functions

This section is empty.

Types

type AuditEntry

type AuditEntry struct {
	ID             int64
	OperatorHandle string
	TargetUserID   string
	TargetHandle   string
	Action         string
	Reason         string
	Detail         json.RawMessage
	At             time.Time
}

AuditEntry is one operator_audit row, with the users it names rendered as display handles (never emails), so the same row can be shown to the affected user.

type DirectoryUser

type DirectoryUser struct {
	ID          string
	Handle      string
	Actor       string
	CreatedAt   time.Time
	LastSeenAt  *time.Time
	SuspendedAt *time.Time
	// Operator reports that one of the user's sign-in identities is listed in
	// CAIRN_OPERATORS. (A CAIRN_OPERATOR_GROUP operator is one by session,
	// not by identity, and is not flagged here.)
	Operator  bool
	Artifacts int64
	Bytes     int64
}

DirectoryUser is one user as the operator sees them: identity and counts, never content. Actor is the user as rendered on the wire (their verified email, else their actor key); the operator needs it to know whom they are acting on.

type Identity

type Identity struct {
	Issuer  string
	Subject string
}

Identity is one CAIRN_OPERATORS entry: the (issuer, subject) a sign-in records on its session, exactly as it records them (the OIDC issuer is the configured CAIRN_OIDC_ISSUER value; a GitHub sign-in records GitHub's origin and the numeric account id).

func (Identity) String

func (i Identity) String() string

String renders the identity in its configuration form, "<issuer>|<subject>".

type Revoked

type Revoked struct {
	Sessions            int64 `json:"sessions"`
	PersonalTokens      int64 `json:"personal_access_tokens"`
	OAuthGrants         int64 `json:"oauth_grants"`
	OAuthTokens         int64 `json:"oauth_tokens"`
	OAuthAuthorizations int64 `json:"oauth_authorization_codes"`
}

Revoked counts the credentials a suspension ended. All zero on reinstatement: nothing is restored, the user signs in again.

type Service

type Service struct {
	// contains filtered or unexported fields
}

Service is the Postgres-backed operator core: the directory, suspension, and the audit trail both write and read.

func NewService

func NewService(pool *pgxpool.Pool, set *Set) *Service

NewService builds the operator core over the shared pool and the configured profile.

func (*Service) AuditFor

func (s *Service) AuditFor(ctx context.Context, userID string, limit int) ([]AuditEntry, error)

AuditFor returns the audit rows that name userID as their target, newest first: what the affected user reads (SPEC-0023: "readable by the affected user").

func (*Service) Directory

func (s *Service) Directory(ctx context.Context, limit, offset int) ([]DirectoryUser, error)

Directory returns one page of users, oldest first, with the count and total size of the artifacts each owns. Nothing about an individual artifact is read (SPEC-0023 REQ "Operator Surfaces Bound Tenant Data and Never Read It").

func (*Service) IsOperatorUser

func (s *Service) IsOperatorUser(ctx context.Context, userID string) (bool, error)

IsOperatorUser reports whether one of the user's sign-in identities is listed in CAIRN_OPERATORS: the operator check for a caller with no session to read a groups claim from.

func (*Service) RecentAudit

func (s *Service) RecentAudit(ctx context.Context, limit int) ([]AuditEntry, error)

RecentAudit returns the newest audit rows across the instance, for the operator console.

func (*Service) SetSuspended

func (s *Service) SetSuspended(ctx context.Context, in SuspensionInput) (*Suspension, error)

SetSuspended suspends or reinstates a user, and writes its audit row, in one transaction (SPEC-0023 REQ "Database Operation Standards").

Suspension offboards: it deletes the user's sessions and revokes their personal access tokens, OAuth grants with every access and refresh token in them, and unredeemed authorization codes, so none authenticates on the next request (SPEC-0023 "Suspending a user offboards them"). Each authenticator also refuses a suspended user outright, so a credential that raced the revocation, or a new sign-in, still fails. Reinstating clears the flag and restores nothing.

An operator cannot suspend themselves, and a user with a CAIRN_OPERATORS identity cannot be suspended from the console: the list is the operator's to edit, and suspending a configured operator would only lock them out of the instance they run.

type Set

type Set struct {
	// contains filtered or unexported fields
}

Set is the configured operator profile. The zero value and nil both mean "no operator": Enabled reports false and nothing matches.

func Parse

func Parse(operators, group string) (*Set, error)

Parse builds the operator profile from CAIRN_OPERATORS (comma-separated "<issuer>|<subject>" entries) and CAIRN_OPERATOR_GROUP. An entry splits at its FIRST "|", because issuers are URLs and never contain one while subjects may ("auth0|123"). A malformed entry is a boot error naming its 1-based position, never a silently dropped operator.

func (*Set) Enabled

func (s *Set) Enabled() bool

Enabled reports whether the instance has an operator at all. When it is false every operator route answers 404 (SPEC-0023 "No operator configured").

func (*Set) Group

func (s *Set) Group() string

Group is the configured CAIRN_OPERATOR_GROUP, or "".

func (*Set) IsOperator

func (s *Set) IsOperator(issuer, subject, sessionGroup string) bool

IsOperator reports whether a session is an operator's: its provenance is listed, or it recorded the configured operator group at sign-in. A session that recorded a group which is no longer the configured one is not an operator's, so renaming or unsetting CAIRN_OPERATOR_GROUP demotes it.

func (*Set) Len

func (s *Set) Len() int

Len is the number of distinct CAIRN_OPERATORS identities.

func (*Set) Lists

func (s *Set) Lists(issuer, subject string) bool

Lists reports whether (issuer, subject) is a CAIRN_OPERATORS identity. An empty issuer or subject (the development login records neither) never matches.

type Suspension

type Suspension struct {
	UserID      string
	SuspendedAt *time.Time
	Revoked     Revoked
	AuditID     int64
}

Suspension is the outcome of a suspend or unsuspend: the user's state after it, what suspension revoked, and the audit row it wrote.

type SuspensionInput

type SuspensionInput struct {
	// OperatorID is the acting operator's user id.
	OperatorID string
	// UserID is the user acted on.
	UserID string
	// Suspend is true to suspend, false to reinstate.
	Suspend bool
	// Reason is required and shown to the affected user.
	Reason string
}

SuspensionInput is one suspend or unsuspend action.

Jump to

Keyboard shortcuts

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