identity

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: May 30, 2026 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Overview

Package identity defines Harbor's load-bearing isolation key.

Every Runtime, Protocol, Memory, State, Skills, Tools, Planner and Governance code path scopes its work by the (TenantID, UserID, SessionID) triple. The triple is the isolation boundary; RunID is the per-execution scope inside a session and is carried by Quadruple — never substituted for Identity in scoping decisions.

Identity is mandatory: there is no opt-out knob (decisions.md D-001). Validate fails closed when any component is empty; With and WithRun validate at write time so bugs surface at the call site.

This package is dependency-free and holds no package-level mutable state beyond two unexported context-key sentinels. Concurrent reuse is safe by construction (decisions.md D-025).

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrIdentityMissing — the context carries no Identity AND no
	// Quadruple. Both MustFrom and MustQuadrupleFrom panic with
	// this sentinel when their respective key is absent.
	ErrIdentityMissing = errors.New("identity: no Identity or Quadruple in context")
	// ErrIdentityIncomplete — one or more components empty. Identity is mandatory.
	ErrIdentityIncomplete = errors.New("identity: one or more components empty")
)

Functions

func Validate

func Validate(id Identity) error

Validate returns an error wrapping ErrIdentityIncomplete when any of (TenantID, UserID, SessionID) is empty. Whitespace-only strings pass; the caller is responsible for input normalization.

func With

func With(ctx context.Context, id Identity) (context.Context, error)

With attaches Identity to ctx. Returns the original ctx and a wrapped ErrIdentityIncomplete if the Identity fails Validate.

func WithRun

func WithRun(ctx context.Context, id Identity, runID string) (context.Context, error)

WithRun attaches a Quadruple (Identity + RunID) to ctx. The Identity must Validate; the RunID must be non-empty. Returns the original ctx and a wrapped ErrIdentityIncomplete on either failure.

Types

type Identity

type Identity struct {
	TenantID  string
	UserID    string
	SessionID string
}

Identity is the load-bearing isolation key. All three components are mandatory; an Identity with any empty component is rejected by Validate.

func From

func From(ctx context.Context) (Identity, bool)

From returns the Identity in ctx and a presence bool. Use when absence is recoverable (e.g. cross-cutting middleware that may run pre-auth).

func MustFrom

func MustFrom(ctx context.Context) Identity

MustFrom returns the Identity in ctx. Panics with ErrIdentityMissing when none is present. Use in handler/runtime paths where the caller has already established that identity is mandatory at this point.

type Quadruple

type Quadruple struct {
	Identity
	RunID string
}

Quadruple is Identity + the per-execution RunID. Used in Envelopes and run-scoped state. Quadruple is NOT a substitute for Identity in scoping decisions: the triple is the isolation boundary; RunID is the per-execution scope inside a session.

func MustQuadrupleFrom

func MustQuadrupleFrom(ctx context.Context) Quadruple

MustQuadrupleFrom returns the Quadruple in ctx. Panics with ErrIdentityMissing when none is present. The Quadruple key is independent from the Identity key: a context attached via With does NOT satisfy MustQuadrupleFrom, and vice versa.

func QuadrupleFrom

func QuadrupleFrom(ctx context.Context) (Quadruple, bool)

QuadrupleFrom returns the Quadruple in ctx and a presence bool.

Directories

Path Synopsis
Package conformancetest exposes the canonical identity-correctness suite that every identity-aware Harbor subsystem (StateStore drivers, MemoryStore drivers, Governance, Audit, Memory) must run.
Package conformancetest exposes the canonical identity-correctness suite that every identity-aware Harbor subsystem (StateStore drivers, MemoryStore drivers, Governance, Audit, Memory) must run.

Jump to

Keyboard shortcuts

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