agentcredential

package
v0.0.52 Latest Latest
Warning

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

Go to latest
Published: Nov 18, 2026 License: Apache-2.0 Imports: 6 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 agentcredential holds the identity broker credentials of registered agents, in memory only, for the server, which registers them at run entry, and the MCP broker, which presents them on gateway calls. A credential is never persisted and never given to the engine or the model.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrNoCredential is a lookup's error when nothing is held for the key; a
	// lookup never registers.
	ErrNoCredential = errors.New("agentcredential: no credential held")
	// ErrDropped refuses to store a registration whose root was dropped, or
	// the holder closed, while it was in flight.
	ErrDropped = errors.New("agentcredential: entry dropped during registration")
	// ErrOtherAgent refuses a registration that returned an agent other than
	// the one registered.
	ErrOtherAgent = errors.New("agentcredential: broker returned another agent")
	// ErrExpired refuses a registration that returned an expired credential.
	ErrExpired = errors.New("agentcredential: broker returned an expired credential")
)

Functions

This section is empty.

Types

type Credential

type Credential struct {
	// BrokerSessionID is the broker session the agent was registered to; the
	// credential verifies only there.
	BrokerSessionID string
	Agent           identitybroker.AgentRef
	// Owner is the owner the agent was registered with: the run owner under
	// the #2557 shortcut.
	Owner     identitybroker.Owner
	Token     identitybroker.Token
	ExpiresAt time.Time
}

Credential is a held agent credential and what it was registered with.

type Holder

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

Holder holds agent credentials. Callers that take their own lock around Drop take it before the holder's; the holder never calls out while holding its own lock.

func New

func New(broker identitybroker.Service, now func() time.Time) *Holder

New returns a Holder registering through broker, with now as its clock.

func (*Holder) Close

func (h *Holder) Close()

Close drops every credential; later and in-flight stores are refused with ErrDropped, and lookups return ErrNoCredential. A nil Holder holds nothing.

func (*Holder) Credential

func (h *Holder) Credential(ctx context.Context, key Key, renew bool) (Credential, error)

Credential is the MCP broker's lookup. With no entry for key it returns ErrNoCredential: it never opens, reopens, or registers. Past renewAt, or with renew set (after svid_expired), it renews the credential. Renewal is single-flight per key: every lookup, the first included, waits for the one in flight or for its own context, and one lookup's cancellation does not end the renewal. A renewal is stored only if key's root was not dropped and the holder not closed since it started (ErrDropped otherwise). If it fails otherwise, a lookup past half-life gets the held credential while it has not expired; a lookup with renew, made after the broker refused the held credential, gets the renewal's error.

func (*Holder) Drop

func (h *Holder) Drop(root string)

Drop drops every credential held for root's session tree, and refuses to store any registration or renewal for it already in flight. Callers that guard their own state with a lock call it holding that lock. A nil Holder holds nothing.

func (*Holder) Ensure

func (h *Holder) Ensure(ctx context.Context, key Key, req identitybroker.RegisterAgentRequest, admit func() error) error

Ensure is the run-entry path. It registers the agent with req unless the held entry has the same incarnation and broker session and is before renewAt. A registration must return an unexpired credential for an agent whose ID ends in the incarnation and that, with a credential held for the same incarnation, is the held agent; otherwise Ensure returns ErrExpired or ErrOtherAgent and keeps what it held. admit is called, without the holder's lock, only once such a registration succeeded, and its error is returned unchanged; the registration is then stored only if key's root was not dropped since Ensure started and the holder is not closed (ErrDropped). A broker error is returned unchanged.

func (*Holder) Held

func (h *Holder) Held(key Key) (Credential, bool)

Held returns the credential held for key without renewing it, and whether one is held.

type Key

type Key struct{ RootSessionID, AgentSessionID string }

Key names a held credential. For a session's main agent both IDs are the root host session.

Jump to

Keyboard shortcuts

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