Help us shape the future of Go! Take the 2026 Go Developer Survey

policy

package
v0.21.0 Latest Latest
Warning

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

Go to latest
Published: Oct 29, 2026 License: AGPL-3.0 Imports: 18 Imported by: 0

Documentation

Overview

Package policy is the policy administration point (ADR-0475 §9): administrators write policies as drafts, publish them as immutable numbered versions, switch them on and off, and try them against a simulated request. What it publishes is compiled once into an immutable authz.Set that the enforcement point reads without a lock.

Design-time state in two sidecar stores owned by the run loop: one record per policy (its draft, its current version, whether it is enabled) and one file per published version, written once. Nothing here reaches the event log; a decision records the policy id and version it was made under, and this store is where that version can be read back.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNotFound   = errors.New("policy: no such policy")
	ErrNoDraft    = errors.New("policy: there is no draft to publish")
	ErrIDMismatch = errors.New("policy: the document's id is not the policy's")
	// ErrInvalid marks a document that does not parse or does not compile: the
	// caller's to fix, as against a store that could not be read or written.
	ErrInvalid = errors.New("policy: invalid document")
)

Functions

func TraceView

func TraceView(steps []authz.Step) any

TraceView renders a trace for a response or an evidence record.

Types

type Service

type Service struct {

	// Limits are the installation's resource budgets. Open sets them to
	// [limits.Default]; the server overwrites them with its own.
	Limits limits.Limits
	// contains filtered or unexported fields
}

Service is the policy area. Build it with Open.

func Open

func Open(loop *runloop.Loop, dir string, now func() time.Time) (*Service, error)

Open opens the stores under dir and compiles what is published. It reads the stores directly rather than through the loop: it runs while the server is being built, before the loop serves anybody, and the loop is not yet running to ask.

func (*Service) HandleGet

func (s *Service) HandleGet(w http.ResponseWriter, r *http.Request)

HandleGet returns one policy with every version it has published.

func (*Service) HandleList

func (s *Service) HandleList(w http.ResponseWriter, _ *http.Request)

HandleList lists every policy.

func (*Service) HandlePublish

func (s *Service) HandlePublish(w http.ResponseWriter, r *http.Request)

HandlePublish publishes the draft as the next version.

func (*Service) HandleSaveDraft

func (s *Service) HandleSaveDraft(w http.ResponseWriter, r *http.Request)

HandleSaveDraft saves the body as the policy's draft, with the warnings it raises.

func (*Service) HandleSetEnabled

func (s *Service) HandleSetEnabled(w http.ResponseWriter, r *http.Request)

HandleSetEnabled switches a policy on or off.

func (*Service) HandleSimulate

func (s *Service) HandleSimulate(w http.ResponseWriter, r *http.Request)

HandleSimulate evaluates a simulated request against the published set — or, with "policy", against that unpublished document in place of its published version — and explains the answer. Nothing is recorded and nothing is enforced, and the answer says so.

func (*Service) List

func (s *Service) List() ([]Summary, error)

List returns every policy, by id.

func (*Service) LoadError

func (s *Service) LoadError() error

LoadError is why the published set could not be built at startup or at the last publication, or nil.

func (*Service) Publish

func (s *Service) Publish(id, by string) (Summary, error)

Publish makes the draft the policy's next version: written once to its own file, then recorded as current and enabled, then compiled into the set. A version file a crash left unrecorded is skipped, never overwritten.

func (*Service) SaveDraft

func (s *Service) SaveDraft(id string, src []byte, by string) (Summary, error)

SaveDraft validates a document and keeps it as the policy's next version. A draft that does not compile is refused here, where its author is.

func (*Service) Set

func (s *Service) Set() *authz.Set

Set is the compiled published set the enforcement point decides with.

func (*Service) SetEnabled

func (s *Service) SetEnabled(id string, enabled bool, by string) (Summary, error)

SetEnabled switches a published policy on or off.

func (*Service) SetSubjectResolver

func (s *Service) SetSubjectResolver(fn func(id string) (authz.Subject, bool))

SetSubjectResolver installs the lookup a simulation uses for a subject it names by id alone.

func (*Service) Version

func (s *Service) Version(id string, v int) (versionRecord, bool, error)

Version reads one published version back.

type Summary

type Summary struct {
	ID            string          `json:"id"`
	Current       int             `json:"current"`
	Enabled       bool            `json:"enabled"`
	Draft         json.RawMessage `json:"draft,omitempty"`
	DraftWarnings []string        `json:"draftWarnings,omitempty"`
	UpdatedAt     int64           `json:"updatedAt"`
	UpdatedBy     string          `json:"updatedBy"`
}

Summary is a policy as the listing shows it.

Jump to

Keyboard shortcuts

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