authz

package
v0.36.0 Latest Latest
Warning

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

Go to latest
Published: Nov 22, 2026 License: Apache-2.0 Imports: 11 Imported by: 1 module, 1 package

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 authz carries the record of one authorization decision: what a service decided about one subject, over which state, and its signature.

The decision itself is the application's. borg's contract defines what a role and a binding mean and folds them into a subject's effective permissions; a service establishes the subject's membership, fetches the records and evaluates them. This package writes down what came of that, so that a decision can be checked afterwards by someone who was not there: the receipt names the organization token the decision rested on, the grants and policy records it used, and the answer, and it is signed by the service that gave the answer.

A receipt is evidence, never authority. Holding one grants nothing: it says only that a service decided something at a time, against a state anyone can fetch and check for themselves.

Index

Constants

View Source
const (
	// ProtocolName is the BRC-43 protocol name of a decision signature, at
	// security level 1: the signature is one anyone verifies from the
	// signer's published identity key.
	ProtocolName = "authz decision"
	// KeyID is the key id that protocol derives under.
	KeyID = "receipt"
)

Registry values, frozen once a receipt is published.

View Source
const (
	RKMagic      = 0
	RKBy         = 1
	RKOrg        = 2
	RKHall       = 3
	RKSubject    = 4
	RKPermission = 5
	RKAllow      = 6
	RKSeq        = 7
	RKToken      = 8
	RKGrants     = 9
	RKPolicies   = 10
	RKTime       = 11
	RKReason     = 12
)

Receipt keys.

View Source
const (
	// MaxReceipt bounds an encoded receipt.
	MaxReceipt = 4096
	// MaxUsed bounds the commitments one receipt lists per kind.
	MaxUsed = 64
	// MaxPermission bounds the asked permission, borg's bound.
	MaxPermission = 256
	// MaxHall bounds the rendezvous name a receipt carries.
	MaxHall = 64
	// MaxReason bounds the label a denial carries.
	MaxReason = 64
	// MaxTime is the last second RFC 3339 can write.
	MaxTime = 253402300799
)

Bounds.

Variables

View Source
var (
	ErrTooLarge  = record.ErrTooLarge
	ErrCBOR      = record.ErrCBOR
	ErrKeyType   = record.ErrKeyType
	ErrMagic     = record.ErrMagic
	ErrMissing   = record.ErrMissing
	ErrType      = record.ErrType
	ErrRange     = record.ErrRange
	ErrList      = record.ErrList
	ErrIdentity  = errors.New("authz: key is not a canonical compressed key")
	ErrSignature = errors.New("authz: signature does not verify under the signer's key")
)

The refusals.

View Source
var Derivation = pushdrop.Derivation{
	Protocol: wallet.Protocol{SecurityLevel: wallet.SecurityLevelEveryApp, Protocol: ProtocolName},
	KeyID:    KeyID,
}

Derivation is the derivation a receipt's signature is made and checked under: counterparty anyone, so a verifier derives the key from the signer's identity key alone.

View Source
var MagicReceipt = []byte{'a', 'z', 'r', 0x01}

MagicReceipt is key 0 of a receipt: "az", 'r', version 1.

Functions

This section is empty.

Types

type Receipt

type Receipt struct {
	// By is the identity key of the service that decided.
	By []byte // key 1
	// Org is the organization whose state the decision rested on.
	Org []byte // key 2
	// Hall is that organization's rendezvous.
	Hall string // key 3
	// Subject is the key the decision was about.
	Subject []byte // key 4
	// Permission is what was asked, in full and with no wildcard.
	Permission string // key 5
	// Allow is the answer.
	Allow bool // key 6
	// Seq and Token name the organization token the decision rested on: the
	// state a checker fetches to reach the same answer.
	Seq   uint64   // key 7
	Token [32]byte // key 8, txid in hash byte order
	// Grants and Policies are the commitments of the records the decision
	// used, ascending.
	Grants   [][32]byte // key 9
	Policies [][32]byte // key 10
	// Time is when the service decided, Unix seconds on its own clock.
	Time uint64 // key 11
	// Reason is a short label for a denial, empty for an allow.
	Reason string // key 12
	// Extra holds integer keys above the last this version defines.
	Extra cbor.Map
}

Receipt is one decision, as it is written down and signed.

func Decode

func Decode(b []byte) (*Receipt, error)

Decode parses a receipt in the refusal order.

func (*Receipt) Encode

func (r *Receipt) Encode() ([]byte, error)

Encode writes the receipt in canonical CBOR, the bytes a signature covers.

func (*Receipt) Validate

func (r *Receipt) Validate() error

Validate applies every rule that needs only the receipt itself.

type Signed

type Signed struct {
	// Record is the receipt exactly as it was signed.
	Record []byte
	// Signature is strict low-S DER over SHA-256 of Record.
	Signature []byte
}

Signed is a receipt and the signature over it, the pair a service hands out and a checker reads.

func Sign

func Sign(ctx context.Context, w wallet.Interface, originator string, r *Receipt) (*Signed, error)

Sign writes the receipt and signs it through the service's wallet, under the receipt derivation. The wallet's identity key MUST be the receipt's By, or nobody can check the signature.

func (*Signed) Verify

func (s *Signed) Verify() (*Receipt, error)

Verify reads a signed receipt and checks its signature under the key the receipt names as its signer. It returns the decoded receipt only when the signature verifies, so a caller cannot read a receipt it has not checked.

Jump to

Keyboard shortcuts

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