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 ¶
- Variables
- func AddressRule(host string) string
- func ResolveWithGrace(now, previousExpiresAt time.Time, current, previous string, attempt Attempt) (string, error)
- func TunablesFrom(s *runtimesettings.Service) func(context.Context) Tunables
- type AWSBroker
- type AWSCredentials
- type AWSLogin
- type AWSLoginSpec
- type AWSSpec
- type Attempt
- type Resolver
- func (r *Resolver) Flush()
- func (r *Resolver) Probe(ctx context.Context, cfg store.VaultSettings, credential string) error
- func (r *Resolver) ProbePath(ctx context.Context, cfg store.VaultSettings, credential, path string) error
- func (r *Resolver) Resolve(ctx context.Context, cfg store.VaultSettings, credential, path, key string) (string, error)
- func (r *Resolver) SessionToken(ctx context.Context, cfg store.VaultSettings, credential string) (string, error)
- type Tunables
Constants ¶
This section is empty.
Variables ¶
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.
var ErrNoAWSCredentials = errors.New("vault: aws secrets engine returned no credentials")
ErrNoAWSCredentials marks a creds read that returned no usable key pair.
var ErrNoAWSRole = errors.New("vault: aws role not found")
ErrNoAWSRole marks an aws secrets engine role that does not exist at Vault.
var ErrPathDenied = errors.New("vault: policy does not allow reading the path")
ErrPathDenied marks a path the credential's policy does not allow reading.
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 ¶
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 ¶
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.
type AWSCredentials ¶
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 ¶
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 ¶
AWSSpec names one Vault aws secrets engine role for one account. Mount defaults to aws.
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 ¶
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 ¶
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.