Documentation
¶
Overview ¶
Package scan finds vulnerabilities in images through pluggable scanners — osv-scanner and grype, both shell-outs — either by registry reference (ImageScanner: the mirror's locked images) or over a local docker archive (ArchiveScanner: a fresh build, scanned before anything is pushed). Kubescape optionally sweeps rendered manifests or a manifests tree 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. The scanners never apply policy; Blocking (severities, unfixed handling) and Suppress (the allowlist) are the separate steps both engines call.
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 ArchiveScanner ¶ added in v0.12.0
type ArchiveScanner interface {
// Name identifies the scanner in findings and narration.
Name() string
// ScanArchive scans the docker archive at path.
ScanArchive(ctx context.Context, path string) ([]Finding, error)
}
ArchiveScanner scans a local docker-archive tarball — an image that exists only on disk, like a fresh build no registry has seen yet.
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.
func Blocking ¶ added in v0.12.0
func Blocking(findings []Finding, policy spec.ScanPolicy) []Finding
Blocking applies a resolved policy's blocking rule: severity in failOn, and — under ignoreUnfixed — only findings a released fix exists for. Allowlist suppression (Suppress) is a separate, later step.
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.
func (*Grype) ScanArchive ¶ added in v0.12.0
ScanArchive implements ArchiveScanner: grype -o json over a local docker archive.
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.
func (*OSV) ScanArchive ¶ added in v0.12.0
ScanArchive implements ArchiveScanner: osv-scanner scan image --archive over a local docker archive (a mirror export or a freshly built image).
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.