Documentation
¶
Overview ¶
Package admin owns platform role definitions, scoped grants and authorization.
Index ¶
- Variables
- type AuditBatch
- type AuditPosition
- type AuditProvider
- type AuditRequest
- type AuthorizationMode
- type Effective
- type Filter
- type Grant
- type Identity
- type Mutation
- type Page
- type Record
- type Repository
- type Revision
- type Role
- type RoleInput
- type Scope
- type Service
- func (s Service) Change(ctx context.Context, p account.Principal, subject, key string, in Mutation, ...) (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) 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)
- 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") )
var Global = Scope{"*", "*", "*"}
Functions ¶
This section is empty.
Types ¶
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 Effective ¶
type Effective struct {
AuthorizationMode AuthorizationMode `json:"authorization_mode"`
Subject string `json:"subject"`
Revision string `json:"revision"`
Grants []Grant `json:"grants"`
}
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 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 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
}
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) Operations ¶
type Store ¶
type Store interface {
Role(context.Context, string) (Role, error)
Effective(context.Context, string) (Effective, error)
CreateRole(context.Context, Role) error
Change(context.Context, string, Mutation, bool) (Revision, error)
Record(context.Context, Record) error
Replay(context.Context, string, string, string) ([]byte, error)
SaveReplay(context.Context, string, string, string, []byte, time.Time) error
ReadAudit(context.Context, AuditRequest) (AuditBatch, error)
}