Documentation
¶
Overview ¶
Package policy provides snapshot inspection, diff, dry-run, and portable policy manifest contracts.
Index ¶
- Constants
- Variables
- func Encode(manifest Manifest) ([]byte, error)
- type Algorithm
- type Compiler
- type CompilerLimits
- type CompilerOption
- type DecisionComparison
- type Decoder
- type DecoderFunc
- type DryRunReport
- type Format
- type Manifest
- type Model
- type Record
- type Repository
- type SnapshotDiff
- type Synchronizer
- func (synchronizer *Synchronizer) Decide(ctx context.Context, request authorization.Request) (authorization.Decision, error)
- func (synchronizer *Synchronizer) LastVerified() (time.Time, bool)
- func (synchronizer *Synchronizer) Observe(ctx context.Context, revision authorization.Revision) error
- func (synchronizer *Synchronizer) Reload(ctx context.Context) (bool, error)
- func (synchronizer *Synchronizer) Run(ctx context.Context) error
- type SynchronizerOption
Constants ¶
const DefaultMaxStaleness = 2 * time.Minute
const DefaultSyncInterval = 30 * time.Second
Variables ¶
var ( ErrNilDecoder = errors.New("policy decoder is nil") ErrMissingDecoder = errors.New("policy decoder is not registered") ErrNilEvaluator = errors.New("policy decoder returned a nil evaluator") ErrDocumentLimitExceeded = errors.New("policy document size limit exceeded") ErrPolicyLimitExceeded = errors.New("policy compiler policy limit exceeded") ErrTotalDocumentLimitExceeded = errors.New("policy compiler total document size limit exceeded") )
var ( ErrInvalidManifest = errors.New("invalid policy manifest") ErrDuplicateRecord = errors.New("duplicate policy record") ErrManifestLimitExceeded = errors.New("policy manifest size limit exceeded") )
var ( ErrNilRepository = errors.New("policy synchronizer repository is nil") ErrNilCompiler = errors.New("policy synchronizer compiler is nil") ErrNilEngine = errors.New("policy synchronizer engine is nil") ErrInvalidSyncInterval = errors.New("policy synchronizer interval is invalid") ErrInvalidMaxStaleness = errors.New("policy synchronizer maximum staleness is invalid") ErrStaleManifest = errors.New("policy repository manifest is stale") ErrPolicyStale = errors.New("authorization policy verification is stale") )
var ErrNilSnapshot = errors.New("policy snapshot is nil")
Functions ¶
Types ¶
type Compiler ¶
type Compiler struct {
// contains filtered or unexported fields
}
Compiler activates portable manifests through an explicit model decoder registry. The registry is copied at construction and is safe for concurrent Compile calls when its decoders are safe for concurrent use.
func NewCompiler ¶
func NewCompiler( decoders map[Model]Decoder, options ...CompilerOption, ) (*Compiler, error)
type CompilerLimits ¶
type CompilerOption ¶
type CompilerOption func(*Compiler)
func WithCompilerLimits ¶
func WithCompilerLimits(limits CompilerLimits) CompilerOption
type DecisionComparison ¶
type DecisionComparison struct {
Index int
Current authorization.Decision
Candidate authorization.Decision
Changed bool
}
type Decoder ¶
type Decoder interface {
Decode(json.RawMessage) (authorization.Evaluator, error)
}
Decoder converts one validated model document into an immutable evaluator.
type DecoderFunc ¶
type DecoderFunc func(json.RawMessage) (authorization.Evaluator, error)
func (DecoderFunc) Decode ¶
func (decode DecoderFunc) Decode( document json.RawMessage, ) (authorization.Evaluator, error)
type DryRunReport ¶
type DryRunReport struct {
FromRevision authorization.Revision
ToRevision authorization.Revision
Decisions []DecisionComparison
}
func DryRun ¶
func DryRun( ctx context.Context, current *authorization.Snapshot, candidate *authorization.Snapshot, requests []authorization.Request, ) (DryRunReport, error)
type Manifest ¶
type Manifest struct {
Format Format `json:"format"`
Revision authorization.Revision `json:"revision"`
Algorithm Algorithm `json:"algorithm"`
Policies []Record `json:"policies"`
}
type Record ¶
type Record struct {
ID authorization.PolicyID `json:"id"`
Revision authorization.Revision `json:"revision"`
Model Model `json:"model"`
Priority int `json:"priority,omitempty"`
ActiveFrom *time.Time `json:"active_from,omitempty"`
ActiveUntil *time.Time `json:"active_until,omitempty"`
Metadata map[string]string `json:"metadata,omitempty"`
Document json.RawMessage `json:"document"`
}
type Repository ¶
type Repository interface {
Load(context.Context) (Manifest, error)
Update(context.Context, authorization.Revision, Manifest) (Manifest, error)
}
Repository is the storage-neutral optimistic-concurrency contract for portable policy manifests.
type SnapshotDiff ¶
type SnapshotDiff struct {
FromRevision authorization.Revision
ToRevision authorization.Revision
AlgorithmChanged bool
Added []authorization.PolicyID
Removed []authorization.PolicyID
Changed []authorization.PolicyID
}
func Diff ¶
func Diff(current, candidate *authorization.Snapshot) (SnapshotDiff, error)
type Synchronizer ¶
type Synchronizer struct {
// contains filtered or unexported fields
}
Synchronizer keeps an engine converged with its authoritative repository. Direct repository polling is the correctness path; external invalidation transports may call Observe to reduce propagation latency.
func NewSynchronizer ¶
func NewSynchronizer( repository Repository, compiler *Compiler, engine *authorization.Engine, options ...SynchronizerOption, ) (*Synchronizer, error)
func (*Synchronizer) Decide ¶
func (synchronizer *Synchronizer) Decide( ctx context.Context, request authorization.Request, ) (authorization.Decision, error)
Decide enforces the maximum age of the last successful repository verification before delegating to the active immutable engine snapshot.
func (*Synchronizer) LastVerified ¶
func (synchronizer *Synchronizer) LastVerified() (time.Time, bool)
LastVerified reports the time of the latest successful authoritative repository verification, including a same-revision verification.
func (*Synchronizer) Observe ¶
func (synchronizer *Synchronizer) Observe( ctx context.Context, revision authorization.Revision, ) error
Observe handles an untrusted invalidation revision by reloading the source of truth. It rejects hints ahead of the repository state.
type SynchronizerOption ¶
type SynchronizerOption func(*Synchronizer)
func WithMaxStaleness ¶
func WithMaxStaleness(maxStaleness time.Duration) SynchronizerOption
func WithSyncInterval ¶
func WithSyncInterval(interval time.Duration) SynchronizerOption
func WithSynchronizerClock ¶
func WithSynchronizerClock(clock func() time.Time) SynchronizerOption