tokens

package
v0.0.0-...-7c75ef6 Latest Latest
Warning

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

Go to latest
Published: Nov 27, 2026 License: Apache-2.0 Imports: 5 Imported by: 1 module, 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 tokens maintains a per-AgentSession bearer-token registry. The memory HTTP handler uses Lookup to authenticate; the operator's AgentSession reconciler calls Set on EVERY reconcile of a live session and Revoke on deletion.

Every map here is process memory: a restarted operator begins with an empty registry while the per-session Secret holding each token — and every client presenting one — survives untouched. Two things put tokens back. At startup the operator restores every bearer it served (each live session's, each Ready Workshop's) in one pass (pkg/controllers/tokenrestore), and holds the registry in the "restoring" state (BeginRestore / FinishRestore) until that pass is done, so an unknown bearer is answered "retry" rather than "refused" for exactly as long as the registry is incomplete. And the reconciler re-installs a session's token on every pass, not only at creation (see the reconciler's reregisterMemoryToken, which reads the durable value back out of the Secret). Set on creation alone once left a finished session's memory unreadable for the rest of the operator's life, answering every read with a bare 401.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RetryWhileRestoring

func RetryWhileRestoring(w http.ResponseWriter, restoring bool, msg string) bool

RetryWhileRestoring answers w with a retryable 503 + Retry-After when restoring is true, and reports whether it did. A caller that authenticates bearers against a Registry calls it on a lookup MISS, before refusing the bearer: mid-restore, an unknown bearer is far likelier a session not restored yet than a forged token, and a 401 would fail that session for good. Once the restore is done (or on a registry never put in the restoring state) it writes nothing, and the caller's refusal stands. msg is the response body.

restoring must be read with Registry.Restoring BEFORE the lookup that missed. Read after it, a restore that registers the bearer and finishes in between would turn that miss into a permanent 401 for a token that is now valid.

Types

type Registry

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

func NewRegistry

func NewRegistry() *Registry

func (*Registry) Authorizes

func (r *Registry) Authorizes(token string, key memory.NamespacedName) bool

Authorizes reports whether token is registered AND key is one of the session paths it was registered for (the primary or any extra).

This is the READ answer. It says "this token may look at key's data"; it does NOT say the token may change it — see AuthorizesMutation.

func (*Registry) AuthorizesMutation

func (r *Registry) AuthorizesMutation(token string, key memory.NamespacedName) bool

AuthorizesMutation reports whether token may CHANGE data under key: write an entry, delete one, or send a signal into the scope.

Only the token's PRIMARY session qualifies. The extras Set registers are READ scopes — a runner holds them to fetch artifacts produced by ToolCalls it dispatched against per-bundle SpiceboxSessions, and nothing in the runner writes into one. Answering a mutation with Authorizes instead would let a runner's token Put and DELETE across every bundle scope it was registered with — a strictly wider surface than its own session.

func (*Registry) BeginRestore

func (r *Registry) BeginRestore()

BeginRestore puts the registry in the restoring state: it holds no tokens yet, but the sessions they belong to still exist, and their runners are still presenting them. Call it once, at construction, before anything can serve a request against the registry.

While restoring, Restoring reports true, and callers that authenticate bearers answer an unknown one with a retryable 503 rather than a 401. A 401 fails a live session for good, and during a restore an unknown bearer is far likelier a session not restored yet than a forged token. This replaces a fixed post-boot grace, which measured nothing about the restore: on a large install the restore outlasted it, and sessions it had not reached yet were refused permanently.

func (*Registry) FinishRestore

func (r *Registry) FinishRestore()

FinishRestore ends the restoring state. Safe to call more than once, and a no-op on a registry that never began restoring.

func (*Registry) IsAuthzdToken

func (r *Registry) IsAuthzdToken(token string) bool

IsAuthzdToken returns true if the bearer matches the configured authzd token.

func (*Registry) IsChannelsdToken

func (r *Registry) IsChannelsdToken(token string) bool

IsChannelsdToken returns true if the bearer matches the system channelsd token (and the token has been configured). A channelsd token is authorized for GET (read transcript) and POST (append turn) on any session; DELETE remains denied.

func (*Registry) IsWebdToken

func (r *Registry) IsWebdToken(token string) bool

IsWebdToken returns true if the bearer matches the configured webd token. Callers MUST gate it to read operations only — this method reports identity, not authorization. httpsrv does so at both entry points in one vocabulary: ServeHTTP derives a route's access from memoryRouteAccess, and the routes mounted beside /memory/* pass their access to checkSystemBearer, which refuses this token on anything but a read. Reducing the question to "is it a system token?" reintroduces the defect this doc exists to prevent (/inbound-asset once accepted this token on a POST).

func (*Registry) Lookup

func (r *Registry) Lookup(token string) (memory.NamespacedName, bool)

Lookup resolves token to its primary session.

func (*Registry) LookupInfo

func (r *Registry) LookupInfo(token string) (TokenInfo, bool)

LookupInfo resolves token to its full TokenInfo including CallerID.

func (*Registry) PublisherKey

func (r *Registry) PublisherKey(publisher, keyID string) (ed25519.PublicKey, bool)

PublisherKey implements provenance.PublisherKeyLookup.

func (*Registry) Registered

func (r *Registry) Registered(k memory.NamespacedName) bool

Registered reports whether k currently has a token installed. It answers "does this process still know this session's bearer?", which is the question a restarted operator asks before paying to read the token back out of the session's Secret — the maps above are process memory and start empty, while the Secret and every client holding its value do not.

It deliberately says nothing about WHICH token is installed: the caller that re-registers cannot mint, so a true answer means the durable value was already installed by whoever minted it.

func (*Registry) Restoring

func (r *Registry) Restoring() bool

Restoring reports whether the startup restore is still in progress, so an unknown bearer may yet belong to a session whose token is about to return.

func (*Registry) Revoke

func (r *Registry) Revoke(k memory.NamespacedName)

Revoke removes any token associated with k. Idempotent.

func (*Registry) Set

func (r *Registry) Set(k memory.NamespacedName, token string, callerID string, extras ...memory.NamespacedName)

Set installs token for k, replacing (and invalidating) any prior token. callerID is the canonical user ID of the token holder (may be empty). extras lists additional session paths the token should authorize for artifact READS (e.g. per-bundle SpiceboxSessions whose artifacts the AgentSession's runner needs to fetch).

"Reads" is a CONTRACT, not a description: an extra scope is a foreign session's data this token may look at, never one it may write into. Authorizes and AuthorizesMutation are the two halves of that — a consumer answering a mutation with Authorizes grants every extra scope full write access.

func (*Registry) SetAuthzdToken

func (r *Registry) SetAuthzdToken(token string)

SetAuthzdToken records the system-level authzd token. Accepted for GET (read) and POST (append) on every session; DELETE remains denied. Empty string disables.

func (*Registry) SetChannelsdToken

func (r *Registry) SetChannelsdToken(token string)

SetChannelsdToken records the system-level channelsd token. It is accepted for GET (read transcript) and POST (append turn) on every session. DELETE remains denied — only per-session bearers may delete a session's memory. Setting an empty string disables it.

func (*Registry) SetPublisherKey

func (r *Registry) SetPublisherKey(publisher, keyID string, pub ed25519.PublicKey)

SetPublisherKey registers (or appends) a public key for a publisher (caller ID). Old keys remain valid for verifying old entries.

func (*Registry) SetWebdToken

func (r *Registry) SetWebdToken(token string)

SetWebdToken records the system-level webd token. Unlike the channelsd and authzd tokens, it is READ-ONLY: accepted for reads on any session (so webd can serve the browser artifact view) but never for writes or publisher-key registration. webd is browser-facing, so it must not hold a credential that can append to or forge the audit log. Empty string disables it.

func (*Registry) WaitRestored

func (r *Registry) WaitRestored(ctx context.Context) error

WaitRestored blocks until the startup restore has finished or ctx ends. It returns at once for a registry that never began restoring.

type TokenInfo

type TokenInfo struct {
	Session  memory.NamespacedName
	CallerID string
}

TokenInfo holds the session identity and optional caller ID associated with a token.

Jump to

Keyboard shortcuts

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