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 ¶
- Variables
- type Credential
- type Holder
- func (h *Holder) Close()
- func (h *Holder) Credential(ctx context.Context, key Key, renew bool) (Credential, error)
- func (h *Holder) Drop(root string)
- func (h *Holder) Ensure(ctx context.Context, key Key, req identitybroker.RegisterAgentRequest, ...) error
- func (h *Holder) Held(key Key) (Credential, bool)
- type Key
Constants ¶
This section is empty.
Variables ¶
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 ¶
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 ¶
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.