Documentation
¶
Overview ¶
Package secrets is the canonical client for go-fleet-secrets, the fleet vault. It centralizes the GET /secrets/<name> call plus the response-envelope decode so no consumer hand-rolls it.
Why this package exists: go-fleet-dns-sync hand-rolled the vault read and decoded the secret's "value" at the JSON top level, while the vault wraps payloads in the go-common response envelope ({"status":"success","data":{"value":...}}). The mismatch read an empty value, fell through to an unset env fallback, and silently disabled the DNS reconciler for 10 days (2026-05). Defining the read + decode once here means that contract can't drift per-consumer.
Transport note: the vault is reached over the public gateway FQDN (fleet-secrets.0exec.com) which, via split-horizon DNS, resolves to a private gateway IP from inside the docker mesh. That hop is legitimate but requires a safehttp client with SAFEHTTP_ALLOW_PRIVATE_IPS set (or a plain *http.Client for a docker-internal hostname). The caller owns that choice and passes the configured client in — this package does not build one.
Index ¶
- Variables
- func ApprovedVaultURL(raw string) bool
- func DirectTransport() *http.Transport
- type Client
- func (c *Client) Get(ctx context.Context, name string) (string, error)
- func (c *Client) GetDetailed(ctx context.Context, name string) (Result, error)
- func (c *Client) WithCache(dir string, maxAge time.Duration) *Client
- func (c *Client) WithEnv(getenv func(string) string) *Client
- func (c *Client) WithFallbacks(urls ...string) *Client
- type Doer
- type Result
- type Source
- type StatusError
Constants ¶
This section is empty.
Variables ¶
var ErrMissingAPIKey = errors.New("secrets: Fleet Secrets API key is not configured")
Functions ¶
func ApprovedVaultURL ¶
ApprovedVaultURL reports whether raw is an acceptable vault base URL: https, an approved fleet-secrets host, no credentials, path, query or non-443 port. The API key is sent to every URL in the list, so the list is an allowlist, not free text.
func DirectTransport ¶
DirectTransport returns an HTTP transport that never consults the HTTP_PROXY, HTTPS_PROXY or NO_PROXY environment variables.
Fleet-owned infrastructure (the vault itself and the approved OpenObserve hosts) must be reached directly. Services that run with proxy_egress set those variables to an external scraping proxy meant for third-party targets, and the fleet's strict service-scoped bundles deliberately remove the public mesh suffixes from NO_PROXY. A vault call that follows the environment is then tunnelled through that proxy: it reaches the gateway from the proxy's public address, which the vault vhost's source allowlist refuses (403), and the caller's vault API key would travel via a third party. The result was a one-shot credential load that failed on every start of such a service, silently leaving it without telemetry.
The transport is a clone of http.DefaultTransport with Proxy cleared, so dial and TLS handshake timeouts and HTTP/2 behaviour are unchanged. Each call returns a fresh transport; callers own its lifetime.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client reads secrets from go-fleet-secrets.
func New ¶
New builds a Client. baseURL is the vault root (e.g. "https://fleet-secrets.0exec.com"); a trailing slash is trimmed. apiKey is the caller's fleet API key — the gateway translates it into the X-Auth-User principal the vault checks against each secret's consumers allowlist. httpClient is the caller's configured transport (see the transport note on the package doc).
func NewFromEnv ¶
NewFromEnv builds a client for the fleet's approved HTTPS endpoint and resolves its caller key from protected runtime configuration. A custom Doer is accepted for tests; nil uses a short-timeout HTTP client that never follows redirects, so the API key cannot be forwarded to another host.
func (*Client) Get ¶
Get fetches a single secret's plaintext value by name, decoding the fleet response envelope's data.value. It never logs or embeds the secret value in any returned error.
With fallback URLs and/or a cache configured (WithFallbacks, WithCache, WithEnv) Get fails soft: an outage of the primary (transport error, 5xx, 429, an undecodable or empty answer) moves on to the next URL, and when every URL fails the last-known-good cached value is returned. A 401, 403 or 404 is a definitive answer, never retried elsewhere and never served from the cache. See GetDetailed to learn where the value came from.
Errors:
- misconfiguration (nil client/transport, empty base URL)
- transport failure
- non-200 status (a *StatusError; the status code is included, the body is not)
- envelope decode failure (via response.DecodeData; an error envelope surfaces as *response.Error)
- a 200 success envelope whose value is empty
func (*Client) GetDetailed ¶
GetDetailed is Get with provenance, so a caller can log "served from cache" without the value.
func (*Client) WithCache ¶
WithCache enables the encrypted last-known-good cache in dir. maxAge <= 0 means defaultCacheAge.
func (*Client) WithEnv ¶
WithEnv applies FLEET_SECRETS_FALLBACK_URLS / FLEET_SECRETS_CACHE_DIR / FLEET_SECRETS_CACHE_MAX_AGE. Unapproved fallback URLs are dropped silently (the key must not travel to them); with none of the variables set it is a no-op, so it is safe to call everywhere.
func (*Client) WithFallbacks ¶
WithFallbacks appends vault base URLs tried, in order, when the primary has an outage-type failure. It does no host validation (programmatic callers own that; see ApprovedVaultURL). Returns c for chaining.
type Doer ¶
Doer is the minimal HTTP surface this client needs. Both *http.Client and the safehttp client satisfy it.
type Result ¶
type Result struct {
Value string
Source Source
URL string // base URL that answered (empty for SourceCache)
Age time.Duration // for SourceCache: how old the cached copy is
}
Result is a secret value plus its provenance. Value is never logged by this package.
type StatusError ¶
StatusError is returned by Get when the vault answers with a status other than 200. It carries the numeric status and never the response body, so a caller can tell an outage a later attempt may outlast (5xx) from a configuration problem retrying cannot fix (401, 403, 404) with errors.As instead of parsing the message. The message is unchanged from earlier releases.
func (*StatusError) Error ¶
func (e *StatusError) Error() string