enforce

package
v0.7.4 Latest Latest
Warning

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

Go to latest
Published: Nov 7, 2026 License: Apache-2.0 Imports: 10 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package enforce is the whole of borg's decision procedure (docs/spec.md section 13) behind one call, for a service that decides on a requester's behalf: the organization's latest token and the subject's grants, groups and policy records, each verified against the service's own headers, folded into a verdict, signed into a receipt and handed back. A service adds authorization in one file and keeps its own interface in front of this one, so the dependency on borg lives here and nowhere else in it.

It fails closed. Any read it cannot complete is a deny with a reason, and an allow is reused only within the freshness the service states, which the receipt makes visible by naming the seq it rested on.

Index

Constants

View Source
const DefaultFreshness = 60 * time.Second

DefaultFreshness is how long an allow is reused for one subject and one permission at one seq when the service states no bound of its own.

View Source
const MaxCached = 10000

MaxCached bounds the allows an Enforcer keeps; past it the cache is cleared, which costs a read and never an answer.

Variables

View Source
var ErrNotReady = errors.New("enforce: a reader, a spend source and a wallet are required")

ErrNotReady is a nil reader, spend source or wallet: the Enforcer cannot decide, so it denies.

Functions

This section is empty.

Types

type Enforcer

type Enforcer struct {
	// Reader asks the hosts and verifies what they answer. Its Headers are
	// the service's own, which is what makes a decision the service's.
	Reader *reader.Client
	// Spends says whether an outpoint is spent: a node or an index. Without
	// one nothing is current, and every decision denies (spec section 13).
	Spends reader.Spends
	// Wallet signs receipts; its identity key is the service's, and is the
	// key a checker verifies the receipt under. Originator is the wallet's
	// originator for the service.
	Wallet     wallet.Interface
	Originator string
	// Hall and Org name the organization.
	Hall string
	Org  []byte
	// Freshness bounds how long an allow is reused; zero is
	// DefaultFreshness. A deny is never reused: a member just granted is
	// read afresh.
	Freshness time.Duration
	// Now is the clock; nil is time.Now.
	Now func() time.Time
	// contains filtered or unexported fields
}

Enforcer decides for one organization. Make one per organization a service answers for and keep it: it holds the organization's latest view and the allows it may reuse.

func (*Enforcer) Allow

func (e *Enforcer) Allow(ctx context.Context, subject []byte, permission string) (Verdict, error)

Allow decides whether subject holds permission in the organization now. The permission is what a service asks, in full and with no wildcard. The verdict is a deny with a reason whenever the read could not be completed, and the error says why; a verdict with a receipt is one a checker can verify, whichever way it went.

func (*Enforcer) Forget

func (e *Enforcer) Forget()

Forget drops every reused allow, for a service that learns of a change before the freshness would.

type Verdict

type Verdict struct {
	Allow    bool
	Reason   string
	Decision reader.Decision
	Receipt  *authz.Signed
	Cached   bool
}

Verdict is one decision: the reader's, the signed receipt a checker can verify alone, and whether it was reused from the cache.

Jump to

Keyboard shortcuts

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