revocation

package
v2.13.0 Latest Latest
Warning

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

Go to latest
Published: Oct 31, 2026 License: MIT Imports: 7 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 revocation carries credential revocation events, the bus that fans them out, and the watcher that cancels a context when one matches.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Publish

func Publish(ctx context.Context, bus Bus, ev Event) error

Publish sends ev on bus, stamping At when zero.

func PublishQuiet

func PublishQuiet(ctx context.Context, bus Bus, ev Event)

PublishQuiet publishes ev and logs, rather than returns, a delivery failure.

Types

type Bus

type Bus interface {
	// Publish delivers ev to every subscriber, local and remote.
	Publish(ctx context.Context, ev Event) error
	// Subscribe registers fn and returns a func that removes it. fn must not
	// block: it runs on the publisher's or listener's goroutine.
	Subscribe(fn func(Event)) (unsubscribe func(), err error)
}

Bus fans revocation events out to subscribers. The default is in-process; implement it over Postgres NOTIFY or Redis pub/sub so a revocation on one node reaches streams held by another.

type Event

type Event struct {
	Kind   Kind      `json:"kind"`
	ID     string    `json:"id,omitempty"`
	UserID string    `json:"userId,omitempty"`
	Reason string    `json:"reason,omitempty"`
	At     time.Time `json:"at"`
}

Event reports one revocation. An empty ID means "every credential of this kind belonging to UserID".

func FromAudit

func FromAudit(action string, target models.TargetRef, md map[string]any) (Event, bool)

FromAudit maps audit actions that void a credential to events, so every internal revoke path reaches the bus without per-site wiring. It reports false for actions that revoke nothing.

type Kind

type Kind string

Kind says what was revoked.

const (
	Session         Kind = "session"
	APIToken        Kind = "api_token"
	Agent           Kind = "agent"
	AgentCredential Kind = "agent_credential"
	Delegation      Kind = "delegation"
	// Owner means a user was disabled or deleted: every credential
	// that user owns or delegated is void.
	Owner Kind = "owner"
	// OrgMember means a user lost one organization (a SCIM deactivation of
	// a multi-org user) but stays active elsewhere: ID is the organization
	// and UserID the user. Only streams scoped to both are cut.
	OrgMember Kind = "org_member"
)

Revocation kinds.

type MemoryBus

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

MemoryBus is the in-process Bus.

func NewMemoryBus

func NewMemoryBus() *MemoryBus

NewMemoryBus returns an empty in-process bus.

func (*MemoryBus) Publish

func (b *MemoryBus) Publish(_ context.Context, ev Event) error

Publish calls every subscriber synchronously, isolating panics.

func (*MemoryBus) Subscribe

func (b *MemoryBus) Subscribe(fn func(Event)) (func(), error)

Subscribe registers fn.

type Target

type Target struct {
	UserID       string
	SessionID    string
	TokenID      string
	AgentID      string
	CredentialID string
	DelegationID string
	// OrganizationID scopes a stream to one organization; with UserID it is
	// cut when that user is deprovisioned from the organization.
	OrganizationID string
}

Target names the credential a stream was opened with. Set every ID that applies; an event matches when it names any of them.

func (Target) Matches

func (t Target) Matches(ev Event) bool

Matches reports whether ev voids the target.

type WatchOptions

type WatchOptions struct {
	// PollInterval, when positive, also re-validates SessionToken or
	// BearerToken on a timer, a backstop for a bus that missed an event
	// (a remote node, a dropped NOTIFY). Sessions reuse WatchSession.
	PollInterval time.Duration
	// SessionToken is the raw session token to poll.
	SessionToken string
	// BearerToken is the raw API token to poll.
	BearerToken string
}

WatchOptions tunes a revocation watch.

type Watcher

type Watcher struct {
	Bus Bus
	// WatchSession returns a context cancelled when the session dies; nil when sessions are unavailable.
	WatchSession func(ctx context.Context, token string, every time.Duration) (context.Context, context.CancelCauseFunc)
	// CheckBearer re-validates a raw API token; nil when API tokens are off.
	CheckBearer func(ctx context.Context, raw string) error
}

Watcher supplies the credential re-validation a watch polls with.

func (Watcher) Watch

Watch returns a context cancelled, with an error wrapping models.ErrCredentialRevoked as its cause, as soon as an event matches target or a poll finds the credential invalid. Call the cancel func when the stream ends.

Jump to

Keyboard shortcuts

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