Documentation
¶
Index ¶
- Variables
- type Action
- type AttributeName
- type Attributes
- type Authorizer
- type CombiningAlgorithm
- type Decision
- type Engine
- func (engine *Engine) Decide(ctx context.Context, request Request) (Decision, error)
- func (engine *Engine) DecideBatch(ctx context.Context, requests []Request) ([]Decision, error)
- func (engine *Engine) ReplaceSnapshot(next *Snapshot, expected Revision) error
- func (engine *Engine) Revision() Revision
- type EngineOption
- type Environment
- type Evaluator
- type Event
- type InstrumentationConfig
- type Instrumented
- type Instrumenter
- type Limits
- type Outcome
- type PolicyDefinition
- type PolicyEvaluationError
- type PolicyID
- type PolicyInfo
- type ReasonCode
- type Request
- type Resource
- type ResourceID
- type ResourceType
- type Revision
- type Snapshot
- type Subject
- type SubjectID
- type SubjectKind
- type TenantID
- type TraceEntry
- type ValidationError
- type Value
- func BoolValue(value bool) Value
- func FloatValue(value float64) (Value, error)
- func IPValue(value netip.Addr) Value
- func IntValue(value int64) Value
- func MustFloatValue(value float64) Value
- func NullValue() Value
- func StringSetValue(values []string) Value
- func StringValue(value string) Value
- func TimeValue(value time.Time) Value
- func (value Value) Bool() (bool, bool)
- func (value Value) CollectionLength() (int, bool)
- func (value Value) Compare(other Value) (int, bool)
- func (value Value) Equal(other Value) bool
- func (value Value) Float() (float64, bool)
- func (value Value) IP() (netip.Addr, bool)
- func (value Value) Int() (int64, bool)
- func (value Value) Kind() ValueKind
- func (value Value) String() (string, bool)
- func (value Value) StringSet() ([]string, bool)
- func (value Value) Time() (time.Time, bool)
- type ValueKind
Constants ¶
This section is empty.
Variables ¶
var ( // ErrInvalidCombiningAlgorithm indicates an unsupported combining algorithm. ErrInvalidCombiningAlgorithm = errors.New("invalid combining algorithm") // ErrInvalidOutcome indicates a decision with an unsupported outcome. ErrInvalidOutcome = errors.New("invalid decision outcome") )
var ( ErrRevisionConflict = errors.New("authorization revision conflict") ErrRevisionNotMonotonic = errors.New("authorization revision is not monotonic") )
var ( ErrNilAuthorizer = errors.New("authorization instrumented authorizer is nil") ErrNilInstrumenter = errors.New("authorization instrumenter is nil") ErrInvalidInstrumentationConfig = errors.New("authorization instrumentation config is invalid") )
var ( ErrInvalidPolicy = errors.New("invalid policy") ErrDuplicatePolicy = errors.New("duplicate policy") ErrInvalidActivationWindow = errors.New("invalid policy activation window") ErrInvalidRevision = errors.New("invalid policy revision") )
var ErrBatchLimitExceeded = errors.New("authorization batch limit exceeded")
var ErrInvalidFloat = errors.New("attribute float must be finite")
var ErrInvalidRequest = errors.New("invalid authorization request")
var ErrNilSnapshot = errors.New("authorization snapshot is nil")
var ErrPolicyLimitExceeded = errors.New("authorization policy limit exceeded")
var ErrPolicyPanic = errors.New("authorization policy panicked")
Functions ¶
This section is empty.
Types ¶
type AttributeName ¶
type AttributeName string
type Attributes ¶
type Attributes map[AttributeName]Value
type CombiningAlgorithm ¶
type CombiningAlgorithm uint8
CombiningAlgorithm determines how multiple policy decisions are resolved.
const ( DenyOverrides CombiningAlgorithm = iota AllowOverrides FirstApplicable PriorityOrder )
func (CombiningAlgorithm) String ¶
func (algorithm CombiningAlgorithm) String() string
String returns the stable name of a combining algorithm.
type Decision ¶
type Decision struct {
Outcome Outcome
Reason ReasonCode
MatchedPolicyIDs []PolicyID
MatchedPolicyIDsTruncated bool
Revision Revision
Trace []TraceEntry
TraceTruncated bool
}
Decision is the result of one or more policy evaluations.
type Engine ¶
type Engine struct {
// contains filtered or unexported fields
}
Engine evaluates every request against one coherent snapshot.
func NewEngine ¶
func NewEngine(snapshot *Snapshot, options ...EngineOption) (*Engine, error)
NewEngine creates an engine from an immutable policy snapshot.
func (*Engine) DecideBatch ¶
DecideBatch evaluates a bounded request set against exactly one snapshot.
func (*Engine) ReplaceSnapshot ¶
ReplaceSnapshot atomically installs a newer snapshot when the caller's expected revision still matches the active view.
type EngineOption ¶
type EngineOption func(*Engine)
func WithClock ¶
func WithClock(clock func() time.Time) EngineOption
WithClock supplies the time used when a request omits Environment.Time.
func WithLimits ¶
func WithLimits(limits Limits) EngineOption
WithLimits configures positive limits and leaves zero-valued fields at safe defaults.
type Environment ¶
type Environment struct {
Time time.Time
Attributes Attributes
}
Environment contains deterministic request-scoped evaluation inputs.
type Evaluator ¶
Evaluator is the bounded, I/O-free decision interface implemented by policy models such as ACL, RBAC, and ABAC.
type Event ¶
type Event struct {
Outcome Outcome
Reason ReasonCode
Revision Revision
MatchedPolicyIDs []PolicyID
MatchedPolicyIDsTruncated bool
TraceCount int
TraceTruncated bool
Duration time.Duration
Failed bool
}
Event contains bounded decision metadata without subject, resource, tenant, attribute, or policy-document contents.
type InstrumentationConfig ¶
type Instrumented ¶
type Instrumented struct {
// contains filtered or unexported fields
}
func NewInstrumented ¶
func NewInstrumented( authorizer Authorizer, instrumenter Instrumenter, config InstrumentationConfig, ) (*Instrumented, error)
type Instrumenter ¶
type PolicyDefinition ¶
type PolicyDefinition struct {
ID PolicyID
Revision Revision
Priority int
ActiveFrom time.Time
ActiveUntil time.Time
Metadata map[string]string
Evaluator Evaluator
}
PolicyDefinition binds a stable policy identity to its evaluator.
type PolicyEvaluationError ¶
PolicyEvaluationError identifies a failed policy without exposing its internal error text. Unwrap retains programmatic error inspection.
func (*PolicyEvaluationError) Error ¶
func (evaluationError *PolicyEvaluationError) Error() string
func (*PolicyEvaluationError) Unwrap ¶
func (evaluationError *PolicyEvaluationError) Unwrap() error
type PolicyInfo ¶
type PolicyInfo struct {
ID PolicyID
Revision Revision
Priority int
ActiveFrom time.Time
ActiveUntil time.Time
Metadata map[string]string
}
PolicyInfo is the safe, inspectable metadata for one snapshotted policy.
type ReasonCode ¶
type ReasonCode string
const ( ReasonDefaultDeny ReasonCode = "default-deny" ReasonInvalidRequest ReasonCode = "invalid-request" ReasonEvaluationError ReasonCode = "evaluation-error" ReasonContextCanceled ReasonCode = "context-canceled" ReasonPolicyInactive ReasonCode = "policy-inactive" ReasonPolicyStale ReasonCode = "policy-stale" )
type Request ¶
type Request struct {
Subject Subject
Action Action
Resource Resource
Tenant TenantID
Environment Environment
Attributes Attributes
}
Request contains the stable, typed inputs shared by every policy model. An empty tenant denotes an explicitly global request scope.
type Resource ¶
type Resource struct {
Type ResourceType
ID ResourceID
Attributes Attributes
}
Resource identifies either a resource type or a concrete resource instance. An empty ID intentionally represents the entire resource type.
type ResourceID ¶
type ResourceID string
type ResourceType ¶
type ResourceType string
type Snapshot ¶
type Snapshot struct {
// contains filtered or unexported fields
}
Snapshot is one coherent, immutable policy view used for a complete decision. Its policy contents are intentionally private.
func NewSnapshot ¶
func NewSnapshot( revision Revision, algorithm CombiningAlgorithm, definitions ...PolicyDefinition, ) (*Snapshot, error)
NewSnapshot validates and creates a revisioned policy snapshot.
func (*Snapshot) Algorithm ¶
func (snapshot *Snapshot) Algorithm() CombiningAlgorithm
Algorithm returns the snapshot's validated combining algorithm.
func (*Snapshot) Policies ¶
func (snapshot *Snapshot) Policies() []PolicyInfo
Policies returns a defensive copy of inspectable policy metadata.
type Subject ¶
type Subject struct {
Kind SubjectKind
ID SubjectID
Groups []SubjectID
Attributes Attributes
}
Subject identifies the principal making an authorization request.
type SubjectKind ¶
type SubjectKind string
SubjectKind identifies the application-defined kind of principal.
const ( SubjectUser SubjectKind = "user" SubjectServiceAccount SubjectKind = "service-account" SubjectAPIKey SubjectKind = "api-key" SubjectGroup SubjectKind = "group" )
type TraceEntry ¶
type TraceEntry struct {
PolicyID PolicyID
Outcome Outcome
Reason ReasonCode
}
TraceEntry records one policy result without request or attribute values.
type ValidationError ¶
type ValidationError struct {
Field string
}
ValidationError identifies an invalid public input without including its potentially sensitive value.
func (*ValidationError) Error ¶
func (validationError *ValidationError) Error() string
func (*ValidationError) Unwrap ¶
func (validationError *ValidationError) Unwrap() error
type Value ¶
type Value struct {
// contains filtered or unexported fields
}
Value is an immutable typed attribute value. Its zero value represents an invalid or missing value and is distinct from explicit null.
func FloatValue ¶
func MustFloatValue ¶
func StringSetValue ¶
func StringValue ¶
func (Value) CollectionLength ¶
CollectionLength reports the cardinality of collection values.
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
Package abac provides a bounded, closed expression model for typed attribute-based authorization.
|
Package abac provides a bounded, closed expression model for typed attribute-based authorization. |
|
Package acl provides typed subject-to-resource access control lists.
|
Package acl provides typed subject-to-resource access control lists. |
|
Package authcache provides explicit advisory cache adapters for portable policy manifests.
|
Package authcache provides explicit advisory cache adapters for portable policy manifests. |
|
Package authhttp provides the canonical net/http authorization adapter.
|
Package authhttp provides the canonical net/http authorization adapter. |
|
Package authlog emits bounded authorization audit events through log/slog.
|
Package authlog emits bounded authorization audit events through log/slog. |
|
Package authn maps immutable authenticated principals into authorization subjects without making authentication depend on authorization.
|
Package authn maps immutable authenticated principals into authorization subjects without making authentication depend on authorization. |
|
Package authorizationtest provides deterministic fixtures, assertions, and conformance checks for authorization integrations.
|
Package authorizationtest provides deterministic fixtures, assertions, and conformance checks for authorization integrations. |
|
Package authotel records bounded authorization metrics and traces through standard OpenTelemetry providers, including providers owned by telemetry.
|
Package authotel records bounded authorization metrics and traces through standard OpenTelemetry providers, including providers owned by telemetry. |
|
Package authrpc provides fail-closed jsonrpc authorization middleware.
|
Package authrpc provides fail-closed jsonrpc authorization middleware. |
|
examples
|
|
|
tenant_documents
command
Package main demonstrates composing tenant RBAC, resource ACL, and a trusted ownership attribute under deny-overrides semantics.
|
Package main demonstrates composing tenant RBAC, resource ACL, and a trusted ownership attribute under deny-overrides semantics. |
|
Package httpauth provides fail-closed net/http authorization integration.
|
Package httpauth provides fail-closed net/http authorization integration. |
|
Package policy provides snapshot inspection, diff, dry-run, and portable policy manifest contracts.
|
Package policy provides snapshot inspection, diff, dry-run, and portable policy manifest contracts. |
|
Package postgres persists complete policy manifests atomically in PostgreSQL.
|
Package postgres persists complete policy manifests atomically in PostgreSQL. |
|
Package rbac provides typed roles, permissions, assignments, and bounded role inheritance.
|
Package rbac provides typed roles, permissions, assignments, and bounded role inheritance. |
|
Package valkey distributes monotonic policy revision invalidations through Valkey without relying on lossy pub/sub delivery for correctness.
|
Package valkey distributes monotonic policy revision invalidations through Valkey without relying on lossy pub/sub delivery for correctness. |