actor

package
v0.11.9 Latest Latest
Warning

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

Go to latest
Published: Oct 29, 2026 License: Apache-2.0 Imports: 2 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 actor carries the identity of the caller making a request.

An Actor is relay's view of the auth module's principal: the control-plane middleware converts the principal its authenticator chain produced (FromPrincipal) and handlers read it via From(ctx).

Handlers should never read cookies or tokens directly — they go through the Actor in context. This keeps call sites stable across changes to the identity backend (YAML today, Postgres/Kratos/SuperTokens later).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func WithActor

func WithActor(ctx context.Context, a *Actor) context.Context

WithActor returns a context carrying a.

Types

type Actor

type Actor struct {
	// UserID is the durable reference (UUIDv7). Empty means "no user" —
	// usually the admin-token bypass path or anonymous inference traffic.
	UserID string

	// Username is the display name. Subject to change; never use it as
	// a join key.
	Username string

	// SessionID identifies the session this actor came from, for audit
	// correlation. It is derived from, never equal to, the session token: it
	// is stored and shown to audit readers. Empty for the admin-token bypass.
	SessionID string

	// AdminToken is true when this actor came from the RELAY_ADMIN_TOKEN
	// bypass instead of a user session. Authz can grant blanket
	// permissions to break-glass callers.
	AdminToken bool

	// Roles are carried verbatim from the user record at session build;
	// app/authz interprets them. Empty for the admin-token bypass (which
	// AdminToken already marks as all-powerful).
	Roles []string

	// Subjects are the RBAC subject strings this caller acts under
	// ("user:<id>", "group:<name>", …). Built once per request by the
	// session middleware; handlers never assemble them. Empty for the
	// admin-token bypass, which authz short-circuits.
	Subjects []string

	// IdPGroups are the group names an identity provider asserted at login,
	// carried verbatim from the session. Empty for password logins and the
	// admin-token bypass.
	IdPGroups []string
}

Actor is the authenticated caller for the current request.

func From

func From(ctx context.Context) *Actor

From returns the actor in ctx, or nil if no actor is set.

func FromPrincipal added in v0.10.8

func FromPrincipal(p *principal.Principal) *Actor

FromPrincipal converts an authenticated principal to an Actor. The admin-kind principal is the admin-token bypass.

func (*Actor) HasRole added in v0.7.0

func (a *Actor) HasRole(role string) bool

HasRole reports whether the actor carries role.

func (*Actor) IsAuthenticated

func (a *Actor) IsAuthenticated() bool

IsAuthenticated reports whether the actor represents any kind of valid caller (real user session or admin-token bypass).

func (*Actor) Principal added in v0.10.8

func (a *Actor) Principal() principal.Principal

Principal converts a back to the module's principal, as the authorization engine reads it. Admin is set for the admin-token bypass only; which roles also make an admin is authz's rule. An Actor records no credential, so that part is left empty.

Jump to

Keyboard shortcuts

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