Documentation
¶
Overview ¶
Package gitleaks is an OPT-IN external-scanner adapter (iss-96), wired into every scanner the core builds as a scanner.Augmenter (augmenter.go, iss-2608291814575788). It is off by default and adds nothing — no dependency invoked, no process spawned, no cost — until a repo asks for it by dropping an enabled .abcd/config/gitleaks.json. This realises abcd's host-delegated boundary (AGENTS.md: "native/CLI/API/MCP oracles are opt-in adapters"): the always-on native scanner (internal/adapter/scanner) stays the default, and a repo that wants deeper coverage over unstructured prose arms this adapter, which shells out to a gitleaks binary and appends its findings to the native scanner's in every scan the scanner makes.
Reach and cost. The native pattern set is prefix-anchored and misses unanchored, labelled, high-entropy values in prose (iss-96's residue). gitleaks' generic-api-key rule reaches keyword+delimiter+entropy values that the native set does not. Its findings AUGMENT native redaction — they are masked by the same scanner.Redact discipline and counted in the record's audit counters — they never replace it.
Fail-closed, never a silent no-op. When a repo has opted in but the gitleaks binary is not found (not on PATH and no valid configured path), the adapter returns ErrConfiguredNotFound rather than quietly skipping the deeper scan: a repo that armed the adapter must not believe it is covered when it is not. The scanner carries it as a coverage gap (it matches scanner.ErrAugmenterNotFound): a release refuses on it, and a write path writes on the native scanner and names the gap in its receipt.
Binary admission (GHSA-fg9r-3f8g-89m6). The config that names the binary is COMMITTED content, so it is trusted for nothing: a candidate binary — a configured path or a PATH lookup result alike — runs only when it is an absolute path to a regular executable named gitleaks that lies outside the repository both lexically and after symlink resolution (admitBinary). A refusal is ErrConfiguredPathRefused, as loud as the not-found case and never a fallback to PATH, and it names the remedy: a repository rooted at $HOME (a dotfiles checkout) contains ~/.local/bin and ~/go/bin, so an install there is "inside the repository" and must move outside it, or the path must be unset.
Testability. The binary lookup and the process execution are both injected (Adapter.LookPath, Adapter.Runner), so the gate, the loud-stage and the augmentation path are all exercised with a fake — no real gitleaks binary is required to test this package.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrConfiguredNotFound error = notFoundError{}
ErrConfiguredNotFound is returned when the repo opted in but no gitleaks binary could be located. It is deliberately loud: the message names the opt-in so an operator sees "gitleaks configured but not found" rather than a silent skip.
It matches scanner.ErrAugmenterNotFound under errors.Is, so the scanner carries it as the one coverage-gap state without importing this package.
var ErrConfiguredPathRefused = errors.New("gitleaks configured path refused")
ErrConfiguredPathRefused is returned when a binary WAS located but fails the admission rule (admitBinary): it is relative, lies inside the repository, is reached through a symlink that does, is not a regular file, or is not executable. It is distinct from ErrConfiguredNotFound because the operator's remedy differs — the file exists; it is where it is that is the problem — and it is equally loud: it degrades the scanner, so every write path fails closed on it and a release refuses, and the adapter never falls back to PATH after refusing a configured path.
var ErrFindingNotLocated = errors.New("gitleaks finding not located in the text")
ErrFindingNotLocated is returned when gitleaks reported a finding whose Secret and Match both occur nowhere in the scanned text, so there is no span to redact. It is loud for the reason ErrConfiguredNotFound is: a repo that armed the adapter must not store a transcript the external scanner flagged while the record counts zero findings (GHSA-j7v5-q7x6-v3rp). It degrades the scanner, so the write fails closed; the remedy is the rule that reported the value, or enabled:false.
Functions ¶
func NewAugmenter ¶ added in v0.12.0
NewAugmenter is the production factory: the default adapter over the repository's own .abcd/config/gitleaks.json. It returns nil when the repository did not opt in, so a repository that did nothing pays nothing.
Types ¶
type Adapter ¶
type Adapter struct {
// LookPath resolves a bare binary name to a full path (defaults to
// exec.LookPath). It returns an error when the binary is absent.
LookPath func(string) (string, error)
// Runner executes the located binary over the text.
Runner Runner
}
Adapter augments native redaction with gitleaks findings. Construct it with NewDefault for the production wiring (real PATH lookup, real exec runner), or build one directly with a fake LookPath/Runner in tests.
func NewDefault ¶
func NewDefault() *Adapter
NewDefault returns the production adapter: tools.Resolve for discovery (abcd's own recorded copy, whatever comes first on PATH, else the PATH lookup: itd-2610240918594138) and a real gitleaks shell-out for execution. What it finds is still held to admitBinary.
func (*Adapter) Augment ¶
func (a *Adapter) Augment(ctx context.Context, repoRoot string, cfg Config, text, logical string) ([]scanner.Finding, error)
Augment scans text with gitleaks when cfg opts in, returning findings to fold into the native redaction. Behaviour by state:
- not opted in (cfg.Enabled false): returns (nil, nil), invokes NOTHING — no lookup, no process. This is the gate that keeps the default path free.
- opted in, binary absent: returns ErrConfiguredNotFound (loud-stage).
- opted in, binary present but inadmissible (admitBinary): returns ErrConfiguredPathRefused (loud-stage), with no fallback to PATH.
- opted in, binary present and admitted: runs it and converts its findings; a report it cannot place in the text is ErrFindingNotLocated (loud-stage), never a dropped finding.
func (*Adapter) AugmenterFor ¶ added in v0.12.0
AugmenterFor builds the augmenter for repoRoot from this adapter's lookup and runner. An absent config is nil (not opted in); a present but broken config is an augmenter that is never available, so the repository that tried to arm gitleaks and got it wrong is told rather than silently left on the native scanner. The binary is resolved once here, to answer Available, and again on every run, so what is executed is judged when it is executed.
type Augmenter ¶ added in v0.12.0
type Augmenter struct {
// contains filtered or unexported fields
}
Augmenter is the gitleaks adapter in the scanner's Augmenter shape, so every consumer that builds a scanner inherits the repository's opt-in rather than the transcript store alone (iss-2608291814575788). The scanner declares the interface and never imports this package; the composition root (cmd/abcd) registers NewAugmenter with scanner.SetDefaultAugmenter.
Available is the binary's state, or the last run's: a run that fails, a report that cannot be parsed, or a finding gitleaks placed nowhere in the text (ErrFindingNotLocated) is kept and returned from then on, which the scanner reads as a degrade. A binary the repository configured and nobody installed is ErrConfiguredNotFound, which matches scanner.ErrAugmenterNotFound and is carried as a coverage gap instead.
type Config ¶
type Config struct {
SchemaVersion int `json:"schema_version"`
Enabled bool `json:"enabled"`
Path string `json:"path,omitempty"` // optional explicit binary path
}
Config is the on-disk opt-in shape (.abcd/config/gitleaks.json). Absent file means not opted in (the default).
func LoadConfig ¶
LoadConfig reads the per-repo opt-in config with the same trust-boundary discipline the native scanner applies to pii.json: an os.Root-contained, size-capped, symlink-refusing read. An ABSENT config is the default-off case and returns a disabled Config with no error — the whole point of opt-in is that a repo which did nothing pays nothing. A PRESENT but unreadable or invalid config fails closed with an error, so a repo that tried to arm the adapter and got it wrong is told, not silently left unprotected.