Documentation
¶
Overview ¶
Package session implements server-side opaque sessions (plan §5.3): a 256-bit random id handed to the browser, only its SHA-256 hash stored; rotated on login; idle + absolute timeouts that cannot be reopened by a backward wall clock step — even across a process restart (plan §5.9; review #1).
Clock model: within a process, m.now() is monotonic-anchored to boot. Across restarts that anchor resets to the (possibly stepped-back) wall clock, so we additionally clamp to a persisted "high-water mark" of the greatest wall second ever observed. effectiveNow() = max(monotonic-anchored now, high-water) — it never regresses, so an expired session stays expired and GC still purges it after a backward step. Create and Load/GC all use the SAME effective clock.
Index ¶
- Variables
- type Manager
- func (m *Manager) Create(ctx context.Context, username, peerIP, userAgent string) (rawID string, err error)
- func (m *Manager) Delete(ctx context.Context, rawID string) error
- func (m *Manager) DeleteAll(ctx context.Context) (int64, error)
- func (m *Manager) DeleteAllForUser(ctx context.Context, username string) (int64, error)
- func (m *Manager) GC(ctx context.Context) error
- func (m *Manager) Load(ctx context.Context, rawID string) (*Session, error)
- func (m *Manager) Peek(ctx context.Context, rawID string) (*Session, error)
- type Session
Constants ¶
This section is empty.
Variables ¶
var ErrNotFound = errors.New("session: not found")
ErrNotFound means no live session matched (missing, expired, or revoked).
Functions ¶
This section is empty.
Types ¶
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager owns session lifecycle against the DB.
func (*Manager) Create ¶
func (m *Manager) Create(ctx context.Context, username, peerIP, userAgent string) (rawID string, err error)
Create mints a new session for username, returns the raw id for the cookie.
func (*Manager) DeleteAll ¶
DeleteAll revokes EVERY session (used when the auth config changes — password or TOTP — so no session predating the change survives, regardless of which username it was issued under). Returns rows affected.
func (*Manager) DeleteAllForUser ¶
DeleteAllForUser revokes every session for a user (privilege change / forced logout). Returns rows affected.
func (*Manager) GC ¶
GC removes expired sessions; called opportunistically. Uses the same effective clock as Load so a backward step does not strand expired rows.
func (*Manager) Load ¶
Load returns the session for a raw cookie id, enforcing idle + absolute timeouts against the non-regressing effective clock, and ADVANCES last_seen — active use keeps the session alive (this runs on every authed request via the session middleware).
func (*Manager) Peek ¶
Peek is Load WITHOUT advancing last_seen — a read-only liveness check enforcing the SAME idle + absolute expiry. It must not keep an idle session alive, so it's used by the dashboard's focus-loss watchdog status probe (an unfocused tab polling "am I still logged in?" must observe the idle-out, not postpone it).