vault

package
v1.5.9 Latest Latest
Warning

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

Go to latest
Published: Nov 22, 2026 License: Apache-2.0 Imports: 25 Imported by: 0

Documentation

Overview

Package vault resolves a live secret value from an external HashiCorp Vault instance at container-create time, as an alternative to internal/secrets' own envelope-encrypted storage. It is a sibling package, not a change to internal/secrets: a Vault-sourced value is never persisted here or anywhere else. It may be held in memory for a short runtime-setting TTL, the same discipline internal/secrets uses.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrBlockedAddress  = errors.New("vault address is link-local, metadata or private; for a Vault on a private or loopback address turn on the vault.allow_private_address setting")
	ErrRedirectBlocked = errors.New("vault redirected to another host or scheme")
)

Errors returned when the configured address fails the connection guard.

View Source
var ErrNoAWSCredentials = errors.New("vault: aws secrets engine returned no credentials")

ErrNoAWSCredentials marks a creds read that returned no usable key pair.

View Source
var ErrNoAWSRole = errors.New("vault: aws role not found")

ErrNoAWSRole marks an aws secrets engine role that does not exist at Vault.

View Source
var ErrPathDenied = errors.New("vault: policy does not allow reading the path")

ErrPathDenied marks a path the credential's policy does not allow reading.

View Source
var ErrSecretMissing = errors.New("vault: secret not found")

ErrSecretMissing marks a secret, field or version that does not exist, so callers can tell it from an outage.

Functions

func AddressRule

func AddressRule(host string) string

AddressRule reports the always-blocked rule a literal host hits, "" when the host passes. Names are only checked against metadata hosts: the dial-time guard still covers whatever a name resolves to.

func ResolveWithGrace

func ResolveWithGrace(now, previousExpiresAt time.Time, current, previous string, attempt Attempt) (string, error)

ResolveWithGrace tries the current credential first. The previous credential is tried only while previousExpiresAt is set and still in the future, so a rotation grace of 0 (no previous kept, zero expiry) never falls back.

func TunablesFrom

func TunablesFrom(s *runtimesettings.Service) func(context.Context) Tunables

TunablesFrom reads the bounds from runtime settings; a nil service serves env then defaults.

Types

type AWSBroker

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

AWSBroker reads aws/creds/<role>, keeps each lease until a share of its TTL has passed, replaces it lazily on the next use and revokes it when the account goes away.

func NewAWSBroker

func NewAWSBroker(tunables func(context.Context) Tunables) *AWSBroker

NewAWSBroker returns a broker reading its client bounds from tunables on every call.

func (*AWSBroker) Credentials

func (b *AWSBroker) Credentials(ctx context.Context, s AWSSpec, token string) (AWSCredentials, error)

Credentials returns live credentials for the spec, reading a new lease only when none is cached or the cached one has passed its renewal point. token is the Vault token resolved from the secret source.

func (*AWSBroker) Probe

func (b *AWSBroker) Probe(ctx context.Context, s AWSSpec, token string) error

Probe checks, with the given token, that Vault answers and the aws secrets engine role exists. The caller gets a class of failure, never Vault's own text.

func (*AWSBroker) Revoke

func (b *AWSBroker) Revoke(ctx context.Context, account, token string) error

Revoke ends every cached lease of the account and drops them from memory. A failed revoke is reported, the cache is cleared either way.

type AWSCredentials

type AWSCredentials struct {
	AccessKeyID     string
	SecretAccessKey string
	SessionToken    string
}

AWSCredentials is a short lived key set. It is held in memory only and never logged.

type AWSLogin

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

AWSLogin caches Vault tokens obtained through auth/aws/login so a lease read does not log in every time.

func NewAWSLogin

func NewAWSLogin(tunables func(context.Context) Tunables) *AWSLogin

NewAWSLogin returns a login helper reading its client bounds from tunables on every call.

func (*AWSLogin) Token

func (l *AWSLogin) Token(ctx context.Context, spec AWSLoginSpec, keys func(context.Context) (AWSCredentials, error)) (string, error)

Token returns a live Vault token for the spec, logging in only when none is cached or it is past its renewal point. keys is called only when a login is needed.

type AWSLoginSpec

type AWSLoginSpec struct {
	Address   string
	Namespace string
	Mount     string
	Role      string
	ServerID  string
	// STSURL overrides the signed endpoint, for tests only.
	STSURL string
}

AWSLoginSpec names the Vault aws auth mount and role Levelrail logs in to with its own AWS identity.

type AWSSpec

type AWSSpec struct {
	Account   string
	Address   string
	Namespace string
	Mount     string
	Role      string
}

AWSSpec names one Vault aws secrets engine role for one account. Mount defaults to aws.

type Attempt

type Attempt func(credential string) (string, error)

Attempt authenticates with one credential and reads the secret, returning the value.

type Resolver

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

Resolver reads secrets from a HashiCorp Vault or OpenBao KV v2 engine. It keeps an AppRole login token and a short read cache in memory only.

func NewResolver

func NewResolver() *Resolver

NewResolver returns a Resolver reading its bounds from runtime defaults and env.

func NewResolverWith

func NewResolverWith(tunables func(context.Context) Tunables) *Resolver

NewResolverWith returns a Resolver reading its bounds from tunables on every resolve.

func (*Resolver) Flush

func (r *Resolver) Flush()

Flush drops every cached token and value, for a connection change or rotation.

func (*Resolver) Probe

func (r *Resolver) Probe(ctx context.Context, cfg store.VaultSettings, credential string) error

Probe checks that the address is reachable and the credential authenticates, by looking up the caller's own token. It reads no secret and returns no data.

func (*Resolver) ProbePath

func (r *Resolver) ProbePath(ctx context.Context, cfg store.VaultSettings, credential, path string) error

ProbePath is Probe plus a read-only check of one KV v2 path: the policy's capabilities on it, then its metadata. It never reads secret data.

func (*Resolver) Resolve

func (r *Resolver) Resolve(ctx context.Context, cfg store.VaultSettings, credential, path, key string) (string, error)

Resolve authenticates against cfg's Vault instance using credential (a Vault token when cfg.AuthMethod is store.VaultAuthMethodToken, an AppRole secret ID when it's store.VaultAuthMethodAppRole), reads the KV v2 secret at path under cfg.MountPath, and returns the string value stored at key inside it. Never logs credential, path contents, or the returned value. A login failure fails the read; nothing stale is served.

func (*Resolver) SessionToken

func (r *Resolver) SessionToken(ctx context.Context, cfg store.VaultSettings, credential string) (string, error)

SessionToken returns the Vault token for cfg: the credential for token auth or a cached AppRole login.

type Tunables

type Tunables struct {
	Timeout      time.Duration
	CacheTTL     time.Duration
	AllowPrivate bool
	RenewPercent int
}

Tunables are the live Vault client bounds, read per resolve so a settings change applies at once.

Jump to

Keyboard shortcuts

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