stepup

package
v0.183.0 Latest Latest
Warning

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

Go to latest
Published: Nov 9, 2026 License: MIT Imports: 6 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 stepup is the "prove it's you again" gate: an action that is worth more than an ordinary signed-in request — typing into a mirrored host's tmux, which is a shell on that host — needs a sign-in that happened RECENTLY, not merely a session that is still valid.

The request's authentication time is put on its context by internal/api's session wrapper (WithAuthTime) and read by whoever gates an action (Fresh): today internal/api's mirror terminal socket and its two send routes, and, independently, the mirror plugin's own Attach and Paste (internal/mirror). Neither trusts the other to have checked.

🔴 THE TIME IS THE SIGN-IN'S, NEVER THE TOKEN'S. A GoTrue access token is re-minted by every refresh, so its `iat` says nothing about when the person last proved who they are; its `amr` timestamp does (gotrue.Claims. AuthenticatedAt, measured on v2.189.0 and v2.197.0). In password mode it is the session cookie's issue time, which only a sign-in mints.

🔴 FRESHNESS BELONGS TO ONE SESSION — ONE BROWSER ON ONE DEVICE — NEVER TO THE USER. The time rides in that session's own credential (the GoTrue session's `amr`, carried by its access cookie; in password mode the session cookie itself), and nothing here or in internal/api keeps a per-user "last confirmed" anywhere. Confirming on a laptop therefore leaves the same user's phone exactly as stale as it was (TestAConfirmOnOneSessionLeavesAnotherStale, internal/api). Keep it that way: a per-user clock would let one device's confirm unlock every other signed-in device, including a lost one.

🔴 UNKNOWN IS STALE. A context with no authentication time — a token without `amr`, a machine token, no session at all — is never fresh.

Index

Constants

View Source
const (
	// DefaultWindow is the window when nothing configures one.
	DefaultWindow = 12 * time.Hour
	// MinWindow and MaxWindow bound a configured window (ParseWindow). Below a
	// minute the confirm dialog could not be answered before it expired again;
	// above a day the gate would no longer mean "recently".
	MinWindow = time.Minute
	MaxWindow = 24 * time.Hour
)

The window: how long a sign-in stays fresh enough for a step-up action.

It is ONE value for the whole process, read through Window by every gate and by every sentence that names it to a person (WindowText) — there is no second copy to drift. DefaultWindow unless the deployment configures one (MUSTER_STEPUP_WINDOW, read by cmd/muster-server's config → SetWindow).

View Source
const CredentialMaxAge = 5 * time.Minute

CredentialMaxAge is the SHORTER, FIXED window for an action that changes how the account can be signed in to — today, adding a passkey (internal/api).

🔴 IT IS DELIBERATELY NOT THE CONFIGURABLE WINDOW. The window above was lengthened so that typing into one's own session is not a password wall on every message; a new credential is a different stake — it outlives the session that minted it — so a session left open for hours must not be able to mint one. It does not follow the configured window.

Variables

View Source
var ErrStale error = staleError{}

ErrStale is the refusal for a step-up action on a session that did not sign in within Window. Its text is shown to the person, so it names the remedy.

⚠ WRAP IT WITH A TYPE THAT UNWRAPS TO IT, NOT WITH fmt.Errorf("%w"): Errorf formats its message once, so a wrapper built at package load would keep naming the default window after SetWindow changed it (mirror.ErrStepUpRequired is the worked example).

Functions

func AuthTime

func AuthTime(ctx context.Context) (time.Time, bool)

AuthTime is the request's authentication time, and false when none was recorded.

func Fresh

func Fresh(ctx context.Context, now time.Time) bool

Fresh reports whether the request's person authenticated within Window of now. Unknown is not fresh.

func FreshUntil

func FreshUntil(ctx context.Context) time.Time

FreshUntil is the instant the request's sign-in stops being fresh — zero when there is no authentication time. The terminal page uses it to decide whether to ask before attaching; the server re-checks regardless.

func FreshWithin

func FreshWithin(ctx context.Context, now time.Time, maxAge time.Duration) bool

FreshWithin reports whether the request's person authenticated within maxAge of now. Unknown is not fresh. Fresh is this with Window; the one other caller passes CredentialMaxAge.

func HumanDuration

func HumanDuration(d time.Duration) string

HumanDuration writes d in whole hours, minutes and seconds, largest first, omitting the zero parts: "12 hours", "1 hour 30 minutes", "5 minutes".

func ParseWindow

func ParseWindow(v string) (time.Duration, error)

ParseWindow reads a configured window: "" is DefaultWindow; anything else must be a Go duration ("12h", "45m", "1h30m") within [MinWindow, MaxWindow]. Zero, a negative duration, a bare number and an over-long window are all errors — a deployment that typed the variable wrong must fail to start rather than run with a gate it did not choose.

func SetWindow

func SetWindow(d time.Duration) error

SetWindow configures the window for this process. It refuses anything outside [MinWindow, MaxWindow] and leaves the window as it was.

func Window

func Window() time.Duration

Window is how long a sign-in stays fresh enough for a step-up action.

func WindowText

func WindowText() string

WindowText is the window as a person reads it ("12 hours"): what every user-facing sentence about the gate is built from.

func WithAuthTime

func WithAuthTime(ctx context.Context, t time.Time) context.Context

WithAuthTime records that the request's person authenticated at t.

Types

This section is empty.

Jump to

Keyboard shortcuts

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