Documentation
¶
Overview ¶
Package admin owns platform role definitions, scoped grants and authorization.
Index ¶
- Variables
- type AdministratorFilter
- type AdministratorPage
- type AdministratorQuery
- type AdministratorSummary
- type AuditBatch
- type AuditPosition
- type AuditProvider
- type AuditRequest
- type AuthorizationMode
- type BatchGrantChangeItem
- type BatchGrantChangeResultItem
- type BatchGrantChangesInput
- type BatchGrantChangesResult
- type BatchItemStatus
- type Effective
- type Filter
- type Grant
- type GrantChangesInput
- type GrantTarget
- type Identity
- type MissingReason
- type Mutation
- type Page
- type Record
- type Repository
- type Revision
- type Role
- type RoleFilter
- type RoleInput
- type RolePage
- type RolePosition
- type RoleQuery
- type Scope
- type Service
- func (s Service) BatchChangeGrants(ctx context.Context, p account.Principal, key string, ...) (BatchGrantChangesResult, error)
- func (s Service) Change(ctx context.Context, p account.Principal, subject, key string, in Mutation, ...) (out Revision, err error)
- func (s Service) ChangeGrants(ctx context.Context, p account.Principal, subject, key string, ...) (out Revision, err error)
- func (s Service) CreateRole(ctx context.Context, p account.Principal, key string, in RoleInput) (out Role, err error)
- func (s Service) Effective(ctx context.Context, p account.Principal, subject string, scope Scope) (out Effective, err error)
- func (s Service) Evaluate(ctx context.Context, p account.Principal, cap string, scope Scope) error
- func (s Service) ListAdministrators(ctx context.Context, p account.Principal, f AdministratorFilter) (AdministratorPage, error)
- func (s Service) ListRoles(ctx context.Context, p account.Principal, f RoleFilter) (RolePage, error)
- func (s Service) Operations(ctx context.Context, p account.Principal, f Filter) (Page, error)
- func (s Service) Role(ctx context.Context, p account.Principal, id string) (out Role, err error)
- func (s Service) Templates(ctx context.Context, p account.Principal) ([]Role, error)
- type Store
Constants ¶
This section is empty.
Variables ¶
var ( ErrInvalid = errors.New("invalid_request") ErrUnauthenticated = errors.New("unauthenticated") ErrForbidden = errors.New("forbidden") ErrConflict = errors.New("conflict") ErrNotFound = errors.New("not_found") // ErrSnapshotExpired wraps ErrUnavailable so callers checking availability stay // compatible while Operations distinguishes expired/cleaned paging snapshots. ErrSnapshotExpired = fmt.Errorf("%w: snapshot_expired", ErrUnavailable) )
var Global = Scope{"*", "*", "*"}
Functions ¶
This section is empty.
Types ¶
type AdministratorFilter ¶ added in v0.2.1
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 AdministratorSummary ¶ added in v0.2.1
type AuditBatch ¶
type AuditPosition ¶
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 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 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 Identity ¶
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" )
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 Role ¶
type RoleFilter ¶ added in v0.2.1
type RolePosition ¶ added in v0.2.1
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) Intersection ¶
Intersection preserves all three restrictions; a group never implies a school.
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 (s Service) BatchChangeGrants(ctx context.Context, p account.Principal, key string, in BatchGrantChangesInput) (BatchGrantChangesResult, error)
func (Service) ChangeGrants ¶ added in v0.2.1
func (Service) CreateRole ¶
func (Service) Evaluate ¶
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 (s Service) ListAdministrators(ctx context.Context, p account.Principal, f AdministratorFilter) (AdministratorPage, error)
func (Service) Operations ¶
type Store ¶
type Store interface {
Role(context.Context, string) (Role, error)
ListRoles(context.Context, RoleQuery) ([]Role, error)
Effective(context.Context, string) (Effective, error)
ListAdministrators(context.Context, AdministratorQuery) ([]AdministratorSummary, error)
CreateRole(context.Context, Role) error
Change(context.Context, string, Mutation, bool) (Revision, error)
ApplyGrantChanges(context.Context, string, string, []GrantTarget, []GrantTarget, string, string, time.Time) (Revision, error)
Record(context.Context, Record) error
Replay(context.Context, string, string, string, time.Time) ([]byte, error)
SaveReplay(context.Context, string, string, string, []byte, time.Time) error
ReadAudit(context.Context, AuditRequest) (AuditBatch, error)
}