auth

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 5, 2026 License: MIT Imports: 12 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 auth manages agent tokens, run-scoped worker tokens and peer credential checks (RFC 5.4, 8.2).

Index

Constants

View Source
const HumanPrincipal = "human"

HumanPrincipal is the token name for the human (CLI, hooks, status line).

View Source
const RunTokenPrefix = "run_"

RunTokenPrefix marks worker run tokens.

Variables

View Source
var ErrAuth = errors.New("authentication failed")

ErrAuth is returned for any authentication failure.

Functions

func EnsureToken

func EnsureToken(name string) (string, error)

EnsureToken creates name's token file (0600) if it is missing and returns it.

func PeerUID

func PeerUID(c *net.UnixConn) (int, error)

PeerUID returns the uid of the process on the other end of a Unix socket (SO_PEERCRED).

func ReadToken

func ReadToken(name string) (string, error)

ReadToken reads name's token file.

func TokenPath

func TokenPath(name string) string

TokenPath is where the token for name lives.

Types

type Principal

type Principal struct {
	Agent  string // agent id, or "human"
	Origin string // interactive | cli | worker | human
	RunID  string // set for worker run tokens
	Hop    int    // hop of the message the run is handling
	Thread string // thread of the message the run is handling
}

Principal is an authenticated caller.

func (Principal) IsHuman

func (p Principal) IsHuman() bool

IsHuman reports whether the caller holds the human token.

type Registry

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

Registry validates tokens. Agent tokens come from files; run tokens are minted per run and revoked when the run ends.

func NewRegistry

func NewRegistry() *Registry

NewRegistry returns an empty registry.

func (*Registry) Authenticate

func (r *Registry) Authenticate(agent, token, origin string) (Principal, error)

Authenticate checks {agent, token}. origin is the client's claimed origin for agent tokens ("interactive" or "cli"); it is ignored for run tokens.

func (*Registry) Load

func (r *Registry) Load(agentIDs []string) error

Load ensures and loads tokens for the given agent ids plus the human.

func (*Registry) MintRun

func (r *Registry) MintRun(p Principal) string

MintRun creates a run-scoped token.

func (*Registry) Redact

func (r *Registry) Redact(s string) string

Redact replaces any known token in s with "[redacted]".

func (*Registry) RevokeRun

func (r *Registry) RevokeRun(token string)

RevokeRun invalidates a run token.

Jump to

Keyboard shortcuts

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