redact

package
v0.2.4 Latest Latest
Warning

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

Go to latest
Published: Oct 16, 2026 License: Apache-2.0 Imports: 11 Imported by: 0 modules, 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 redact removes credentials from Kubernetes objects and log text before anything is written to a Flightbay bundle. It records how many replacements were made and where, never the values themselves.

Index

Constants

View Source
const LastApplied = "kubectl.kubernetes.io/last-applied-configuration"

LastApplied is the annotation that can hold a full copy of an object.

View Source
const Placeholder = "[REDACTED]"

Placeholder is written in place of every redacted value.

Variables

View Source
var Rules = []struct{ Name, Description string }{
	{"private-key", "PEM private keys (certificates are kept for expiry and SAN checks)"},
	{"authorization", "Authorization: Bearer / Basic header values"},
	{"jwt", "JSON Web Tokens"},
	{"aws-access-key", "AWS access key IDs (AKIA..., ASIA...)"},
	{"api-key", "sk-... and sk-ant-... style API keys"},
	{"url-credentials", "user:password@ in URLs"},
	{"sensitive-key", "the value of any key or variable whose name contains password, passwd, secret, token, api_key or credential"},
}

Rules describes the built-in scrubbers, in the order they run. The customer document (flightbay docs collects) is generated from this list.

View Source
var (

	// SensitiveKey matches object keys and env var names whose values are credentials.
	SensitiveKey = regexp.MustCompile(`(?i)(password|passwd|secret|token|api[_\-]?key|credential)`)
)

Functions

This section is empty.

Types

type FieldRule

type FieldRule struct {
	Source string
	// contains filtered or unexported fields
}

FieldRule removes one path from every object, for example

metadata.annotations["corp.example/*"]
spec.template.spec.containers[*].env
data.license

Segments are separated by dots. A segment in ["..."] may contain dots and slashes (annotation and label keys). Both forms accept * and ? globs. [*] steps into every element of a list. The last segment names the key to remove.

func ParseFieldRule

func ParseFieldRule(src string) (FieldRule, error)

ParseFieldRule compiles one path.

type FieldRules

type FieldRules []FieldRule

FieldRules is a compiled list.

func ParseFieldRules

func ParseFieldRules(paths []string) (FieldRules, error)

ParseFieldRules compiles a list of paths.

func (FieldRules) Apply

func (rs FieldRules) Apply(obj map[string]any) map[string]int

Apply removes every matching field from obj in place and returns how many were removed per rule. A last-applied-configuration annotation is a full copy of the object, so the rules apply inside it too.

type LineRedactor

type LineRedactor struct {
	// contains filtered or unexported fields
}

LineRedactor scrubs a stream of log lines, including private keys that span lines.

func (*LineRedactor) Line

func (l *LineRedactor) Line(s string) string

Line scrubs one line.

type Redactor

type Redactor struct {
	// contains filtered or unexported fields
}

Redactor applies the built-in scrubbers plus customer-supplied patterns.

func New

func New(extra []string) (*Redactor, error)

New builds a Redactor. Extra patterns are Go regular expressions; any match is replaced.

func (*Redactor) DropFields

func (r *Redactor) DropFields(paths []string) error

DropFields makes the Redactor remove these paths from every object it scrubs. Removals are counted in the redaction report as drop-field-N.

func (*Redactor) Lines

func (r *Redactor) Lines(loc string) *LineRedactor

Lines returns a stateful redactor for one log stream.

func (*Redactor) Object

func (r *Redactor) Object(loc string, obj map[string]any) map[string]any

Object returns a scrubbed deep copy of an unstructured Kubernetes object.

func (*Redactor) Report

func (r *Redactor) Report() Report

Report returns counts per location and rule.

func (*Redactor) Secret

func (r *Redactor) Secret(loc string, obj map[string]any, mode SecretMode, helm bool) map[string]any

Secret reduces a Secret to metadata, optionally with key names and byte lengths. Values never survive. With helm set, Helm release Secrets become a chart summary.

func (*Redactor) String

func (r *Redactor) String(loc, s string) string

String scrubs free text (a log line, a ConfigMap value, an argument).

type Report

type Report struct {
	Total     int                       `json:"total"`
	Locations map[string]map[string]int `json:"locations"`
	Note      string                    `json:"note"`
}

Report is written to redaction-report.json.

type SecretMode

type SecretMode string

SecretMode controls how much of a Secret is captured. No mode captures values.

const (
	SecretMetadata SecretMode = "metadata" // name, type, labels, annotations
	SecretKeys     SecretMode = "keys"     // metadata plus key names and byte lengths
)

Jump to

Keyboard shortcuts

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