identity

package
v1.0.310 Latest Latest
Warning

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

Go to latest
Published: Oct 24, 2026 License: MIT Imports: 9 Imported by: 0 modules, 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 identity is the listener-independent MCP principal + resolved-identity model for both capabilities (Management and Gateway). It represents the DISTINCT principal types, the explicit delegation chain, the immutable resolved identity context, and the one-identity-per-protocol-session binding.

It is a pure data engine: it binds no socket, performs no network I/O, and makes no allow/deny policy decision (that is PR-6). It receives already-validated authentication material (from internal/mcp/authn and internal/mcp/senderconstraint) and returns either a validated immutable context or a typed rejection. It never holds a raw token — only a one-way sanitized correlation digest.

Deliberately NOT the SWG/browser identity model: there is no browser session identity, no client_id-as-audience, no flat human-only principal, no SWG role as MCP authorization. The principal types are separate structs, never one generic map with optional fields.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Agent

type Agent struct {
	AgentID string
	Owner   PrincipalRef // MUST reference the authenticated subject
	Version string
	Managed ManagedState
	Trust   TrustClass
}

Agent is an agent principal that acts on behalf of a subject.

type AssuranceLevel

type AssuranceLevel uint8

AssuranceLevel is the subject's authentication-assurance level.

CAUTION (OVN-05). The labels below describe NIST-AAL-style HUMAN authentication strength. Culvert cannot currently determine that: no `amr`/`acr` claim is parsed anywhere, so no AAL fact exists in the product. What is actually derived is the strength of the VERIFIED SENDER BINDING — a DPoP proof shows the presenter controls the token's key, not that a person completed MFA.

Express a sender-constraint requirement with the policy fields `principal.sender_binding` / `principal.sender_bound`, not with this value, and do not "upgrade" the derivation to claim an AAL it cannot observe — see docs/design/mcp/OPEN-DECISION-assurance-model.md.

Higher is stronger; the capability config sets the minimum accepted.

const (
	// AssuranceUnknown — no assurance asserted (rejected where a minimum is required).
	AssuranceUnknown AssuranceLevel = iota
	// AssuranceLow — single-factor / basic.
	AssuranceLow
	// AssuranceMedium — multi-factor.
	AssuranceMedium
	// AssuranceHigh — hardware-backed / phishing-resistant.
	AssuranceHigh
)

type BindingStore

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

BindingStore binds exactly one resolved identity to one protocol session, keyed by session id. It is deliberately DECOUPLED from the PR-1 session.Manager: it holds its own leaf lock and never calls into the session manager while holding it (and the manager never calls into this store), so no ABBA lock cycle with the session manager is possible. The caller wires session lifecycle by calling Unbind when a session closes/expires — this keeps the store listener-independent.

Invariants (all tested):

  • a binding is created only after successful authentication (the caller passes a validated *ResolvedContext);
  • the binding is immutable once set;
  • re-binding the SAME identity (equal Fingerprint) is idempotent;
  • binding a DIFFERENT identity to the same session is rejected and the existing binding retained (covers subject/tenant/client/agent/capability/server-resource change — all of which change the fingerprint);
  • one session can never read another session's identity (keyed by id);
  • a rejected bind never deletes or alters an existing valid binding;
  • Unbind removes the binding (session close/expiry).

func NewBindingStore

func NewBindingStore() *BindingStore

NewBindingStore returns an empty binding store.

func (*BindingStore) Bind

func (s *BindingStore) Bind(sessionID string, ctx *ResolvedContext) (*ResolvedContext, error)

Bind associates ctx with sessionID. First bind sets it. A subsequent bind with an identity whose Fingerprint equals the existing one is idempotent (returns the existing binding, nil error). A bind with a DIFFERENT fingerprint is rejected with ReasonSessionIdentityRebind and the existing binding is retained unchanged.

func (*BindingStore) Get

func (s *BindingStore) Get(sessionID string) (*ResolvedContext, bool)

Get returns the identity bound to sessionID, if any. A session can only ever observe its own binding.

func (*BindingStore) Len

func (s *BindingStore) Len() int

Len returns the number of bound sessions.

func (*BindingStore) Unbind

func (s *BindingStore) Unbind(sessionID string)

Unbind removes the binding for sessionID (idempotent). Callers invoke it when the protocol session closes or expires. A malformed or rejected authentication must NOT call Unbind — only a genuine session-close does — so a failed auth can never delete a valid binding.

type Client

type Client struct {
	ClientID   string // OAuth client_id
	AppID      string // application / deployment id
	Tenant     TenantID
	Capability protocol.Capability // MUST match the resolved context capability
	Trust      TrustClass
}

Client is an OAuth client / application principal.

type ConfirmationMethod

type ConfirmationMethod uint8

ConfirmationMethod is the sender-constraint proof method carried in the context.

const (
	// ConfirmNone — no sender constraint (bearer).
	ConfirmNone ConfirmationMethod = iota
	// ConfirmDPoP — DPoP proof-of-possession.
	ConfirmDPoP
	// ConfirmMTLS — mutual-TLS certificate binding.
	ConfirmMTLS
)

type Human

type Human struct {
	Subject    string // stable subject identifier (sub)
	Tenant     TenantID
	Groups     []string
	Assurance  AssuranceLevel
	Issuer     string
	SessionRef string // session / delegation reference (never a raw token)
}

Human is a human subject principal.

type Link struct {
	Kind PrincipalKind
	ID   string
}

Link is one stable, typed link in the delegation chain. It carries a typed reference, never a display name.

type ManagedState

type ManagedState uint8

ManagedState is whether an agent runs under managed control.

const (
	// ManagedUnknown — not asserted.
	ManagedUnknown ManagedState = iota
	// Managed — the agent is centrally managed.
	Managed
	// Unmanaged — the agent is not centrally managed.
	Unmanaged
)

type PrincipalKind

type PrincipalKind uint8

PrincipalKind is the type tag of a principal, used by typed cross-references (e.g. an Agent's owner) so a reference can never be mistaken for another type.

const (
	// KindNone — the zero value: no principal.
	KindNone PrincipalKind = iota
	// KindHuman — a human subject.
	KindHuman
	// KindWorkload — a non-human workload/service subject.
	KindWorkload
	// KindAgent — an agent principal.
	KindAgent
	// KindClient — an OAuth client / application.
	KindClient
	// KindTenant — a tenant.
	KindTenant
	// KindServer — a registered MCP server.
	KindServer
	// KindTool — a catalog tool.
	KindTool
	// KindResource — a protected resource.
	KindResource
)

func (PrincipalKind) String

func (k PrincipalKind) String() string

String returns the principal-kind label.

type PrincipalRef

type PrincipalRef struct {
	Kind PrincipalKind
	ID   string
}

PrincipalRef is a stable, typed reference to another principal (never a display name). An Agent's owner, for example, is a PrincipalRef the chain validates against the authenticated subject.

type ResolveInput

type ResolveInput struct {
	Capability        protocol.Capability
	Tenant            Tenant
	Subject           Subject
	Agent             *Agent             // optional; if present its owner must be the subject
	Client            Client             // required
	Server            *registry.ServerID // Gateway only
	Tool              *ToolRef           // Gateway only; optional
	Resource          *ResourceRef       // optional protected-resource reference
	CanonicalResource string             // the validated canonical Culvert resource (audience)
	Issuer            string
	Scopes            []string
	Assurance         AssuranceLevel
	SenderConstraint  SenderConstraint
	Expiry            time.Time
	AuthTime          time.Time
	HasAuthTime       bool
	TokenDigest       string // one-way sanitized correlation digest; never a raw token
}

ResolveInput is the already-token-validated material the identity layer resolves into an immutable context. The authn layer fills it after validating the token (signature, issuer, audience, expiry, scopes); the identity layer validates the PRINCIPAL CHAIN, tenant consistency, capability isolation, and Gateway server/tool resolution. It carries NO raw token — only a sanitized digest.

type ResolvedContext

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

ResolvedContext is the immutable, validated resolved identity. Fields are unexported and read through accessors (slices are copied out) so a consumer can neither mutate it nor extract a raw token — there is deliberately no RawToken / ForwardToken / AuthorizationHeader accessor.

func Resolve

Resolve validates a ResolveInput into an immutable ResolvedContext, or returns a typed rejection. It makes NO allow/deny policy decision; it only proves the principal chain, tenant consistency, capability isolation, and Gateway server/tool resolution. reg/cat may be nil for Management (which must not reference a server/tool).

func (*ResolvedContext) Agent

func (c *ResolvedContext) Agent() (Agent, bool)

Agent returns the agent principal and whether one is present.

func (*ResolvedContext) Assurance

func (c *ResolvedContext) Assurance() AssuranceLevel

Assurance returns the subject assurance level.

func (*ResolvedContext) AuthTime

func (c *ResolvedContext) AuthTime() (time.Time, bool)

AuthTime returns the authentication time and whether it is present.

func (*ResolvedContext) CanonicalResource

func (c *ResolvedContext) CanonicalResource() string

CanonicalResource returns the validated canonical Culvert resource (audience).

func (*ResolvedContext) Capability

func (c *ResolvedContext) Capability() protocol.Capability

Capability returns the surface the identity is scoped to.

func (*ResolvedContext) Chain

func (c *ResolvedContext) Chain() []Link

Chain returns the explicit causal delegation chain of a resolved context, in order:

subject (Human|Workload) → Agent → Client → Culvert capability → Server → Tool → Resource

Management stops at the Culvert capability and never carries a Server/Tool link (Resolve rejects a Management context that does). Optional links (Agent, and the Gateway Server/Tool/Resource) are simply absent when not present — they are NEVER synthesized from display names or untrusted parameters.

func (*ResolvedContext) Client

func (c *ResolvedContext) Client() Client

Client returns the OAuth client / application principal.

func (*ResolvedContext) Expiry

func (c *ResolvedContext) Expiry() time.Time

Expiry returns the token expiry.

func (*ResolvedContext) Fingerprint

func (c *ResolvedContext) Fingerprint() string

Fingerprint returns the stable identity fingerprint used for binding equality (NOT pointer identity or display names).

func (*ResolvedContext) Issuer

func (c *ResolvedContext) Issuer() string

Issuer returns the token issuer.

func (*ResolvedContext) Scopes

func (c *ResolvedContext) Scopes() []string

Scopes returns a copy of the granted scopes.

func (*ResolvedContext) SenderConstraint

func (c *ResolvedContext) SenderConstraint() SenderConstraint

SenderConstraint returns the sender-constraint state.

func (*ResolvedContext) Server

func (c *ResolvedContext) Server() (registry.ServerID, bool)

Server returns the Gateway server id and whether one is present.

func (*ResolvedContext) Subject

func (c *ResolvedContext) Subject() Subject

Subject returns the authenticated subject (Human or Workload) as a deep copy, so a consumer can never mutate the context's internal principal (which would diverge it from its precomputed fingerprint).

func (*ResolvedContext) Tenant

func (c *ResolvedContext) Tenant() Tenant

Tenant returns the tenant.

func (*ResolvedContext) TenantID

func (c *ResolvedContext) TenantID() TenantID

TenantID returns the tenant id.

func (*ResolvedContext) TokenDigest

func (c *ResolvedContext) TokenDigest() string

TokenDigest returns the one-way sanitized token correlation digest.

func (*ResolvedContext) Tool

Tool returns the tool reference, its carried catalog eligibility, and presence. The eligibility is CARRIED for downstream policy (PR-6); PR-3 never turns a quarantined/review state into an allow decision.

type ResourceRef

type ResourceRef struct {
	Type   string // stable resource type
	ID     string // stable resource identifier
	Tenant TenantID
	Scope  string // bounded scope representation
}

ResourceRef is a protected-resource principal reference.

type SenderConstraint

type SenderConstraint struct {
	Method     ConfirmationMethod
	Thumbprint string
}

SenderConstraint is the sender-constraint state carried into the context. The thumbprint is a sanitized public confirmation value (a DPoP jkt or an x5t#S256), never key material.

type Subject

type Subject struct {
	Kind     SubjectKind
	Human    *Human
	Workload *Workload
}

Subject is the single authenticated subject: exactly one of Human or Workload. Modeling it as a tagged union (not two optional fields) makes "both set" and "neither set" representable-but-rejected at validation, never silently ignored.

type SubjectKind

type SubjectKind uint8

SubjectKind selects which subject a Subject carries.

const (
	// SubjectNone — no subject (invalid).
	SubjectNone SubjectKind = iota
	// SubjectHuman — the subject is a Human.
	SubjectHuman
	// SubjectWorkload — the subject is a Workload.
	SubjectWorkload
)

type Tenant

type Tenant struct {
	ID        TenantID
	Isolation string // isolation-boundary identifier
	Residency string // optional residency classification
}

Tenant is a tenant principal / isolation boundary.

type TenantID

type TenantID string

TenantID is a stable tenant identifier. Tenant isolation is enforced by exact equality across every reference in a resolved context.

type ToolRef

type ToolRef struct {
	Server registry.ServerID
	Name   string
}

ToolRef references a catalog tool by its PR-2 key (server + name). Authorization by name alone is forbidden; the key binds the tool to a specific server.

type TrustClass

type TrustClass uint8

TrustClass is a supplied risk/trust classification. It is carried, never synthesized, and is not itself a policy decision.

const (
	// TrustUnknown — no classification supplied.
	TrustUnknown TrustClass = iota
	// TrustUntrusted — explicitly untrusted.
	TrustUntrusted
	// TrustLow — low trust.
	TrustLow
	// TrustHigh — high trust.
	TrustHigh
)

type Workload

type Workload struct {
	Service     string // stable service identity
	Tenant      TenantID
	Namespace   string
	Environment string
	Attestation string // attestation reference
	Issuer      string
}

Workload is a non-human workload/service subject principal.

Jump to

Keyboard shortcuts

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