Documentation
¶
Overview ¶
Package rules holds the built-in gk guard policy rule implementations. Each file in this package contributes exactly one Rule to policy.Default.
Index ¶
Constants ¶
This section is empty.
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 with the built-in patterns. The rules
// package cannot import the cli package that owns the diff scanner, so
// the caller injects it. Nil disables the built-in fallback.
ScanDiff func(diff 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
// contains filtered or unexported fields
}
SecretPatternsRule delegates secret scanning to the gitleaks binary when present. When the binary is missing it scans the diff with the built-in patterns instead and adds an informational Violation, so users see both the findings and why coverage is narrower in their environment.
Per the 2026-04-22 probe verdict, gk prefers the industry-standard gitleaks over maintaining a parallel scanner. The rule is intentionally thin — all detection logic lives in gitleaks; this adapter just maps GitleaksFindings to policy.Violations.
func NewSecretPatternsRule ¶
func NewSecretPatternsRule() *SecretPatternsRule
NewSecretPatternsRule returns a SecretPatternsRule with redaction enabled and git-history scan mode. Callers can tweak the exposed GitleaksOpts field after construction.
func (*SecretPatternsRule) Evaluate ¶
func (r *SecretPatternsRule) Evaluate(ctx context.Context, in policy.Input) ([]policy.Violation, error)
Evaluate runs gitleaks against the repo rooted at in.WorkDir. Each gitleaks Finding becomes a Violation with SeverityError. When gitleaks is absent, Evaluate falls back to the built-in patterns and emits one Info Violation explaining the narrower coverage.
func (*SecretPatternsRule) Name ¶
func (*SecretPatternsRule) Name() string
Name implements policy.Rule.