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
- func BuildCursorCodec(cfg CursorCodecConfig) (*query.CursorCodec, error)
- func BuildHMACKey(cfg HMACKeyConfig) ([]byte, error)
- func InternalAddrToBaseURL(addr string) string
- func IsRealMode(adapterMode string) bool
- func IsWellKnownDemoKey(key []byte) bool
- func LoadCellHMACKey(cellEnvPrefix string) string
- func LoadConfigCoreKeyProvider() (providerName, masterKey, prevMasterKey string)
- func LoadCursorKeys(cellEnvPrefix string) (primary, previous string)
- func LoadKeySet(adapterMode string, clk clock.Clock) (*auth.KeySet, error)
- func PgxPoolFromProvider(pg capability.PGProvider) (*pgxpool.Pool, error)
- func RejectDemoKey(adapterMode, envName string, key []byte) error
- func ResolveAndRejectDemoKey(adapterMode, envLabel, primary, devDefault string) ([]byte, error)
- func WellKnownDemoKeys() []string
- type CursorCodecConfig
- type HMACKeyConfig
Constants ¶
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 ¶
InternalAddrToBaseURL converts a bind address to an HTTP base URL for the internal HTTP client. Mirrors cmd/corebundle.internalAddrToBaseURL.
func IsRealMode ¶
IsRealMode reports whether adapterMode activates real-mode guards.
func IsWellKnownDemoKey ¶
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 ¶
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 ¶
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 ¶
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 ¶
RejectDemoKey returns an error in real mode when key matches a well-known demo value.
func ResolveAndRejectDemoKey ¶
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.