webkey

package
v2.4.19 Latest Latest
Warning

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

Go to latest
Published: Oct 9, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package webkey manages the dedicated web-surface access credential for the embedded web UI. It is a separate credential namespace: the web key is never used as, defaulted to, or derived from http.token or the sync token.

Index

Constants

View Source
const (
	// DefaultFileName is the conventional web key file name inside the Cortex
	// configuration directory.
	DefaultFileName = "web.key"
)
View Source
const EnvKey = "CORTEX_WEB_KEY"

EnvKey is the environment variable that pins the web access key on deployments without a writable state volume (e.g. ephemeral container hosts). When set, the key file is never minted or consulted: verification uses the pinned secret in memory and the previous key file is ignored.

Variables

View Source
var (
	// ErrKeyNotFound indicates no web key file exists at the store path.
	ErrKeyNotFound = errors.New("webkey: web access key file not found")
	// ErrKeyExists indicates the web key file is already present.
	ErrKeyExists = errors.New("webkey: web access key file already exists")
	// ErrInvalidKey is the deterministic rejection for any failed verification.
	ErrInvalidKey = errors.New("webkey: invalid web access key")
	// ErrMalformedKeyFile indicates the key file cannot be parsed.
	ErrMalformedKeyFile = errors.New("webkey: malformed web key file")
	// ErrInsecurePermissions indicates the key file is group/other readable.
	ErrInsecurePermissions = errors.New("webkey: web key file permissions too permissive")
)
View Source
var (
	// ErrInvalidPinnedKey is the deterministic fail-closed rejection for any
	// CORTEX_WEB_KEY value that does not match the minted key format.
	ErrInvalidPinnedKey = errors.New("webkey: CORTEX_WEB_KEY does not match the minted key format (ctx_ + 43 base64url characters)")
)

Functions

func ResolveEnvOverride added in v2.4.17

func ResolveEnvOverride() (string, error)

ResolveEnvOverride returns the trimmed CORTEX_WEB_KEY override ("" when the variable is unset or blank). A non-blank value that fails ValidateSecret is an error so callers can abort startup instead of silently regenerating.

func ValidateSecret added in v2.4.17

func ValidateSecret(secret string) error

ValidateSecret enforces the minted key format: the ctx_ namespace prefix followed by exactly 43 RawURL-base64 characters decoding to a 256-bit secret. It is the fail-closed gate for operator-pinned keys.

Types

type Record

type Record struct {
	Prefix string
	Digest string
}

Record is the non-secret at-rest representation of a web access key. It never carries the plaintext secret.

type Store

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

Store owns a single web key file at a caller-supplied path.

func NewStore

func NewStore(path string) (*Store, error)

NewStore returns a Store bound to path. The path is never defaulted or read from global configuration; callers pass an explicit location.

func (*Store) EnsureFirstBoot

func (s *Store) EnsureFirstBoot() (string, bool, error)

EnsureFirstBoot mints and persists a key when none exists, returning the plaintext with minted=true exactly once. When a key already exists, including the loser of a concurrent first boot, it returns minted=false and no plaintext.

func (*Store) Exists

func (s *Store) Exists() (bool, error)

Exists reports whether a key file is present without revealing its contents.

func (*Store) Generate

func (s *Store) Generate() (string, error)

Generate mints a new web key, persists it with an exclusive create, and returns the plaintext exactly once. It fails with ErrKeyExists when a key file already exists and never leaves a partial file behind.

func (*Store) Load

func (s *Store) Load() (Record, error)

Load reads and validates the persisted record without exposing the secret.

func (*Store) Path

func (s *Store) Path() string

Path reports the key file location.

func (*Store) Regenerate

func (s *Store) Regenerate() (string, error)

Regenerate atomically replaces the persisted key with a freshly minted one and returns the new plaintext exactly once. The previous key remains valid until the replacement write succeeds.

func (*Store) Verify

func (s *Store) Verify(secret string) error

Verify checks secret against the persisted record using prefix lookup and a constant-time digest comparison.

type Verifier

type Verifier interface {
	Verify(secret string) error
}

Verifier validates a presented web access key.

func NewEnvVerifier added in v2.4.17

func NewEnvVerifier(secret string) (Verifier, error)

NewEnvVerifier builds a Verifier for a validated operator-pinned web key.

Jump to

Keyboard shortcuts

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