vault

package
v1.7.0 Latest Latest
Warning

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

Go to latest
Published: Feb 24, 2026 License: MIT Imports: 20 Imported by: 0

Documentation

Overview

Package vault implements a store.Plugin backed by HashiCorp Vault's KV v2 secrets engine. Each configuration value is stored as a separate Vault secret, enabling native value-level versioning, encryption at rest (via Vault's storage barrier), authentication, and access control through Vault ACL policies.

Storage layout (with default mount="secret", prefix="zhi"):

secret/data/zhi/{tree_id}/{path}      — value data
secret/metadata/zhi/{tree_id}/{path}  — value metadata and versions

For example, the config path "db/host" in tree "prod" maps to the Vault secret at path "zhi/prod/db/host" within the "secret" KV v2 engine.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	// Address is the Vault server address.
	// Defaults to the VAULT_ADDR environment variable, or "http://127.0.0.1:8200".
	Address string

	// Token is the initial Vault authentication token.
	// Defaults to the VAULT_TOKEN environment variable.
	Token string

	// Mount is the KV v2 secrets engine mount point.
	// Defaults to "secret".
	Mount string

	// Prefix is the key prefix within the mount for all zhi data.
	// Defaults to "zhi".
	Prefix string

	// Namespace is the Vault namespace (enterprise feature).
	// Defaults to the VAULT_NAMESPACE environment variable.
	Namespace string

	// CACert is the path to a PEM-encoded CA certificate for verifying
	// the Vault server's TLS certificate.
	// Defaults to the VAULT_CACERT environment variable.
	CACert string

	// ClientCert is the path to a PEM-encoded client certificate for
	// mutual TLS authentication with Vault.
	// Defaults to the VAULT_CLIENT_CERT environment variable.
	ClientCert string

	// ClientKey is the path to a PEM-encoded client private key for
	// mutual TLS authentication with Vault.
	// Defaults to the VAULT_CLIENT_KEY environment variable.
	ClientKey string

	// SkipVerify disables TLS certificate verification. This should
	// only be used for development and testing.
	// Defaults to the VAULT_SKIP_VERIFY environment variable.
	SkipVerify bool
}

Config holds Vault connection and storage settings.

func DefaultConfig

func DefaultConfig() Config

DefaultConfig returns a Config populated from environment variables with sensible defaults.

type Store

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

Store implements store.Plugin using Vault's KV v2 secrets engine.

func New

func New(cfg Config) (*Store, error)

New creates a new Vault store with the given configuration.

func (*Store) AuthMethods

func (s *Store) AuthMethods(_ context.Context) ([]store.AuthMethod, error)

func (*Store) Capabilities

func (s *Store) Capabilities(_ context.Context) (*store.Capabilities, error)

func (*Store) DeleteTree

func (s *Store) DeleteTree(ctx context.Context, id string) error

func (*Store) DeleteTreeVersion

func (s *Store) DeleteTreeVersion(_ context.Context, _ string, _ string) error

func (*Store) DeleteValueVersion

func (s *Store) DeleteValueVersion(ctx context.Context, id string, path string, version string) error

func (*Store) DeleteValues

func (s *Store) DeleteValues(ctx context.Context, id string, paths []string) error

func (*Store) GetTreeVersion

func (s *Store) GetTreeVersion(_ context.Context, _ string, _ string, _ []string) (map[string]config.Value, error)

func (*Store) GetValueVersion

func (s *Store) GetValueVersion(ctx context.Context, id string, path string, version string) (config.Value, bool, error)

func (*Store) GetValues

func (s *Store) GetValues(ctx context.Context, id string, paths []string) (map[string]config.Value, error)

func (*Store) GrantAccess

func (s *Store) GrantAccess(ctx context.Context, id string, user string, permissions []store.Permission) error

func (*Store) InitEncryption

func (s *Store) InitEncryption(_ context.Context, _ []byte) error

Vault handles encryption transparently via its storage barrier. InitEncryption is a no-op since encryption is always active.

func (*Store) ListAccess

func (s *Store) ListAccess(ctx context.Context, id string) (map[string][]store.Permission, error)

func (*Store) ListTreeVersions

func (s *Store) ListTreeVersions(_ context.Context, _ string) ([]string, error)

func (*Store) ListTrees

func (s *Store) ListTrees(ctx context.Context) ([]string, error)

func (*Store) ListValueVersions

func (s *Store) ListValueVersions(ctx context.Context, id string, path string) ([]string, error)

func (*Store) Login

func (s *Store) Login(ctx context.Context, method string, credentials map[string]string) (*store.Credential, error)

func (*Store) LoginInteractive added in v1.2.0

func (s *Store) LoginInteractive(ctx context.Context, method string, params map[string]string) (*store.InteractiveChallenge, error)

LoginInteractive starts an OIDC browser-based authentication flow. It contacts Vault's OIDC auth endpoint to obtain an authorization URL that the user must visit in their browser.

func (*Store) LoginInteractiveCallback added in v1.2.0

func (s *Store) LoginInteractiveCallback(ctx context.Context, _ string, callbackParams map[string]string) (*store.Credential, error)

LoginInteractiveCallback completes the OIDC authentication flow by exchanging the callback parameters (code, state) with Vault.

func (*Store) PutValues

func (s *Store) PutValues(ctx context.Context, id string, values map[string]config.Value, opts *store.PutOptions) error

func (*Store) RevokeAccess

func (s *Store) RevokeAccess(ctx context.Context, id string, user string, paths []string) error

func (*Store) RollbackTree

func (s *Store) RollbackTree(_ context.Context, _ string, _ string) error

func (*Store) RollbackValue

func (s *Store) RollbackValue(ctx context.Context, id string, path string, version string) error

func (*Store) RotateEncryption

func (s *Store) RotateEncryption(_ context.Context, _, _ []byte) error

RotateEncryption is a no-op since Vault manages its own barrier key rotation.

func (*Store) Stop

func (s *Store) Stop()

Stop cancels background token renewal. It is safe to call multiple times.

Directories

Path Synopsis
Package httpclient provides a thin HTTP client for the HashiCorp Vault API.
Package httpclient provides a thin HTTP client for the HashiCorp Vault API.

Jump to

Keyboard shortcuts

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