Documentation
¶
Overview ¶
Package redact provides the process-wide canonical secret redactor.
Index ¶
- Constants
- func Args(args []string) []string
- func ClaimTokens(value string) string
- func ClaimTokensJSON(raw json.RawMessage) json.RawMessage
- func ContainsRawClaimToken(value string) bool
- func ContainsRegisteredSecret(value string) bool
- func CrossScopeJSON(raw json.RawMessage) json.RawMessage
- func CrossScopeString(value string) string
- func Enabled() bool
- func ExactBinaryJSON(raw json.RawMessage) (json.RawMessage, error)
- func ExactBinaryString(value string) string
- func ExactBytes(value []byte) []byte
- func ExactJSON(raw json.RawMessage) (json.RawMessage, error)
- func ExactString(value string) string
- func IsSensitiveKey(key string) bool
- func RegisterDynamicSecret(value string) func()
- func RegisterRequiredSecret(value string) func()
- func SecretFingerprint() [sha256.Size]byte
- func SnapshotEnabled(enabled bool)
- func String(value string) string
- func WithCurrentSecretSnapshot(check func(*SecretSnapshot))
- type Engine
- func (e *Engine) RedactJSON(raw json.RawMessage, fields []string) json.RawMessage
- func (e *Engine) RedactJSONEverywhere(raw json.RawMessage) json.RawMessage
- func (e *Engine) RedactJSONWithProtectedStrings(raw json.RawMessage, fields []string, ...) json.RawMessage
- func (e *Engine) RedactJSONWithProtection(raw json.RawMessage, fields []string, ...) json.RawMessage
- func (e *Engine) RedactLogAttrs(attrs []slog.Attr) []slog.Attr
- func (e *Engine) RedactString(value string) string
- type Options
- type SecretSnapshot
- func (s *SecretSnapshot) ExactBinaryJSON(raw json.RawMessage) (json.RawMessage, error)
- func (s *SecretSnapshot) ExactBinaryString(value string) string
- func (s *SecretSnapshot) MaterialFingerprint() [sha256.Size]byte
- func (s *SecretSnapshot) NeedsBinaryJSONRedaction(raw json.RawMessage) (bool, error)
Constants ¶
const Marker = "[REDACTED]"
Marker is the canonical replacement for secret material in public text.
Variables ¶
This section is empty.
Functions ¶
func Args ¶
Args redacts argument values while preserving sensitive flag context and argument boundaries.
func ClaimTokens ¶
ClaimTokens removes raw task-claim bearer tokens without applying other redaction rules.
func ClaimTokensJSON ¶
func ClaimTokensJSON(raw json.RawMessage) json.RawMessage
ClaimTokensJSON removes raw claim-token fields and values from a JSON payload. Invalid input is materialized as a JSON string so wire callers never emit malformed JSON.
func ContainsRawClaimToken ¶
ContainsRawClaimToken reports whether value contains a concrete task-claim bearer token.
func ContainsRegisteredSecret ¶
ContainsRegisteredSecret reports whether value contains runtime-registered secret material.
func CrossScopeJSON ¶
func CrossScopeJSON(raw json.RawMessage) json.RawMessage
CrossScopeJSON redacts every string of a JSON document read across a workspace or profile boundary. Structural identifiers (`*_id`, hashes, cursors) stay readable; sensitive field names are blanked wholesale.
func CrossScopeString ¶
CrossScopeString redacts free text read across a workspace or profile boundary.
func Enabled ¶
func Enabled() bool
Enabled reports the process-snapshotted additive heuristic setting.
func ExactBinaryJSON ¶
func ExactBinaryJSON(raw json.RawMessage) (json.RawMessage, error)
ExactBinaryJSON removes literal secrets and whole JSON strings whose decoded bytes contain a registered secret.
func ExactBinaryString ¶
ExactBinaryString removes literal and reversibly encoded registered secrets from text.
func ExactBytes ¶
ExactBytes removes registered secrets from an opaque byte payload.
func ExactJSON ¶
func ExactJSON(raw json.RawMessage) (json.RawMessage, error)
ExactJSON removes canonical and registered secrets from JSON keys and string values.
func ExactString ¶
ExactString removes canonical and registered secrets without additive heuristics.
func IsSensitiveKey ¶
IsSensitiveKey reports whether a field name belongs to the shared secret taxonomy.
func RegisterDynamicSecret ¶
func RegisterDynamicSecret(value string) func()
RegisterDynamicSecret registers heuristic runtime material and returns an idempotent cleanup.
func RegisterRequiredSecret ¶
func RegisterRequiredSecret(value string) func()
RegisterRequiredSecret registers nonblank caller-classified secret material and returns an idempotent cleanup.
func SecretFingerprint ¶
SecretFingerprint identifies the current continuous registrations without exposing their values.
func SnapshotEnabled ¶
func SnapshotEnabled(enabled bool)
SnapshotEnabled freezes the process-wide additive heuristic setting. Later calls cannot change it; configuration changes therefore require a restart.
func WithCurrentSecretSnapshot ¶
func WithCurrentSecretSnapshot(check func(*SecretSnapshot))
WithCurrentSecretSnapshot checks against an immutable snapshot and repeats under the registry lock only if registrations changed during the first check. The callback must replace its results on each call and must not register or release secrets.
Types ¶
type Engine ¶
type Engine struct {
// contains filtered or unexported fields
}
Engine applies exact protections and optional conservative heuristics.
func (*Engine) RedactJSON ¶
func (e *Engine) RedactJSON(raw json.RawMessage, fields []string) json.RawMessage
RedactJSON applies exact protection throughout a JSON document and additive heuristics only within the named free-text fields.
func (*Engine) RedactJSONEverywhere ¶
func (e *Engine) RedactJSONEverywhere(raw json.RawMessage) json.RawMessage
RedactJSONEverywhere applies exact protection and the additive heuristics to every string in a JSON document, keeping only structural identifier fields.
func (*Engine) RedactJSONWithProtectedStrings ¶
func (e *Engine) RedactJSONWithProtectedStrings( raw json.RawMessage, fields []string, protect func(path []string, value string) bool, ) json.RawMessage
RedactJSONWithProtectedStrings applies RedactJSON while preserving scalar strings that the caller identifies as public structural handles. The predicate is evaluated only after key-based secret protection, so a sensitive field name can never opt out of redaction. Paths contain object keys; array elements inherit the enclosing field's path.
func (*Engine) RedactJSONWithProtection ¶
func (e *Engine) RedactJSONWithProtection( raw json.RawMessage, fields []string, protectString func(path []string, value string) bool, protectObject func(path []string, value any) bool, ) json.RawMessage
RedactJSONWithProtection extends RedactJSONWithProtectedStrings with a structural predicate. It is consulted only for a sensitive field name, with that field's path; an accepted value is traversed normally instead of being replaced wholesale, so its strings still get exact secret redaction.
func (*Engine) RedactLogAttrs ¶
RedactLogAttrs applies field-aware redaction while preserving correlation, numeric, boolean, duration, time, and other structured envelope values.
func (*Engine) RedactString ¶
RedactString removes secret material from free text.
type Options ¶
type Options struct {
// Disabled turns off additive provider-prefix and entropy heuristics. Exact
// claim, assignment, reference, and registered-secret protection remains active.
Disabled bool
}
Options configures one independent redaction engine.
type SecretSnapshot ¶
type SecretSnapshot struct {
// contains filtered or unexported fields
}
SecretSnapshot pairs the registered secrets with their reversible encodings, derived once per change because redaction reads them for every string.
func RegisteredSecretSnapshot ¶
func RegisteredSecretSnapshot() *SecretSnapshot
RegisteredSecretSnapshot captures one immutable set of registered secrets for redaction.
func (*SecretSnapshot) ExactBinaryJSON ¶
func (s *SecretSnapshot) ExactBinaryJSON(raw json.RawMessage) (json.RawMessage, error)
ExactBinaryJSON redacts keys and string values against this fixed secret set.
func (*SecretSnapshot) ExactBinaryString ¶
func (s *SecretSnapshot) ExactBinaryString(value string) string
ExactBinaryString redacts text against this fixed secret set.
func (*SecretSnapshot) MaterialFingerprint ¶
func (s *SecretSnapshot) MaterialFingerprint() [sha256.Size]byte
MaterialFingerprint identifies the same redaction inputs across repeated registrations. The fingerprint is for in-process cache keys and must never be exposed or logged.
func (*SecretSnapshot) NeedsBinaryJSONRedaction ¶
func (s *SecretSnapshot) NeedsBinaryJSONRedaction(raw json.RawMessage) (bool, error)
NeedsBinaryJSONRedaction reports whether any JSON string requires redaction under this snapshot.