redact

package
v0.290.0 Latest Latest
Warning

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

Go to latest
Published: Nov 24, 2026 License: MIT Imports: 4 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 is THE ONE secret redactor: what looks like a credential in a line of text an agent or a page will be shown is replaced by Mark.

🔴 ONE COPY, EVERY CALLER. It was internal/mirrorhost's (the pending-action summary a waiting session sends, below) and moved here unchanged when the chief's sessions_overview began quoting session transcripts (internal/api's sessions_overview.go); the host also runs every field of a rendered view's transcript stream through it (internal/mirrorhost's redact_stream.go). A second redactor would drift from this one — the shapes it knows are a list that grows — so all of them call this.

Index

Constants

View Source
const Mark = "«redacted»"

Mark replaces each secret.

Variables

This section is empty.

Functions

func HasSecretLiteralIn added in v0.156.0

func HasSecretLiteralIn(path, s string) bool

HasSecretLiteralIn is HasSecretValueIn without the env pair rule: the value and key rules, each judging one line (or a block scalar's start). It is the test for lines that are NOT a whole text, such as a diff's added lines spliced together: there the lines between them are missing, so items cannot be told apart, and the pair rule must run on each hunk's post-image instead (HasSecretPairIn with changed).

func HasSecretPairIn added in v0.156.0

func HasSecretPairIn(path string, lines []string, changed []bool) bool

HasSecretPairIn reports whether lines (a manifest's lines, in order) hold one YAML mapping whose credential-like `name:` (credKey: `name: DB_PASSWORD`) has a sibling `value:` holding a literal: the shape of a Kubernetes env entry, which the key rule cannot see because the name and the literal sit on different lines. A mapping is

  • a block list item: its keys sit at the column after its `- `, and it ends at the next line left of or at its dash (the next `- ` item);
  • a block mapping nested under a key, or at the top of a document (a kustomize JSON6902 patch's `value:` holding `name:` and `value:`): its keys share one column, and it ends at a line left of it or at `---`;
  • a one-line flow mapping, anywhere on a line (`- {name: X, value: y}`, `value: {name: X, value: y}`, `env: [{name: X, value: y}]`), each one its own mapping.

A pair is never made across two mappings. `name:` and `value:` may come in either order. The literal rules are the key rule's (isLiteral), except that a QUOTED boolean or number is not a literal either (an env value must be a string: "true", "5432"); a quoted name or value may carry a comment after it. The pair is judged when either of its lines is marked in changed (nil: every line), so a diff's unchanged name line counts as context. A source file (sourceExts) is code: false.

Not seen (best effort): multi-line JSON, a dash alone on its line, a flow mapping that nests another, an alias whose anchor sits on another key.

func HasSecretValue added in v0.156.0

func HasSecretValue(s string) bool

HasSecretValue reports whether s holds a secret-shaped VALUE: THE secret-shape test for a refusal of an officer's SHIP content (its pull request diff, title, body and comments; internal/officership's draft gate).

It refuses on EITHER of two rules:

  • THE VALUE (Secrets, with one narrowing). Every shape Secrets knows by its VALUE (a token prefix, a PEM block, a JWT, a Stripe, age, Google, Hugging Face or Discord key, an AWS secret) refuses as it redacts. A shape Secrets knows only by a credential NAME (a header, "the password is …", a URL query parameter, and the key forms below) refuses on this rule when the value is itself secret-shaped (literalSecret). A URL's userinfo refuses when it holds a password that is not a reference.
  • 🔴 THE KEY (keyLiteral). A credential-like KEY (one ending in password, passwd, passphrase, pwd, secret, token, api_key/apikey, private_key, secret_key, secret_access_key, credential or credentials; not access_key_id, an identifier) holding a LITERAL refuses, whatever the literal looks like: `password: hunter2`, a diceware passphrase, a letters-only word, a block scalar. Not a literal: an empty or null value, a boolean, a number, a reference (${…}, $(…), $VAR, {{…}}, valueFrom, a flow mapping, an alias, a <placeholder>), a SOPS ENC[…] value, a path or a URL — and a key that itself NAMES a reference (existingSecret…, passwordSecret, tokenSecret, …SecretName, …SecretRef, …secretKeyRef). So `automountServiceAccountToken: false`, `existingSecret: x`, `passwordSecret: x` and `password: ${DB_PASSWORD}` pass.

func HasSecretValueIn added in v0.156.0

func HasSecretValueIn(path, s string) bool

HasSecretValueIn is HasSecretValue for content of the file at path. In a SOURCE file (sourceExts: Go, TypeScript, Python, …) an unquoted value is an expression (`Password: cfg.Password,`), so the key rule judges only a QUOTED string literal there; anywhere else (YAML, JSON, shell, .env, prose) every value is. s is a WHOLE text (a file, a title, a body): its lines are in order, so the env pair rule (HasSecretPairIn) runs on it too.

func Secrets

func Secrets(s string) string

Secrets is s with every value that looks like a secret replaced by «redacted» (see the comment above for the shapes).

Types

This section is empty.

Jump to

Keyboard shortcuts

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