Documentation
¶
Overview ¶
Package redactorgo is the fleet's one allowlist secret-scrubber — so no log line, diagnostic bundle, env dump, or JSON receipt ever leaks a known secret value. A Redactor is built once from a set of registered secret keys (key names whose values are sensitive, e.g. "PASSWORD", "token") and registered secret values (literal strings to mask wherever they appear), then reused to scrub env-var slices, raw byte streams, and JSON documents into a placeholder-substituted copy.
The model is allowlist-by-key + denylist-by-value, the two complementary halves every diagnostic scrubber needs:
- Secret keys catch structurally-known secrets: a "PASSWORD" env var, a "token" JSON field — the value is redacted regardless of its content.
- Secret values catch leaked-known secrets: a concrete credential that shows up embedded in an arbitrary string, URL, or log message.
Pure stdlib + errors-go; safe for concurrent use after construction (the Redactor is immutable once New returns).
Index ¶
Constants ¶
const DefaultMask = "[REDACTED]"
DefaultMask is the placeholder substituted for a redacted value when no WithMask option overrides it.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Option ¶
type Option func(*Redactor)
Option configures a Redactor during New. Options are applied in order, so a later option of the same kind overrides an earlier one.
func WithCaseSensitiveKeys ¶
func WithCaseSensitiveKeys() Option
WithCaseSensitiveKeys makes secret-key matching case-sensitive. By default keys match case-insensitively ("PASSWORD" == "password"), which is the right posture for env-var and JSON-field name matching.
func WithMask ¶
WithMask overrides the redaction placeholder (default DefaultMask). An empty mask is ignored so a Redactor never silently produces blank output.
func WithSecretKeys ¶
WithSecretKeys registers key names whose associated values are secret. A key match scrubs the value in env-var pairs ("KEY=value") and in JSON object fields, regardless of the value's content. Matching is case-insensitive by default (see WithCaseSensitiveKeys).
func WithSecretValues ¶
WithSecretValues registers literal secret strings to mask wherever they appear in any scrubbed text, including inside larger strings (URLs, log lines, JSON string values). Empty values are ignored.
type Redactor ¶
type Redactor struct {
// contains filtered or unexported fields
}
Redactor is an immutable, options-built secret scrubber. Construct it with New; after construction it holds no mutable state and is safe for concurrent use across goroutines.
func New ¶
New builds a Redactor from the given options. At least one secret key or secret value must be registered, otherwise the Redactor would be a no-op and the caller almost certainly forgot to register its secrets — that returns a typed, code-carrying error ("redactor_empty") rather than a silent pass.
func (*Redactor) Bytes ¶
Bytes scrubs a raw byte stream (e.g. a log buffer or file contents), masking every registered secret value. It does not interpret structure; for structured documents prefer [JSON]. Returns a freshly-allocated slice; the input is never mutated.
func (*Redactor) Env ¶
Env scrubs a slice of "KEY=VALUE" environment entries (the os.Environ() shape). For each entry whose KEY is a registered secret key, the VALUE is replaced with the mask; for every entry, registered secret values appearing in the VALUE are also masked. KEY names and the "=" separator are preserved. Returns a new slice; the input is never mutated.
func (*Redactor) EnvMap ¶
EnvMap is the convenience form of [Env] for a map[string]string. The returned map is freshly allocated; the input is never mutated.
func (*Redactor) JSON ¶
JSON scrubs a JSON document: it walks the decoded value, masking the value of any object field whose name is a registered secret key (the whole subtree under a secret key is replaced with the mask), and masking any registered secret value found inside any string leaf. It returns canonical re-encoded JSON. A document that is not valid JSON yields a typed, code-carrying error ("redactor_json"); callers with non-JSON input should use [Bytes] instead.