scan

package
v0.9.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 12, 2026 License: MIT Imports: 15 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 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

func NormalizeSeverity(s string) string

NormalizeSeverity maps scanner severity spellings ("Critical", "high") onto the normalized ladder.

func SeverityFromScore

func SeverityFromScore(score string) string

SeverityFromScore maps a CVSS score onto the normalized ladder, using the standard v3 bands.

func SeverityIn

func SeverityIn(severity string, list []string) bool

SeverityIn reports whether severity is in the (normalized) list.

Types

type ExecRunner

type ExecRunner struct{}

ExecRunner runs tools on the real PATH.

func (ExecRunner) Look

func (ExecRunner) Look(name string) bool

Look implements ToolRunner.

func (ExecRunner) Run

func (ExecRunner) Run(ctx context.Context, name string, args, env []string) ([]byte, error)

Run implements ToolRunner.

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 Suppress

func Suppress(findings []Finding, allow *spec.Allowlist) (kept, suppressed []Finding)

Suppress splits findings into kept and allowlisted, matching an entry's ID against each finding's ID and aliases — so an allowlist written against one scanner's ID family keeps working under another.

func (Finding) Fixed

func (f Finding) Fixed() bool

Fixed reports whether any fixed version is known.

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) Name

func (*Grype) Name() string

Name implements ImageScanner.

func (*Grype) ScanImage

func (g *Grype) ScanImage(ctx context.Context, ref string) ([]Finding, error)

ScanImage implements ImageScanner: grype -o json over the registry reference. The severity gate is the engine's, so grype never gates here — its JSON is the product.

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
	// contains filtered or unexported fields
}

OSV is the built-in library scanner: the image is exported to a local archive with the same registry client everything else uses, extracted by osv-scalibr, and matched against the OSV.dev API. No binary required.

func (*OSV) Name

func (*OSV) Name() string

Name implements ImageScanner.

func (*OSV) ScanImage

func (o *OSV) ScanImage(ctx context.Context, ref string) ([]Finding, error)

ScanImage implements ImageScanner.

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.

Jump to

Keyboard shortcuts

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