cellsecrets

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jun 7, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package cellsecrets provides helpers shared across the cellmodules/ cell modules (accesscore, auditcore, configcore) and cmd/corebundle.

This package is importable by cmd/corebundle (composition root). It contains helpers that both cellmodules/ cell modules and cmd/ need: demo-key rejection, cursor codec construction, HMAC key loading, JWT key set loading, and the pgxpool type assertion.

Index

Constants

View Source
const RealAdapterMode = "real"

RealAdapterMode is the canonical value activating production fail-fast behavior.

Variables

This section is empty.

Functions

func BuildCursorCodec

func BuildCursorCodec(cfg CursorCodecConfig) (*query.CursorCodec, error)

BuildCursorCodec constructs a CursorCodec from already-read primary and previous key strings.

func BuildHMACKey

func BuildHMACKey(cfg HMACKeyConfig) ([]byte, error)

BuildHMACKey loads and validates the HMAC key.

func InternalAddrToBaseURL

func InternalAddrToBaseURL(addr string) string

InternalAddrToBaseURL converts a bind address to an HTTP base URL for the internal HTTP client. Mirrors cmd/corebundle.internalAddrToBaseURL.

func IsRealMode

func IsRealMode(adapterMode string) bool

IsRealMode reports whether adapterMode activates real-mode guards.

func IsWellKnownDemoKey

func IsWellKnownDemoKey(key []byte) bool

IsWellKnownDemoKey reports whether key matches a shipped public dev default. The comparison uses crypto/subtle.ConstantTimeCompare to avoid timing oracles (startup, not hot-path).

func LoadCellHMACKey

func LoadCellHMACKey(cellEnvPrefix string) string

LoadCellHMACKey reads the HMAC key env var for a specific cell using the per-cell namespace convention (GOCELL_<CELLID>_HMAC_KEY).

func LoadConfigCoreKeyProvider

func LoadConfigCoreKeyProvider() (providerName, masterKey, prevMasterKey string)

LoadConfigCoreKeyProvider reads the configcore-specific KeyProvider configuration:

GOCELL_CONFIGCORE_KEY_PROVIDER
GOCELL_CONFIGCORE_MASTER_KEY
GOCELL_CONFIGCORE_MASTER_KEY_PREVIOUS

func LoadCursorKeys

func LoadCursorKeys(cellEnvPrefix string) (primary, previous string)

LoadCursorKeys reads the cursor HMAC primary and previous keys for a cell.

Env variables read:

GOCELL_<CELLID>_CURSOR_KEY
GOCELL_<CELLID>_CURSOR_PREVIOUS_KEY

func LoadKeySet

func LoadKeySet(adapterMode string, clk clock.Clock) (*auth.KeySet, error)

LoadKeySet returns a KeySet, preferring environment-provided keys. In "real" adapter mode, env keys are required (fail-fast if missing).

func PgxPoolFromProvider

func PgxPoolFromProvider(pg capability.PGProvider) (*pgxpool.Pool, error)

PgxPoolFromProvider is the single type-assertion site for the capability.PGProvider's any-typed DB() seam. Placed here so all cellmodules/ cell modules and cmd/ reuse it without duplicating the assertion.

cellmodules/cellsecrets is a composition-root layer (like cmd/) so importing adapters/ (pgxpool) is architecturally acceptable.

func RejectDemoKey

func RejectDemoKey(adapterMode, envName string, key []byte) error

RejectDemoKey returns an error in real mode when key matches a well-known demo value.

func ResolveAndRejectDemoKey

func ResolveAndRejectDemoKey(adapterMode, envLabel, primary, devDefault string) ([]byte, error)

ResolveAndRejectDemoKey picks key material from primary (or falls back to devDefault in dev mode), fails fast in real mode when primary is empty, and rejects known-demo key values.

func WellKnownDemoKeys

func WellKnownDemoKeys() []string

WellKnownDemoKeys returns a copy of the demo-key denylist for callers that must enumerate every value (e.g. tests asserting each is rejected in real mode). Returning a clone prevents mutation of the unexported backing slice.

Types

type CursorCodecConfig

type CursorCodecConfig struct {
	AdapterMode string
	EnvName     string
	PrevEnvName string
	Primary     string
	Previous    string
	DevDefault  string
	Label       string
}

CursorCodecConfig encapsulates BuildCursorCodec parameters.

type HMACKeyConfig

type HMACKeyConfig struct {
	AdapterMode string
	EnvName     string
	Primary     string
	DevDefault  string
}

HMACKeyConfig encapsulates BuildHMACKey parameters.

Jump to

Keyboard shortcuts

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