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 ¶
- Variables
- func TraceView(steps []authz.Step) any
- type Service
- func (s *Service) HandleGet(w http.ResponseWriter, r *http.Request)
- func (s *Service) HandleList(w http.ResponseWriter, _ *http.Request)
- func (s *Service) HandlePublish(w http.ResponseWriter, r *http.Request)
- func (s *Service) HandleSaveDraft(w http.ResponseWriter, r *http.Request)
- func (s *Service) HandleSetEnabled(w http.ResponseWriter, r *http.Request)
- func (s *Service) HandleSimulate(w http.ResponseWriter, r *http.Request)
- func (s *Service) List() ([]Summary, error)
- func (s *Service) LoadError() error
- func (s *Service) Publish(id, by string) (Summary, error)
- func (s *Service) SaveDraft(id string, src []byte, by string) (Summary, error)
- func (s *Service) Set() *authz.Set
- func (s *Service) SetEnabled(id string, enabled bool, by string) (Summary, error)
- func (s *Service) SetSubjectResolver(fn func(id string) (authz.Subject, bool))
- func (s *Service) Version(id string, v int) (versionRecord, bool, error)
- type Summary
Constants ¶
This section is empty.
Variables ¶
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 ¶
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 ¶
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) LoadError ¶
LoadError is why the published set could not be built at startup or at the last publication, or nil.
func (*Service) Publish ¶
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 ¶
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) SetEnabled ¶
SetEnabled switches a published policy on or off.
func (*Service) SetSubjectResolver ¶
SetSubjectResolver installs the lookup a simulation uses for a subject it names by id alone.
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.