Documentation
¶
Overview ¶
Package vault provides composable secrets management, feature flags, and runtime configuration for Go applications.
Vault unifies three capabilities behind a single API surface:
- Secrets: Encrypted key-value storage with versioning and rotation
- Feature Flags: Boolean/string/int/float toggles with targeting rules
- Runtime Config: Hot-reloadable settings with per-tenant overrides
All entity IDs use TypeID (go.jetify.com/typeid) via a single id.ID struct with dynamic prefixes, consistent with Chronicle and the broader Forge ecosystem.
Usage:
v, err := vault.New(
vault.WithStore(memoryStore),
vault.WithEncryptionKey(key),
)
if err != nil { ... }
// Secrets
// An empty appID uses the one configured with WithAppID.
secret, err := v.Secrets().Get(ctx, "openai_api_key", "")
// Feature flags
enabled := v.Flags().Bool(ctx, "new_dashboard", false)
// Runtime config
limit := v.Config().Int(ctx, "rate_limit", 100)
Index ¶
- Variables
- type Config
- type Entity
- type ID
- type Option
- type Prefix
- type Vault
- func (v *Vault) AppID() string
- func (v *Vault) Audit() *audit.Logger
- func (v *Vault) Config() *config.Service
- func (v *Vault) ConfigManager() *configmgr.Manager
- func (v *Vault) EncryptionAlgorithm() string
- func (v *Vault) EncryptionEnabled() bool
- func (v *Vault) FlagCacheTTL() time.Duration
- func (v *Vault) FlagEngine() *flag.Engine
- func (v *Vault) FlagManager() *flag.Manager
- func (v *Vault) Flags() *flag.Service
- func (v *Vault) Health(ctx context.Context) error
- func (v *Vault) Overrides() *override.Resolver
- func (v *Vault) Rotation() *rotation.Manager
- func (v *Vault) Secrets() *secret.Service
- func (v *Vault) Store() store.Store
Constants ¶
This section is empty.
Variables ¶
var ( // Store errors. ErrNoStore = core.ErrNoStore // Key/entity not found errors. ErrKeyNotFound = core.ErrKeyNotFound ErrSecretNotFound = core.ErrSecretNotFound ErrFlagNotFound = core.ErrFlagNotFound ErrConfigNotFound = core.ErrConfigNotFound ErrOverrideNotFound = core.ErrOverrideNotFound ErrRotationNotFound = core.ErrRotationNotFound ErrAuditNotFound = core.ErrAuditNotFound ErrRunNotFound = core.ErrRunNotFound ErrDLQNotFound = core.ErrDLQNotFound ErrCronNotFound = core.ErrCronNotFound ErrEventNotFound = core.ErrEventNotFound ErrWorkflowNotFound = core.ErrWorkflowNotFound // Crypto errors. ErrDecryptionFailed = core.ErrDecryptionFailed ErrEncryptionFailed = core.ErrEncryptionFailed ErrInvalidKey = core.ErrInvalidKey // Feature flag errors. ErrFlagDisabled = core.ErrFlagDisabled ErrFlagExists = core.ErrFlagExists ErrInvalidFlagKey = core.ErrInvalidFlagKey // Rotation errors. ErrRotationFailed = core.ErrRotationFailed ErrUnauthorized = core.ErrUnauthorized // Secret errors. ErrSecretExists = core.ErrSecretExists // Config errors. ErrConfigExists = core.ErrConfigExists // ErrConfigVersionNotFound is returned when a config entry has no // version with the requested number. ErrConfigVersionNotFound = core.ErrConfigVersionNotFound )
Sentinel errors for Vault operations.
These are the same values as their core counterparts, not copies, so errors.Is keeps matching for every caller that wrapped one.
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct {
// AppID is the application identifier used for scoping secrets, flags, and config.
AppID string `json:"app_id" yaml:"app_id"`
// EncryptionKey is the master encryption key (32 bytes for AES-256-GCM).
// If empty, encryption is disabled (not recommended for production).
EncryptionKey []byte `json:"-" yaml:"-"`
// EncryptionKeyEnv names an environment variable to read the encryption
// key from when EncryptionKey is not set directly. This is not a
// fallback that degrades to plaintext: naming the variable is a
// statement of intent, so if it is set, its value must decode to a
// valid key or New fails. It is the empty EncryptionKeyEnv (alongside
// an empty EncryptionKey) that means no key was configured at all and
// secrets are stored as given.
EncryptionKeyEnv string `json:"encryption_key_env" yaml:"encryption_key_env"`
// FlagCacheTTL is the TTL for the flag evaluation cache.
// Defaults to 30 seconds.
FlagCacheTTL time.Duration `json:"flag_cache_ttl" yaml:"flag_cache_ttl"`
// SourcePollInterval is the interval for polling database sources.
// Defaults to 30 seconds.
SourcePollInterval time.Duration `json:"source_poll_interval" yaml:"source_poll_interval"`
}
Config holds the configuration for a Vault instance.
func DefaultConfig ¶
func DefaultConfig() Config
DefaultConfig returns a Config with sensible defaults.
type Entity ¶
Entity is the base type embedded by all Vault entities.
This is a type alias, not a defined type: callers embed vault.Entity and pass it where core.Entity is expected, and both must keep working.
type Option ¶
type Option func(*Vault)
Option configures a Vault instance.
func WithConfig ¶
WithConfig overlays the given Config onto the Vault's current configuration. A non-zero field in cfg overrides the current value; a zero-valued field leaves whatever an earlier option (or DefaultConfig) already set. It does not replace the whole Config wholesale, so it is safe to combine with WithAppID, WithEncryptionKey, and friends in any order without one silently erasing the other.
func WithEncryptionKey ¶
WithEncryptionKey sets the master encryption key (32 bytes for AES-256-GCM).
func WithEncryptionKeyEnv ¶
WithEncryptionKeyEnv sets the environment variable name for the encryption key.
func WithMetrics ¶
WithMetrics records vault's metrics on m: secret operations, encrypt and decrypt calls, flag evaluations, and rotation attempts with their duration. In a Forge app pass app.Metrics(); vault's Forge extension does this for you. A nil m, the default, records nothing. Spans need no option: vault starts them on the global tracer provider, which forge.New installs.
type Vault ¶
type Vault struct {
// contains filtered or unexported fields
}
Vault is the central type. It composes one store into the six subsystem services, wires the audit logger into secret mutations, and hands the whole thing out through accessors.
func New ¶
New creates a Vault from a store and options.
An absent encryption key is not an error: secrets fall back to being stored as given, which is the documented behaviour for development. A key that is present but cannot be decoded IS an error, because silently falling back there would store secrets in the clear while the caller believes they are encrypted. The same holds for a named key env var that is missing or empty: naming the variable is a statement of intent, so New refuses to start rather than writing plaintext the caller thinks is encrypted.
func (*Vault) AppID ¶
AppID returns the vault's configured application id. Every contract handler operates on this app and this app alone; no request carries an app id of its own.
func (*Vault) ConfigManager ¶
ConfigManager returns the config write service: the one path that creates, changes, rolls back and deletes config entries and their tenant overrides with validation, cache invalidation, watchers and audit.
func (*Vault) EncryptionAlgorithm ¶
EncryptionAlgorithm names the algorithm this vault encrypts new secrets with, the same string a stored secret carries in its EncryptionAlg, or "" when no key is configured. Like EncryptionEnabled it describes new writes only, not the rows already stored.
func (*Vault) EncryptionEnabled ¶
EncryptionEnabled reports whether secrets are encrypted at rest. False means a key was not configured and values are stored as given.
func (*Vault) FlagCacheTTL ¶
FlagCacheTTL returns how long the flag engine keeps an evaluation in its cache. A flag write invalidates it in this process at once; another replica serves the old value for up to this long.
func (*Vault) FlagEngine ¶
FlagEngine returns the underlying flag engine, which is what a caller needs for EvaluateDetail. Flags() covers the typed read path.
func (*Vault) FlagManager ¶
FlagManager returns the flag write service: the one path that creates, changes and deletes flags with validation, cache invalidation and audit.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package audit provides audit log entries and store interface.
|
Package audit provides audit log entries and store interface. |
|
Package audithook provides an audit event recording extension for Vault.
|
Package audithook provides an audit event recording extension for Vault. |
|
Package config provides runtime configuration entries and store interface.
|
Package config provides runtime configuration entries and store interface. |
|
Package configmgr is the write service for runtime config entries and their per-tenant overrides.
|
Package configmgr is the write service for runtime config entries and their per-tenant overrides. |
|
Package confy provides confy ConfigSource and SecretProvider adapters backed by vault's config and secret stores.
|
Package confy provides confy ConfigSource and SecretProvider adapters backed by vault's config and secret stores. |
|
Package core holds the types every Vault subsystem needs and that none of them may reach the root package for.
|
Package core holds the types every Vault subsystem needs and that none of them may reach the root package for. |
|
Package crypto provides AES-256-GCM encryption for Vault secrets.
|
Package crypto provides AES-256-GCM encryption for Vault secrets. |
|
Package extension provides the Forge extension adapter for Vault.
|
Package extension provides the Forge extension adapter for Vault. |
|
contract
Package contract wires Vault into the Forge dashboard's contract path.
|
Package contract wires Vault into the Forge dashboard's contract path. |
|
Package flag provides feature flag definitions, targeting rules, and evaluation.
|
Package flag provides feature flag definitions, targeting rules, and evaluation. |
|
Package id defines TypeID-based identity types for all Vault entities.
|
Package id defines TypeID-based identity types for all Vault entities. |
|
internal
|
|
|
storetest
Package storetest holds store conformance tests shared by every backend, so the memory, SQLite, Postgres and MongoDB stores are held to one behavior.
|
Package storetest holds store conformance tests shared by every backend, so the memory, SQLite, Postgres and MongoDB stores are held to one behavior. |
|
telemetry
Package telemetry is vault's tracing and metrics plumbing: the instrumentation scope on every vault span, a way to mark a span failed that never copies error text, and label vectors over a go-utils metrics sink.
|
Package telemetry is vault's tracing and metrics plumbing: the instrumentation scope on every vault span, a way to mark a span failed that never copies error text, and label vectors over a go-utils metrics sink. |
|
telemetrytest
Package telemetrytest records what vault's telemetry emits so tests can assert on it: spans through a tracetest.SpanRecorder installed as the global tracer provider, and metrics through a go-utils sink that remembers every series it handed out.
|
Package telemetrytest records what vault's telemetry emits so tests can assert on it: spans through a tracetest.SpanRecorder installed as the global tracer provider, and metrics through a go-utils sink that remembers every series it handed out. |
|
Package metrics provides interfaces and a collector for Vault operational metrics.
|
Package metrics provides interfaces and a collector for Vault operational metrics. |
|
Package override provides per-tenant config override entities and store interface.
|
Package override provides per-tenant config override entities and store interface. |
|
Package plugin provides the plugin system for extending Vault functionality.
|
Package plugin provides the plugin system for extending Vault functionality. |
|
Package rotation provides secret rotation policy entities and store interface.
|
Package rotation provides secret rotation policy entities and store interface. |
|
Package scope provides context-based request scoping for Vault operations.
|
Package scope provides context-based request scoping for Vault operations. |
|
Package secret provides the secret entity types and store interface.
|
Package secret provides the secret entity types and store interface. |
|
Package source provides a composable configuration source system.
|
Package source provides a composable configuration source system. |
|
Package store defines the composite store interface that all backends implement.
|
Package store defines the composite store interface that all backends implement. |
|
memory
Package memory provides a fully in-memory implementation of store.Store.
|
Package memory provides a fully in-memory implementation of store.Store. |
|
mongo
Package mongo provides a Grove ORM MongoDB implementation of all Vault store interfaces.
|
Package mongo provides a Grove ORM MongoDB implementation of all Vault store interfaces. |
|
postgres
Package postgres provides a Grove ORM implementation of all Vault store interfaces.
|
Package postgres provides a Grove ORM implementation of all Vault store interfaces. |
|
sqlite
Package sqlite provides a Grove ORM SQLite implementation of all Vault store interfaces.
|
Package sqlite provides a Grove ORM SQLite implementation of all Vault store interfaces. |