admin

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Nov 19, 2026 License: AGPL-3.0 Imports: 17 Imported by: 3 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 admin owns platform role definitions, scoped grants and authorization.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalid         = errors.New("invalid_request")
	ErrUnauthenticated = errors.New("unauthenticated")
	ErrForbidden       = errors.New("forbidden")
	ErrConflict        = errors.New("conflict")
	ErrNotFound        = errors.New("not_found")
	ErrUnavailable     = errors.New("unavailable")
	// ErrSnapshotExpired wraps ErrUnavailable so callers checking availability stay
	// compatible while Operations distinguishes expired/cleaned paging snapshots.
	ErrSnapshotExpired = fmt.Errorf("%w: snapshot_expired", ErrUnavailable)
)
View Source
var Global = Scope{"*", "*", "*"}

Functions

This section is empty.

Types

type AdministratorFilter added in v0.2.1

type AdministratorFilter struct {
	Scope      Scope
	RoleID     string
	Capability string
	Cursor     string
	Limit      int
}

type AdministratorPage added in v0.2.1

type AdministratorPage struct {
	Items      []AdministratorSummary `json:"items"`
	NextCursor string                 `json:"next_cursor"`
}

type AdministratorQuery added in v0.2.1

type AdministratorQuery struct {
	Scopes       []Scope
	RoleID       string
	Capability   string
	AfterSubject string
	Limit        int
}

type AdministratorSummary added in v0.2.1

type AdministratorSummary struct {
	Subject  string  `json:"subject"`
	Revision string  `json:"revision"`
	Grants   []Grant `json:"grants"`
}

type AuditBatch

type AuditBatch struct {
	Records  []Record
	Snapshot string
}

type AuditPosition

type AuditPosition struct {
	Time       time.Time
	Source, ID string
}

AuditPosition is a strict descending key (time, source, ID). IDs must be immutable and unique within a provider. Strings use bytewise ordering.

type AuditProvider

type AuditProvider interface {
	ReadAudit(context.Context, AuditRequest) (AuditBatch, error)
}

AuditProvider is implemented by module-owned public query adapters and wired by backend. ReadAudit respects cancellation, returns at most Limit records in descending key order, and returns a nonempty snapshot token (max 256 bytes). Token validity must account for retention; expired data cannot imply completeness.

type AuditRequest

type AuditRequest struct {
	Principal             account.Principal
	Scopes                []Scope
	Actor, Target, Action string
	From, Until           time.Time
	Before                *AuditPosition
	Snapshot              string
	Limit                 int
}

AuditRequest is constructed only after authorization. Providers must apply the union of Scopes and all filters BEFORE limiting, using their own repository. Snapshot pins membership: later inserts, including backdated rows, must not enter it. Expired snapshots return an error, never a newly created snapshot. No provider may return material contents, payment payloads or raw audit JSON.

type AuthorizationMode

type AuthorizationMode string
const (
	PlatformAdminAll AuthorizationMode = "platform_admin_all"
	ExplicitGrants   AuthorizationMode = "explicit_grants"
)

type BatchGrantChangeItem added in v0.2.1

type BatchGrantChangeItem struct {
	Subject          string        `json:"subject"`
	ExpectedRevision string        `json:"expected_revision"`
	Add              []GrantTarget `json:"add"`
	Revoke           []GrantTarget `json:"revoke"`
}

type BatchGrantChangeResultItem added in v0.2.1

type BatchGrantChangeResultItem struct {
	Subject         string          `json:"subject"`
	Status          BatchItemStatus `json:"status"`
	Revision        string          `json:"revision"`
	CurrentRevision string          `json:"current_revision,omitempty"`
	Adding          []Grant         `json:"adding"`
	Revoking        []Grant         `json:"revoking"`
}

type BatchGrantChangesInput added in v0.2.1

type BatchGrantChangesInput struct {
	DryRun bool                   `json:"dry_run"`
	Reason string                 `json:"reason"`
	Items  []BatchGrantChangeItem `json:"items"`
}

type BatchGrantChangesResult added in v0.2.1

type BatchGrantChangesResult struct {
	DryRun bool                         `json:"dry_run"`
	Items  []BatchGrantChangeResultItem `json:"items"`
}

type BatchItemStatus added in v0.2.1

type BatchItemStatus string
const (
	BatchReady     BatchItemStatus = "ready"
	BatchSucceeded BatchItemStatus = "succeeded"
	BatchConflict  BatchItemStatus = "conflict"
	BatchForbidden BatchItemStatus = "forbidden"
	BatchNotFound  BatchItemStatus = "not_found"
)

type Effective

type Effective struct {
	AuthorizationMode AuthorizationMode `json:"authorization_mode"`
	Subject           string            `json:"subject"`
	Revision          string            `json:"revision"`
	Grants            []Grant           `json:"grants"`
}

type Filter

type Filter struct {
	Sources               []string
	Scope                 Scope
	Target, Actor, Action string
	From, Until           time.Time
	Cursor                string
	Limit                 int
}

type Grant

type Grant struct {
	Role  Role  `json:"role"`
	Scope Scope `json:"scope"`
}

type GrantChangesInput added in v0.2.1

type GrantChangesInput struct {
	Add              []GrantTarget `json:"add"`
	Revoke           []GrantTarget `json:"revoke"`
	ExpectedRevision string        `json:"expected_revision"`
	Reason           string        `json:"reason"`
}

type GrantTarget added in v0.2.1

type GrantTarget struct {
	RoleID string `json:"role_id"`
	Scope  Scope  `json:"scope"`
}

type Identity

type Identity interface {
	PlatformAdmin(context.Context, account.Principal) (bool, error)
}

Identity must consult trusted current identity facts, including account status. It returns false,nil for an active non-platform administrator and fails closed for revoked identities or unavailable identity providers. Never use request roles.

type MissingReason added in v0.2.1

type MissingReason string
const (
	MissingSnapshotExpired MissingReason = "snapshot_expired"
	MissingUnconfigured    MissingReason = "unconfigured"
	MissingTimeout         MissingReason = "timeout"
	MissingUnavailable     MissingReason = "unavailable"
)

type Mutation

type Mutation struct {
	RoleID           string `json:"role_id"`
	Scope            Scope  `json:"scope"`
	ExpectedRevision string `json:"expected_revision"`
	Reason           string `json:"reason"`
}

type Page

type Page struct {
	Partial        bool                     `json:"partial"`
	MissingModules []string                 `json:"missing_modules"`
	MissingReasons map[string]MissingReason `json:"missing_reasons"`
	QueriedModules []string                 `json:"queried_modules"`
	Source         string                   `json:"source"`
	Items          []Record                 `json:"items"`
	NextCursor     string                   `json:"next_cursor"`
}

type Record

type Record struct {
	RoleID    string    `json:"role_id,omitempty"`
	Revision  string    `json:"revision,omitempty"`
	ID        string    `json:"id"`
	Source    string    `json:"source"`
	Actor     string    `json:"actor"`
	Action    string    `json:"action"`
	Target    string    `json:"target"`
	Scope     Scope     `json:"scope"`
	Reason    string    `json:"reason"`
	Result    string    `json:"result"`
	CreatedAt time.Time `json:"created_at"`
}

type Repository

type Repository interface {
	// View provides one consistent, uncached authorization/query snapshot.
	View(context.Context, func(Store) error) error
	// Write serializes authorization reads, changes, receipts and audit commits.
	Write(context.Context, func(Store) error) error
}

type Revision

type Revision struct {
	Revision string `json:"revision"`
}

type Role

type Role struct {
	CreatedAt    *time.Time `json:"created_at,omitempty"`
	ID           string     `json:"id"`
	Name         string     `json:"name"`
	LabelKey     string     `json:"label_key,omitempty"`
	Capabilities []string   `json:"capabilities"`
}

func Templates

func Templates() []Role

Templates are suggestions only. Sensitive actions are never bundled into them.

type RoleFilter added in v0.2.1

type RoleFilter struct {
	Keyword    string
	Capability string
	Cursor     string
	Limit      int
}

type RoleInput

type RoleInput struct {
	Role   Role   `json:"role"`
	Reason string `json:"reason"`
}

type RolePage added in v0.2.1

type RolePage struct {
	Items      []Role `json:"items"`
	NextCursor string `json:"next_cursor"`
}

type RolePosition added in v0.2.1

type RolePosition struct {
	CreatedAt time.Time `json:"created_at"`
	ID        string    `json:"id"`
}

type RoleQuery added in v0.2.1

type RoleQuery struct {
	Before     *RolePosition
	Keyword    string
	Capability string
	Limit      int
}

type Scope

type Scope struct {
	School string `json:"school"`
	Group  string `json:"group"`
	Module string `json:"module"`
}

func (Scope) Contains

func (s Scope) Contains(t Scope) bool

func (Scope) Intersection

func (s Scope) Intersection(t Scope) (Scope, bool)

Intersection preserves all three restrictions; a group never implies a school.

func (Scope) Valid

func (s Scope) Valid() bool

type Service

type Service struct {
	// AuditProviders is an immutable host registry; a nil provider is configured but unavailable.
	AuditProviders map[string]AuditProvider
	Repo           Repository
	Identity       Identity
	Now            func() time.Time
	Logger         *slog.Logger
}

func (Service) BatchChangeGrants added in v0.2.1

func (Service) Change

func (s Service) Change(ctx context.Context, p account.Principal, subject, key string, in Mutation, revoke bool) (out Revision, err error)

func (Service) ChangeGrants added in v0.2.1

func (s Service) ChangeGrants(ctx context.Context, p account.Principal, subject, key string, in GrantChangesInput) (out Revision, err error)

func (Service) CreateRole

func (s Service) CreateRole(ctx context.Context, p account.Principal, key string, in RoleInput) (out Role, err error)

func (Service) Effective

func (s Service) Effective(ctx context.Context, p account.Principal, subject string, scope Scope) (out Effective, err error)

func (Service) Evaluate

func (s Service) Evaluate(ctx context.Context, p account.Principal, cap string, scope Scope) error

Evaluate accepts an authenticated, trusted principal and the object's actual scope supplied by the owning service. No identity or scope comes from a client flag. Every call checks current identity. Non-platform administrators also read current grants; trusted platform administrators need no explicit grant for any capability.

func (Service) ListAdministrators added in v0.2.1

func (Service) ListRoles added in v0.2.1

func (s Service) ListRoles(ctx context.Context, p account.Principal, f RoleFilter) (RolePage, error)

func (Service) Operations

func (s Service) Operations(ctx context.Context, p account.Principal, f Filter) (Page, error)

func (Service) Role

func (s Service) Role(ctx context.Context, p account.Principal, id string) (out Role, err error)

func (Service) Templates added in v0.2.1

func (s Service) Templates(ctx context.Context, p account.Principal) ([]Role, error)

Templates returns non-sensitive role suggestions after verifying the caller's live identity.

Directories

Path Synopsis
Package httpapi exposes platform administration through an authenticated host.
Package httpapi exposes platform administration through an authenticated host.

Jump to

Keyboard shortcuts

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