grant

package
v0.20.1 Latest Latest
Warning

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

Go to latest
Published: Nov 26, 2026 License: MIT Imports: 8 Imported by: 1 module, 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 grant signs and verifies the bearer grants of the store.

Index

Constants

View Source
const MaxRefs = 64

MaxRefs is the most patterns that a grant holds.

Variables

View Source
var ErrGrant = errors.New("grant: not accepted")

ErrGrant is the one error of a rejected grant. It never says why.

Functions

This section is empty.

Types

type Claims

type Claims struct {
	Kid     string `json:"kid"`
	Scope   Scope  `json:"scope"`
	WS      string `json:"ws,omitempty"`
	Epoch   uint64 `json:"epoch,omitempty"`
	Repo    string `json:"repo,omitempty"`
	Owner   string `json:"owner,omitempty"`
	Subject string `json:"subject,omitempty"`
	// Refs are the ref patterns that a merge grant may move: a ref name, or a prefix that ends in "*". A merge grant
	// with Refs moves only the refs that a pattern matches. A merge grant without Refs moves any ref, until a later
	// release refuses it. No other scope carries Refs.
	Refs []string `json:"refs,omitempty"`
	Exp  int64    `json:"exp"`
}

Claims name what a bearer may do. Epoch is the claim epoch of the workspace when the grant was minted. Subject is for traces and grants nothing.

func (Claims) MovesRef added in v0.19.0

func (c Claims) MovesRef(name string) bool

MovesRef reports whether the grant may move the ref name. It is true for a grant with no Refs.

type Key

type Key struct {
	Kid    string
	Public ed25519.PublicKey
	Scopes []Scope
}

Key is a public key and the scopes that it may sign.

type Scope

type Scope string
const (
	ScopeNode     Scope = "node"
	ScopeRead     Scope = "read"
	ScopeWrite    Scope = "write"
	ScopeImport   Scope = "import"
	ScopeOperator Scope = "operator"
	ScopeMerge    Scope = "merge"
)

func (Scope) Valid added in v0.5.0

func (s Scope) Valid() bool

Valid reports whether s is one of the six scopes.

type Signer

type Signer struct {
	Kid string
	Key ed25519.PrivateKey
}

Signer mints grants with an Ed25519 private key.

func (Signer) Mint

func (s Signer) Mint(c Claims) (string, error)

Mint signs c under the kid of the signer.

type Verifier

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

Verifier accepts grants signed by one of its keys.

func NewVerifier

func NewVerifier(keys ...Key) *Verifier

func (*Verifier) Verify

func (v *Verifier) Verify(token string, now time.Time) (Claims, error)

Verify returns the claims of token when a known key signed it, the scope is allowed for that key, the claims are complete and now is before Exp.

Jump to

Keyboard shortcuts

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