Help us shape the future of Go! Take the 2026 Go Developer Survey

credentials

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Oct 19, 2026 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Overview

Package credentials delivers explicitly sandbox-authorized credentials. Revocable credentials are encrypted and recorded durably before delivery; scope reductions and failed revocations survive process/replica changes.

Index

Constants

This section is empty.

Variables

View Source
var ErrForbidden = errors.New("credential not granted")

Functions

func Scope

func Scope(a *access.SeatAccess, connection string) (connectors.CredentialScope, error)

Scope returns the exact sandbox scope. Platform-only clauses never enter a sandbox credential. A single token cannot represent heterogeneous per-repository permissions, so that combination is rejected.

Types

type Connections

type Connections interface {
	Tracker(orgID, key string) (connectors.Tracker, error)
}

Connections resolves the connection's current adapter. Revocation must be idempotent: retries include a remote success followed by a database failure.

type Ledger added in v0.7.0

type Ledger interface {
	Seat(context.Context, string) (*store.Seat, error)
	RecordIssuedCredential(context.Context, store.IssuedCredential, *access.SeatAccess) error
	ListIssuedCredentials(context.Context) ([]store.IssuedCredential, error)
	SetCredentialPending(context.Context, string) error
	ClaimCredentialRevocation(context.Context, string) (string, error)
	FinishCredentialRevocation(context.Context, string, string, bool) error
	CountIssuedCredentials(context.Context, string, string) (int, error)
}

Ledger is shared by all replicas. Implementations must not fall back to process-local state when durability is unavailable.

type Registry

type Registry struct {
	Connections   Connections
	Ledger        Ledger
	EncryptionKey []byte
	Log           *slog.Logger
	Now           func() time.Time
}

Registry issues credentials only when current, durably checked access permits it. EncryptionKey is a stable 32-byte key shared by all replicas, kept outside the database. Never rotate it while outstanding rows remain.

func (*Registry) Issue

func (r *Registry) Issue(ctx context.Context, org, seatID string, a *access.SeatAccess, connection string) (runtimeapi.CredentialResponse, error)

Issue persists a revocable credential before exposing it to the caller. seatID must be the authenticated stable seat UUID, never its reusable key. Access is read again before minting, and RecordIssuedCredential checks the same seat identity/access while holding a database lock before committing.

func (*Registry) Outstanding

func (r *Registry) Outstanding(org, seat string) int

Outstanding counts unexpired revocable credentials. New callers should use the ledger count directly when they need to distinguish a database error.

func (*Registry) Reconcile

func (r *Registry) Reconcile(ctx context.Context, org string, _ map[string]*access.SeatAccess) []Revoked

Reconcile uses current committed access, not the caller's snapshot, so a stale sync on another replica cannot preserve a revoked scope. The seats argument is retained for source compatibility; the durable store is authoritative.

func (*Registry) RevokeSeat added in v0.3.0

func (r *Registry) RevokeSeat(ctx context.Context, org, seatID string) []Revoked

RevokeSeat makes existing credentials pending even if access is later restored. seatID is the stable identity, never its reusable key. Retries continue in Sweep after the retirement call returns.

func (*Registry) Sweep added in v0.7.0

func (r *Registry) Sweep(ctx context.Context) []Revoked

Sweep checks all persisted credentials, including retired/deleted seats and pending failures. It runs at startup and periodically on every replica.

type Revoked

type Revoked struct {
	Seat, Connection string
	Err              error
}

Revoked is the result of an attempted revocation, or a durable-ledger error.

Jump to

Keyboard shortcuts

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