Documentation
¶
Overview ¶
Package scan finds vulnerabilities in locked images through pluggable scanners: the built-in osv scanner (a library — extraction plus the OSV.dev API, no binary needed) and grype (a shell-out, for stores that want its database as a second opinion). Kubescape optionally sweeps the rendered manifests for configuration findings, warn-only by default.
Findings normalize to one shape regardless of scanner: an ID with its aliases (CVE/GHSA families cross-reference each other, so an allowlist entry written against one scanner's ID keeps working under another), a severity normalized to CRITICAL/HIGH/MEDIUM/LOW, and the package, installed and fixed-in versions the allowlist derivation needs. Policy — blocking severities, unfixed handling, allowlist suppression — is the engine's business, not the scanners'.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NormalizeSeverity ¶
NormalizeSeverity maps scanner severity spellings ("Critical", "high") onto the normalized ladder.
func SeverityFromScore ¶
SeverityFromScore maps a CVSS score onto the normalized ladder, using the standard v3 bands.
func SeverityIn ¶
SeverityIn reports whether severity is in the (normalized) list.
Types ¶
type Finding ¶
type Finding struct {
// ID is the scanner's primary identifier (CVE, GHSA, GO-...).
ID string `json:"id"`
// Aliases are equivalent identifiers from other ID families.
Aliases []string `json:"aliases,omitempty"`
// Severity is normalized: CRITICAL, HIGH, MEDIUM, LOW, NEGLIGIBLE or
// UNKNOWN.
Severity string `json:"severity"`
// Package is the affected artifact.
Package string `json:"package"`
// Installed is the version the image ships.
Installed string `json:"installed"`
// FixedIn lists released versions carrying the fix.
FixedIn []string `json:"fixedIn,omitempty"`
// Scanner names the reporter (osv, grype).
Scanner string `json:"scanner"`
}
Finding is one vulnerability in one image, scanner-neutral.
type Grype ¶
type Grype struct {
// Runner executes the binary (nil: the real PATH).
Runner ToolRunner
}
Grype shells out to grype, for stores that want its vulnerability database alongside (or instead of) the built-in scanner. The binary must be on PATH when the scanner is enabled.
type ImageScanner ¶
type ImageScanner interface {
// Name identifies the scanner in findings and narration.
Name() string
// ScanImage scans ref (registry reference, usually digest-pinned).
ScanImage(ctx context.Context, ref string) ([]Finding, error)
}
ImageScanner scans one image reference for vulnerabilities.
type KubescapeResult ¶
type KubescapeResult struct {
// Skipped is set (with the reason) when the scan could not run —
// the binary being absent is a warning, not a failure.
Skipped string
// Failed reports a non-zero scan under fail mode.
Failed bool
// Output is the scan's stdout, for narration.
Output []byte
}
KubescapeResult is one configuration scan's outcome.
func Kubescape ¶
func Kubescape(ctx context.Context, runner ToolRunner, renderedPath, mode string) (*KubescapeResult, error)
Kubescape sweeps rendered manifests for configuration findings (RBAC breadth, security contexts). Those are usually inherent to what an upstream operator chart must do, so warn is the default mode; fail blocks on them.
type OSV ¶
type OSV struct {
// Registry pulls the image (nil: ambient keychain).
Registry *ocireg.Client
// Runner executes the binary (nil: the real PATH).
Runner ToolRunner
}
OSV shells out to osv-scanner: the image is exported to a local archive with the same registry client everything else uses, then scanned by the binary (which must be on PATH when the scanner is enabled) against the OSV.dev API.
type ToolRunner ¶
type ToolRunner interface {
// Run executes name with args and extra environment, returning
// stdout. A non-zero exit with useful stdout (grype gating) is NOT
// an error here; runners return stdout and the exit error together.
Run(ctx context.Context, name string, args, env []string) (stdout []byte, err error)
// Look reports whether the binary is available.
Look(name string) bool
}
ToolRunner executes external scanner binaries; a seam so tests can can their output.