rungrant

package
v0.2.36 Latest Latest
Warning

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

Go to latest
Published: Oct 2, 2026 License: MPL-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package rungrant mints and checks the token that travels with one piece of work: proof that the chassis dispatched it, and the id of the run grant row that says what it may ask for.

A token is a claim set and an HMAC over it, the form of a signed URL (chassis/signedurl) under a key of its own:

rg1.<base64url(JSON claims)>.<base64url(HMAC-SHA256)>

The token IDENTIFIES; the row AUTHORIZES. A token carries no allowlist and no budget, so a genuine token is never enough on its own: every request reads the row (chassis/authn), where revocation, a newer generation and a spent budget live. Nothing is stored here, and any node holding the same key verifies any node's token.

A token is a bearer credential until it expires. Keep it out of logs, traces and envelopes.

Index

Constants

View Source
const KeyLabel = "txco/run-grant/v1"

KeyLabel is the derivation label of the signing key (secrets.DeriveKey). Part of the wire contract: changing it invalidates every live token. It differs from every other label, so a token of another kind (a signed URL) never verifies here, nor one of these there.

View Source
const (

	// Prefix starts every token, for a scrubber that finds one by its shape.
	Prefix = version + "."
)

Variables

View Source
var (
	// ErrInvalid is every way a token can be wrong that is not its age:
	// malformed, forged, signed by another key generation.
	ErrInvalid = errors.New("rungrant: invalid token")
	// ErrExpired is a genuine token past its expiry.
	ErrExpired = errors.New("rungrant: token expired")
)

Functions

This section is empty.

Types

type Claims

type Claims struct {
	Grant      string `json:"g"` // run grant id
	Tenant     string `json:"t"` // tenant id, not its slug
	Principal  string `json:"p"`
	Run        string `json:"r"`
	Generation int64  `json:"n"`
	Depth      int    `json:"d,omitempty"`
	Trace      string `json:"x,omitempty"` // the request that minted the grant
	Expires    int64  `json:"e"`           // unix seconds
	KeyVersion int    `json:"k"`           // master-key generation that signed it
}

Claims is what a token says: run grant Grant of tenant Tenant was minted for Principal's run Run at generation Generation, and is good until Expires. Every field but Depth and Trace is required.

type Signer

type Signer struct {
	// contains filtered or unexported fields
}

Signer signs and verifies tokens under one key.

func New

func New(key []byte, keyVersion int) (*Signer, error)

New returns a Signer over key (32 bytes from secrets.DeriveKey with KeyLabel) of the given master-key generation. The Signer keeps its own copy.

func (*Signer) Sign

func (s *Signer) Sign(c Claims) (string, error)

Sign returns the token for c. The Signer stamps its own key generation.

func (*Signer) Verify

func (s *Signer) Verify(token string, now time.Time) (Claims, error)

Verify returns the claims of a genuine, unexpired token. The MAC is checked before a single byte of the claims is parsed.

A nil error says the chassis signed this token and it has not expired. It does NOT say the grant still holds: read the row.

Jump to

Keyboard shortcuts

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