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 ¶
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.
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 ¶
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 ¶
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.