openbao

package module
v0.1.13 Latest Latest
Warning

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

Go to latest
Published: May 12, 2026 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Overview

Package openbao provides a secrets.Provider that resolves secret references from an OpenBao KV v2 secret engine.

The provider uses a thin HTTP client (no SDK dependency) and supports HTTPS-only connections with SSRF protection, custom CA certificates, and mTLS client authentication.

Usage

provider, err := openbao.New(&openbao.Config{
    Address: os.Getenv("BAO_ADDR"),
    Token:   os.Getenv("BAO_TOKEN"),
})
if err != nil {
    return err
}
defer provider.Close()

val, err := provider.Resolve(ctx, ref)

Pass the provider to outputconfig.Load via outputconfig.WithSecretProvider to resolve ref+ URIs in YAML configuration files automatically.

KV v2 Path Convention

Secret references use the raw API path, not the CLI logical path. The CLI command "bao kv get secret/audit/hmac" maps to the API path "secret/data/audit/hmac". Ref URIs use the API path:

ref+openbao://secret/data/audit/hmac#salt

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 OpenBao server URL. Required. Must use HTTPS.
	// Typically sourced from the BAO_ADDR environment variable.
	Address string

	// Token is the authentication token. Required.
	// Typically sourced from the BAO_TOKEN environment variable.
	Token string

	// Namespace is the OpenBao namespace prefix. Optional.
	// Set via X-Vault-Namespace header on every request.
	Namespace string

	// TLSCA is the path to a custom CA certificate PEM file for
	// verifying the OpenBao server's TLS certificate.
	TLSCA string

	// TLSCert is the path to a client certificate for mTLS
	// authentication.
	TLSCert string

	// TLSKey is the path to the client private key for mTLS
	// authentication.
	TLSKey string

	// TLSPolicy controls TLS version and cipher suite selection.
	// Nil defaults to TLS 1.3 only.
	TLSPolicy *audit.TLSPolicy

	// AllowPrivateRanges permits connections to RFC 1918 private
	// addresses and loopback. Required for local development where
	// OpenBao runs on 127.0.0.1. Cloud metadata endpoints remain
	// blocked. Default: false.
	AllowPrivateRanges bool

	// AllowInsecureHTTP permits http:// URLs. Default: false.
	// MUST NOT be set to true in production. Plaintext HTTP exposes
	// the authentication token to network observers. Use only for
	// local development with Docker Compose where OpenBao runs
	// on the internal Docker network.
	AllowInsecureHTTP bool
}

Config holds connection parameters for an OpenBao provider.

func (Config) Format added in v0.1.11

func (c Config) Format(f fmt.State, _ rune)

Format writes the redacted representation to the formatter. Prevents credential leakage via %+v and all other format verbs.

func (Config) GoString added in v0.1.11

func (c Config) GoString() string

GoString returns the same redacted representation as Config.String. Prevents credential leakage when a Config is formatted via %#v.

func (Config) String added in v0.1.11

func (c Config) String() string

String returns a credential-free representation of the config, suitable for debug logging via %v or %+v. Token is never printed; Address path/query/fragment are stripped; presence of TLS client cert and namespace is surfaced without the values (#475).

type Provider

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

Provider resolves secret references from an OpenBao KV v2 engine. Construction validates the address and builds an SSRF-safe HTTP client but performs no network I/O. The first [Resolve] call initiates the connection.

func New

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

New creates an OpenBao provider from the given configuration. Validates the address (HTTPS required unless [Config.AllowInsecureHTTP] is set), builds the TLS config and HTTP client, but performs no network I/O.

Error messages do not echo caller-supplied substrings (the configured address, scheme, or token); the audit/secrets/openbao logger category surfaces the failure class without leakage. Set log-level debug on that category if a deployment-time root cause is needed (#651).

func NewWithHTTPClient

func NewWithHTTPClient(cfg *Config, client *http.Client) (*Provider, error)

NewWithHTTPClient creates an OpenBao provider using the provided HTTP client instead of building one from the Config's TLS settings. This is primarily for testing with net/http/httptest servers. The Config.Address and Config.Token are still validated.

func (*Provider) Close

func (p *Provider) Close() error

Close releases resources held by the provider and zeroes the authentication token from memory (best-effort; Go GC may retain copies).

Close is idempotent: repeated calls are safe, return nil, and do not panic. Token zeroing on an already-zero slice is a no-op, and http.Client.CloseIdleConnections is safe to invoke multiple times per the stdlib contract. Calls to Provider.Resolve after Close will fail with a connection error.

func (*Provider) Format

func (p *Provider) Format(f fmt.State, _ rune)

Format implements fmt.Formatter to prevent token leakage via %+v.

func (*Provider) GoString

func (p *Provider) GoString() string

GoString implements fmt.GoStringer to prevent token leakage via %#v.

func (*Provider) Resolve

func (p *Provider) Resolve(ctx context.Context, ref secrets.Ref) (string, error)

Resolve fetches a single secret value for the given reference.

func (*Provider) ResolvePath

func (p *Provider) ResolvePath(ctx context.Context, path string) (map[string]string, error)

ResolvePath fetches all key-value pairs at the given path from the OpenBao KV v2 engine. Implements secrets.BatchProvider for path-level caching.

func (*Provider) Scheme

func (p *Provider) Scheme() string

Scheme returns "openbao".

func (*Provider) String

func (p *Provider) String() string

String returns a safe representation with the token redacted.

Jump to

Keyboard shortcuts

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