subjects

package
v1.132.0 Latest Latest
Warning

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

Go to latest
Published: Sep 16, 2026 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

Package subjects records the subject each address authenticates as, and folds the address-keyed managed-resource library into the subject-keyed one once the pair is known (#1677).

A user library is keyed by subject: a session files there by its own subject, and so does the portal's upload. A managed-script run acts for its version's author and, knowing that person only by address, filed the same path in a second library keyed by the address. This is how the run learns the subject its author's own session uses: the pair is recorded whenever a person authenticates, at the same chokepoint the known-users directory observes, and the run reads it when it opens its session.

Learning the pair is also the moment the two libraries are put back together. Everything filed under the address is refiled under the subject, keeping its id and aliasing the address it vacates, so a scheduled script keeps its rolling file and every reference to it keeps resolving. The fold runs when a person authenticates, so the files a run wrote before this existed are where their session looks, and before a run executes, so the run's next write versions the file rather than starting a second one.

Index

Constants

View Source
const DefaultObserveTTL = 5 * time.Minute

DefaultObserveTTL is the minimum interval between two observations of one pair, so the record and the fold are not repeated on every authenticated request. It matches the users directory's throttle.

Variables

This section is empty.

Functions

This section is empty.

Types

type Book

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

Book is the recorded pairs plus the fold they enable. It is nil-safe: a deployment with no database holds a nil Book and every method is a no-op.

func New

func New(store Store) *Book

New builds a Book over store.

func (*Book) BindResources

func (b *Book) BindResources(deps resource.Deps)

BindResources supplies what a fold refiles through: the record store, the URI scheme, the move trail and the MCP registry callbacks. It is a setter because the managed-resource layer is assembled after the authenticator this Book observes on. Unbound, a Book records pairs and folds nothing.

func (*Book) ForRun

func (b *Book) ForRun(ctx context.Context, address string) string

ForRun is the subject a run acting for address presents, with everything that address filed folded into that subject's library first. It answers "" when the platform has not seen the person authenticate, in which case the run files by address as it did before and nothing is folded.

func (*Book) Observe

func (b *Book) Observe(info *middleware.UserInfo)

Observe records the pair an authenticated person presents and folds their address-keyed library. It is throttled per pair and runs on a background goroutine: recording who authenticated must never block or fail the authentication path. Errors are logged, never returned.

Only a principal that is a person, or stands for one, is recorded: an identity-provider subject, or an API key, which a person holds and which a session presents as its own subject. A script run acts for somebody else and is what this exists to serve; an anonymous or auth-disabled session names nobody.

func (*Book) Subject added in v1.132.0

func (b *Book) Subject(ctx context.Context, address string) (string, error)

Subject is the subject this address authenticates as in its own sessions, or "" when the platform has not seen that person sign in themselves.

It reads only a pair the person recorded, never one a key they hold recorded, because a credential resolving through this authenticates AS them: a key that could write this row could decide who somebody is (#1759). Unlike ForRun it folds nothing -- a caller only asking who somebody is must not move their files as a side effect. A lookup that fails is reported, never reported as "nobody": a credential is refused on the difference.

type Store

type Store interface {
	// Record notes that address most recently authenticated as subject.
	// fromPerson says whether the principal was the person themselves (an
	// identity-provider session) rather than a key they hold: a key's pair
	// never overwrites a person's (#1759).
	Record(ctx context.Context, address, subject string, fromPerson bool) error
	// Lookup returns the subject recorded for address, or "" when the platform
	// has not seen it authenticate. It answers whatever wrote the row.
	Lookup(ctx context.Context, address string) (string, error)
	// LookupPerson returns the subject recorded for address by the person
	// themselves, or "" when the only pair on record was written by a key.
	// A credential that authenticates AS somebody resolves through this, so a
	// key can never decide who somebody is.
	LookupPerson(ctx context.Context, address string) (string, error)
}

Store persists the pair. The PostgreSQL implementation is internal/platform/subjects/postgres.

Directories

Path Synopsis
Package postgres is the identity_subjects table: the subject each address most recently authenticated as, and whether the person themselves recorded it.
Package postgres is the identity_subjects table: the subject each address most recently authenticated as, and whether the person themselves recorded it.

Jump to

Keyboard shortcuts

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