session

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 8, 2026 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package session holds the administrator sessions of the Admin API in memory and makes the random tokens the Admin API and the operator commands hand out.

Only the SHA-256 of a session token is kept; the token itself exists only in the administrator's cookie. Nothing is ever written to disk, so a restart ends every session. The table is bounded and refuses a new session when full. It imports no internal package. The controller ends an administrator's sessions inside its own lock when a credential changes; the Admin API creates, looks up and ends them.

Index

Constants

View Source
const Max = 64

Max is the most sessions held at once.

Variables

View Source
var ErrFull = errors.New("session limit reached")

ErrFull is returned by Create when Max sessions are live.

Functions

func Hash

func Hash(token string) string

Hash returns the hex SHA-256 of a token, the only form that is stored.

func NewToken

func NewToken() string

NewToken returns 32 random bytes in URL-safe base64.

Types

type Session

type Session struct {
	Admin      string
	Credential int64 // administrator credential version at login
	CSRF       string
	Reference  string // non-secret identifier recorded in audit events

	Expires time.Time // absolute end of the session
	// contains filtered or unexported fields
}

Session is one authenticated administrator session. The server keeps only the SHA-256 of the session token; the token itself exists only in the administrator's cookie.

func (Session) Closed

func (s Session) Closed() <-chan struct{}

Closed returns a channel that closes when the session is revoked or swept.

type Table

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

Table holds the live administrator sessions in memory. A restart ends every session; nothing about them is ever written to the database.

func New

func New(idle, lifetime time.Duration) *Table

func (*Table) Active

func (s *Table) Active(token string, now time.Time) bool

func (*Table) Count

func (s *Table) Count() int

Count returns the number of sessions held, live or not yet swept.

func (*Table) Create

func (s *Table) Create(admin string, credential int64, now time.Time) (string, Session, error)

Create starts a session and returns its token. Expired sessions are swept first; if the limit is still reached, no session is created.

func (*Table) Lookup

func (s *Table) Lookup(token string, now time.Time) (Session, string)

Lookup returns the session for a token and records the activity. An unknown token is never adopted; an expired one is removed.

func (*Table) Revoke

func (s *Table) Revoke(token string)

func (*Table) RevokeAdmin

func (s *Table) RevokeAdmin(name string)

RevokeAdmin ends every session of one administrator, as a credential change requires.

Jump to

Keyboard shortcuts

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