secrets

package
v0.111.5 Latest Latest
Warning

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

Go to latest
Published: Oct 29, 2026 License: Apache-2.0 Imports: 16 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

Constants

This section is empty.

Variables

View Source
var ErrMissingAPIKey = errors.New("secrets: Fleet Secrets API key is not configured")

Functions

func ApprovedVaultURL

func ApprovedVaultURL(raw string) bool

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

func DirectTransport() *http.Transport

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

func New(baseURL, apiKey string, httpClient Doer) *Client

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

func NewFromEnv(getenv func(string) string, httpClient Doer) (*Client, error)

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

func (c *Client) Get(ctx context.Context, name string) (string, error)

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

func (c *Client) GetDetailed(ctx context.Context, name string) (Result, error)

GetDetailed is Get with provenance, so a caller can log "served from cache" without the value.

func (*Client) WithCache

func (c *Client) WithCache(dir string, maxAge time.Duration) *Client

WithCache enables the encrypted last-known-good cache in dir. maxAge <= 0 means defaultCacheAge.

func (*Client) WithEnv

func (c *Client) WithEnv(getenv func(string) string) *Client

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

func (c *Client) WithFallbacks(urls ...string) *Client

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

type Doer interface {
	Do(*http.Request) (*http.Response, error)
}

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 Source

type Source string

Source says where a returned secret came from.

const (
	SourceLive  Source = "live"  // answered by the first (primary) URL
	SourceAlt   Source = "alt"   // answered by a fallback URL
	SourceCache Source = "cache" // every URL failed; last-known-good from disk
)

type StatusError

type StatusError struct {
	Name       string
	StatusCode int
}

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

Jump to

Keyboard shortcuts

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