authtoken

package
v2.4.5 Latest Latest
Warning

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

Go to latest
Published: Oct 31, 2026 License: AGPL-3.0 Imports: 7 Imported by: 0

Documentation

Overview

Package authtoken implements the one-time session token store used by yarilo-auth to hand off authenticated sessions to backend pods without replaying credentials.

Flow:

  1. Login pod authenticates the client via the yarilo-auth AUTH command.
  2. On success yarilo-auth issues a token (Store.Issue) and returns it in the OK response as "token=<hex>".
  3. Login pod forwards the token to the backend in the preamble (XCLIENT TOKEN=<hex>).
  4. Backend calls yarilo-auth VERIFY <id> <token>.
  5. Store.Validate consumes the token (one-time) and returns the bound username and session ID so the backend can enter authenticated state without running passdb again.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type RedisOption

type RedisOption func(*RedisStore)

RedisOption tunes a RedisStore at construction, mirroring locks' options.

func WithKeyPrefix

func WithKeyPrefix(p string) RedisOption

WithKeyPrefix overrides the Redis key prefix. Empty is ignored (keeps the default), so a blank config value does not erase the namespace.

type RedisStore

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

RedisStore is a Redis-backed one-time token store. GETDEL provides atomic consume; Redis TTL replaces the background sweeper.

func NewRedis

func NewRedis(client *redis.Client, ttl time.Duration, opts ...RedisOption) *RedisStore

NewRedis returns a RedisStore. The caller owns the client lifecycle; Close is a no-op.

func (*RedisStore) Close

func (s *RedisStore) Close()

Close is a no-op; the caller manages the Redis client lifecycle.

func (*RedisStore) Consume

func (s *RedisStore) Consume(tok string) bool

Consume removes tok once its session is established (#2259).

func (*RedisStore) Issue

func (s *RedisStore) Issue(username, sessionID, service string) (string, error)

Issue generates a token bound to username, sessionID, and service, kept in Redis for the TTL so any replica validates it.

func (*RedisStore) Validate

func (s *RedisStore) Validate(tok string) (username, sessionID, service string, ok bool)

Validate returns what tok is bound to and leaves it for a retry; ok is false when unknown, consumed, expired or Redis did not answer.

type Store

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

Store issues session tokens (32 random bytes, hex), valid for the TTL until the backend whose session opened consumes it (#2259); a sweeper purges the rest.

func New

func New(ttl time.Duration) *Store

New returns a ready-to-use Store.

func (*Store) Close

func (s *Store) Close()

Close stops the background sweeper.

func (*Store) Consume

func (s *Store) Consume(tok string) bool

Consume removes tok once a session it opened is established, so it cannot open a second one. Reports whether it was there.

func (*Store) Issue

func (s *Store) Issue(username, sessionID, service string) (string, error)

Issue generates a token bound to username, sessionID, and service. The caller must propagate the token to the backend before the TTL elapses.

func (*Store) Validate

func (s *Store) Validate(tok string) (username, sessionID, service string, ok bool)

Validate returns what tok is bound to and leaves it for a retry after a backend that died before its greeting; ok is false when unknown, consumed or expired.

Jump to

Keyboard shortcuts

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