subjects

package
v1.131.1 Latest Latest
Warning

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

Go to latest
Published: Sep 11, 2026 License: Apache-2.0 Imports: 11 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.

type PostgresStore

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

PostgresStore implements Store over the identity_subjects table.

func NewPostgresStore

func NewPostgresStore(db *sql.DB) *PostgresStore

NewPostgresStore builds the store. A nil db yields a store that records nothing and knows nothing, so a caller need not check.

func (*PostgresStore) Lookup

func (s *PostgresStore) Lookup(ctx context.Context, address string) (string, error)

Lookup reads the subject recorded for address.

func (*PostgresStore) Record

func (s *PostgresStore) Record(ctx context.Context, address, subject string) error

Record upserts the pair, keeping the subject most recently seen.

type Store

type Store interface {
	// Record notes that address most recently authenticated as subject.
	Record(ctx context.Context, address, subject string) error
	// Lookup returns the subject recorded for address, or "" when the platform
	// has not seen it authenticate.
	Lookup(ctx context.Context, address string) (string, error)
}

Store persists the pair.

Jump to

Keyboard shortcuts

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