rules

package
v0.167.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: 19 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 rules holds the built-in gk guard policy rule implementations.

Index

Constants

View Source
const DefaultArchiveReaders = 2

DefaultArchiveReaders is how many cat-file processes read the archive blobs. Each one holds the blob it rebuilds. On histories of 132 to 202 jars where the archives took most of the time, two readers took 16-27% less time than one for up to 0.25 GB more memory, and four took 22-39% less for up to 0.6 GB more.

Variables

This section is empty.

Functions

This section is empty.

Types

type SecretPatternsRule

type SecretPatternsRule struct {
	// GitleaksOpts are forwarded to scan.RunGitleaks. WorkDir is filled
	// from Input.WorkDir so callers typically leave it empty.
	GitleaksOpts scan.GitleaksOptions

	// ScanDiff scans a unified diff and ScanFile one file's content with the
	// built-in patterns. The rules package cannot import the cli package that
	// owns the scanners, so the caller injects them. Either nil disables the
	// built-in scan.
	ScanDiff func(diff string) []secrets.Finding
	ScanFile func(path, content string) []secrets.Finding

	// ScannerLabel describes the injected scanner in the fallback notice. It
	// is a func so a lazily loaded ruleset is not compiled until a scan
	// actually falls back. Nil reports the built-in pattern count.
	ScannerLabel func() string

	// Verify checks the credentials the embedded engine attached to its
	// findings when Input.Verify is set, keyed by Credential.ID. The caller
	// injects it so this package makes no network calls. Nil skips
	// verification.
	Verify func(context.Context, []*secrets.Credential) map[string]policy.Verification
	// contains filtered or unexported fields
}

SecretPatternsRule scans with the gitleaks ruleset embedded in gk and adds an informational Violation naming the scanner. The embedded engine follows the gitleaks detection steps (it matched gitleaks 8.30.1 finding for finding on the gk history) and scans faster because large files are split across cores. The gitleaks binary runs instead only when the repo carries a gitleaks config (.gitleaks.toml, .gitleaksignore, or GITLEAKS_CONFIG*), because the embedded engine does not read those files.

func NewSecretPatternsRule

func NewSecretPatternsRule() *SecretPatternsRule

NewSecretPatternsRule returns a SecretPatternsRule with redaction enabled. The gitleaks mode follows the input scope; callers can add flags through GitleaksOpts.ExtraArgs after construction.

func (*SecretPatternsRule) Evaluate

func (r *SecretPatternsRule) Evaluate(ctx context.Context, in policy.Input) ([]policy.Violation, error)

Evaluate scans with the embedded ruleset unless the repo has a gitleaks config, in which case it runs gitleaks and maps each finding to a Violation with SeverityError. A missing gitleaks binary falls back to the embedded ruleset with a notice that the config was not read.

func (*SecretPatternsRule) Name

func (*SecretPatternsRule) Name() string

Name implements policy.Rule.

Jump to

Keyboard shortcuts

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