Documentation
¶
Overview ¶
Package extension provides the Forge extension adapter for Vault.
It implements the forge.Extension interface to integrate Vault into a Forge application with automatic dependency discovery, route registration, and lifecycle management.
Configuration can be provided programmatically via Option functions or via YAML configuration files under "extensions.vault" or "vault" keys.
Index ¶
- Constants
- type Config
- type Extension
- func (e *Extension) Health(ctx context.Context) error
- func (e *Extension) Register(fapp forge.App) error
- func (e *Extension) RegisterContractContributor(disp *dispatcher.Dispatcher, reg dashcontract.Registry, ...) error
- func (e *Extension) Start(_ context.Context) error
- func (e *Extension) Stop(ctx context.Context) error
- func (e *Extension) Store() store.Store
- func (e *Extension) Vault() *vault.Vault
- type Option
- func WithAppID(appID string) Option
- func WithBasePath(path string) Option
- func WithConfig(cfg Config) Option
- func WithConfyKeyPrefix(prefix string) Option
- func WithConfyMountKeys(keys ...string) Option
- func WithConfyMountPatterns(patterns ...string) Option
- func WithDisableMigrate() Option
- func WithDisableRoutes() Option
- func WithEnableAudit(enable bool) Optiondeprecated
- func WithEncryptionKeyEnv(envVar string) Option
- func WithGroveDatabase(name string) Option
- func WithMountToConfy() Option
- func WithRequireConfig(require bool) Option
- func WithStore(s store.Store) Option
- func WithVaultOption(opt vault.Option) Option
Constants ¶
const ExtensionDescription = "Composable secrets management, feature flags, and runtime configuration"
ExtensionDescription is the human-readable description.
const ExtensionName = "vault"
ExtensionName is the name registered with Forge.
const ExtensionVersion = "0.1.0"
ExtensionVersion is the semantic version.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct {
// DisableRoutes prevents HTTP route registration.
DisableRoutes bool `json:"disable_routes" mapstructure:"disable_routes" yaml:"disable_routes"`
// DisableMigrate prevents auto-migration on start.
DisableMigrate bool `json:"disable_migrate" mapstructure:"disable_migrate" yaml:"disable_migrate"`
// BasePath is the URL prefix for vault routes (default: "/vault").
BasePath string `json:"base_path" mapstructure:"base_path" yaml:"base_path"`
// AppID is the application identifier used for scoping secrets, flags, and config.
AppID string `json:"app_id" mapstructure:"app_id" yaml:"app_id"`
// EncryptionKeyEnv is the environment variable name for the encryption key.
// Used to load the master encryption key at startup.
EncryptionKeyEnv string `json:"encryption_key_env" mapstructure:"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" mapstructure:"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" mapstructure:"source_poll_interval" yaml:"source_poll_interval"`
// Deprecated: audit logging is always on and this setting has no effect.
EnableAudit bool `json:"enable_audit" mapstructure:"enable_audit" yaml:"enable_audit"`
// GroveDatabase is the name of a grove.DB registered in the DI container.
// When set, the extension resolves this named database and auto-constructs
// the appropriate store based on the driver type (pg/sqlite/mongo).
// When empty and WithGroveDatabase was called, the default (unnamed) DB is used.
GroveDatabase string `json:"grove_database" mapstructure:"grove_database" yaml:"grove_database"`
// MountToConfy registers vault as a confy ConfigSource and SecretProvider
// so vault-managed config and secrets are accessible via the forge ConfigManager.
MountToConfy bool `json:"mount_to_confy" mapstructure:"mount_to_confy" yaml:"mount_to_confy"`
// ConfyKeyPrefix is prepended to all vault keys when exposed through confy.
// For example, "vault." causes vault key "db.host" to appear as "vault.db.host".
ConfyKeyPrefix string `json:"confy_key_prefix" mapstructure:"confy_key_prefix" yaml:"confy_key_prefix"`
// ConfyMountKeys restricts which vault keys are mounted into confy.
// Only the listed keys will be included; all others are filtered out.
// When empty, all keys are included (unless ConfyMountPatterns is set).
ConfyMountKeys []string `json:"confy_mount_keys" mapstructure:"confy_mount_keys" yaml:"confy_mount_keys"`
// ConfyMountPatterns restricts which vault keys are mounted into confy
// using glob patterns (e.g. "db.*", "auth.*"). Multiple patterns are OR-ed.
// When empty, all keys are included (unless ConfyMountKeys is set).
ConfyMountPatterns []string `json:"confy_mount_patterns" mapstructure:"confy_mount_patterns" yaml:"confy_mount_patterns"`
// RequireConfig requires config to be present in YAML files.
// If true and no config is found, Register returns an error.
RequireConfig bool `json:"-" yaml:"-"`
}
Config holds the Vault extension configuration. Fields can be set programmatically via Option functions or loaded from YAML configuration files (under "extensions.vault" or "vault" keys).
func DefaultConfig ¶
func DefaultConfig() Config
DefaultConfig returns a Config with sensible defaults.
type Extension ¶
type Extension struct {
*forge.BaseExtension
// contains filtered or unexported fields
}
Extension adapts Vault as a Forge extension.
func (*Extension) Health ¶
Health implements forge.Extension.
func (*Extension) Register ¶
Register implements forge.Extension. It loads configuration, initializes the vault, and registers it in the DI container.
func (*Extension) RegisterContractContributor ¶
func (e *Extension) RegisterContractContributor( disp *dispatcher.Dispatcher, reg dashcontract.Registry, wreg dashcontract.WardenRegistry, ) error
RegisterContractContributor implements dashboard.ContractContributorAware. It registers the vault contract contributor, which is what the React shell reads.
func (*Extension) Start ¶
Start implements forge.Extension. It starts the rotation manager's background loop, without which a policy with an enabled, due rotation and a registered rotator never rotates on schedule. The loop is started with context.Background() rather than the context Start receives, which may be cancelled or time out well before the extension itself stops.
It also starts the version-encryption backfill in the background, so Start does not wait on a large table. The backfill only records what the configured key proves, so running it on every start is safe and a second run marks nothing.
func (*Extension) Stop ¶
Stop implements forge.Extension. The rotation loop is stopped before the store is closed, so no in-flight rotation check can run against a closed store.
type Option ¶
type Option func(*Extension)
Option configures the Vault Forge extension.
func WithBasePath ¶
WithBasePath sets the URL prefix for vault routes.
func WithConfig ¶
WithConfig sets the Forge extension configuration.
func WithConfyKeyPrefix ¶
WithConfyKeyPrefix sets a prefix prepended to all vault keys in confy. For example, "vault." causes vault key "db.host" to appear as "vault.db.host".
func WithConfyMountKeys ¶
WithConfyMountKeys restricts which vault keys are mounted into confy. Only the listed keys will be included; all others are filtered out.
func WithConfyMountPatterns ¶
WithConfyMountPatterns restricts which vault keys are mounted into confy using glob patterns (e.g. "db.*", "auth.*"). Multiple patterns are OR-ed.
func WithDisableMigrate ¶
func WithDisableMigrate() Option
WithDisableMigrate prevents auto-migration on start.
func WithDisableRoutes ¶
func WithDisableRoutes() Option
WithDisableRoutes prevents HTTP route registration.
func WithEnableAudit
deprecated
func WithEncryptionKeyEnv ¶
WithEncryptionKeyEnv sets the environment variable name for the encryption key.
func WithGroveDatabase ¶
WithGroveDatabase sets the name of the grove.DB to resolve from the DI container. The extension will auto-construct the appropriate store backend (postgres/sqlite/mongo) based on the grove driver type. Pass an empty string to use the default (unnamed) grove.DB.
func WithMountToConfy ¶
func WithMountToConfy() Option
WithMountToConfy enables mounting vault config and secrets into the forge ConfigManager via confy's ConfigSource and SecretProvider interfaces.
func WithRequireConfig ¶
WithRequireConfig requires config to be present in YAML files. If true and no config is found, Register returns an error.
func WithVaultOption ¶
WithVaultOption passes a vault option through to the underlying Vault instance.