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
- Variables
- type AuditEntry
- type DirectoryUser
- type Identity
- type Revoked
- type Service
- func (s *Service) AuditFor(ctx context.Context, userID string, limit int) ([]AuditEntry, error)
- func (s *Service) Directory(ctx context.Context, limit, offset int) ([]DirectoryUser, error)
- func (s *Service) IsOperatorUser(ctx context.Context, userID string) (bool, error)
- func (s *Service) RecentAudit(ctx context.Context, limit int) ([]AuditEntry, error)
- func (s *Service) SetSuspended(ctx context.Context, in SuspensionInput) (*Suspension, error)
- type Set
- type Suspension
- type SuspensionInput
Constants ¶
const ( ActionSuspendUser = "user.suspend" ActionUnsuspendUser = "user.unsuspend" )
Audit actions. They are the stable vocabulary of operator_audit.action.
const MaxDirectoryPage = 500
MaxDirectoryPage caps one directory page.
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 ¶
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 ¶
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).
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 ¶
NewService builds the operator core over the shared pool and the configured profile.
func (*Service) AuditFor ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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) IsOperator ¶
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.
type Suspension ¶
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.