Documentation
¶
Overview ¶
Package scanner provides pluggable vulnerability scanner execution.
Scanners execute external CLI tools to scan container images and produce JSON reports. Each scanner knows how to invoke its tool and which converter to use for parsing its output.
Available scanners:
- grype: Anchore Grype (if installed)
- trivy: Aqua Security Trivy (if installed)
- snyk: Snyk CLI (if installed and authenticated)
- osv: Google OSV-Scanner (if installed)
The Registry provides scanner discovery and lookup:
registry := scanner.DefaultRegistry()
available := registry.Available() // only installed scanners
for _, s := range available {
path, err := s.Scan(ctx, "docker.io/redis:latest")
// path contains JSON output file
}
To add a new scanner, implement the Scanner interface:
type Scanner interface {
Name() string
IsAvailable() bool
Scan(ctx context.Context, image string) (outputPath string, err error)
ConverterName() string
}
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GetAllScannerNames ¶ added in v0.7.0
func GetAllScannerNames() []string
GetAllScannerNames returns names of all registered scanners.
func GetAvailableScannerNames ¶ added in v0.7.0
func GetAvailableScannerNames() []string
GetAvailableScannerNames returns names of all available scanners.
func GetSampleScanners ¶
func GetSampleScanners() []string
GetSampleScanners returns list of supported scanners.
Types ¶
type GrypeScanner ¶ added in v0.7.0
type GrypeScanner struct{}
GrypeScanner implements the Scanner interface for Grype.
func NewGrypeScanner ¶ added in v0.7.0
func NewGrypeScanner() *GrypeScanner
NewGrypeScanner creates a new Grype scanner.
func (*GrypeScanner) ConverterName ¶ added in v0.7.0
func (g *GrypeScanner) ConverterName() string
ConverterName returns the converter name for grype output.
func (*GrypeScanner) IsAvailable ¶ added in v0.7.0
func (g *GrypeScanner) IsAvailable() bool
IsAvailable returns true if grype is installed.
func (*GrypeScanner) Name ¶ added in v0.7.0
func (g *GrypeScanner) Name() string
Name returns the scanner's identifier.
func (*GrypeScanner) ScanToPath ¶ added in v0.7.0
func (g *GrypeScanner) ScanToPath(ctx context.Context, image, outputPath string) error
ScanToPath runs grype and writes output to the specified path.
type OSVScanner ¶ added in v0.7.0
type OSVScanner struct {
// contains filtered or unexported fields
}
OSVScanner implements the Scanner interface for OSV-Scanner. Note: OSV-Scanner primarily scans lockfiles and SBOMs, not container images directly. Direct container image scanning support varies by osv-scanner version.
func NewOSVScanner ¶ added in v0.7.0
func NewOSVScanner() *OSVScanner
NewOSVScanner creates a new OSV scanner.
func (*OSVScanner) ConverterName ¶ added in v0.7.0
func (o *OSVScanner) ConverterName() string
ConverterName returns the converter name for osv output.
func (*OSVScanner) IsAvailable ¶ added in v0.7.0
func (o *OSVScanner) IsAvailable() bool
IsAvailable returns true if osv-scanner is installed and supports docker scanning.
func (*OSVScanner) Name ¶ added in v0.7.0
func (o *OSVScanner) Name() string
Name returns the scanner's identifier.
func (*OSVScanner) ScanToPath ¶ added in v0.7.0
func (o *OSVScanner) ScanToPath(ctx context.Context, image, outputPath string) error
ScanToPath runs osv-scanner and writes output to the specified path.
type Registry ¶ added in v0.7.0
type Registry struct {
// contains filtered or unexported fields
}
Registry manages registered scanners and provides lookup.
func DefaultRegistry ¶ added in v0.7.0
func DefaultRegistry() *Registry
DefaultRegistry returns a registry with all built-in scanners registered.
func NewRegistry ¶ added in v0.7.0
func NewRegistry() *Registry
NewRegistry creates a new scanner registry.
func (*Registry) Available ¶ added in v0.7.0
Available returns all scanners that are currently available (installed).
func (*Registry) AvailableNames ¶ added in v0.7.0
AvailableNames returns the names of all available scanners.
type Result ¶
type Result struct {
// Image to scan
Image string `json:"image"`
Files map[ScanType]string `json:"files"`
}
Result is the scan result.
type ScanResult ¶ added in v0.7.0
ScanResult is the result from ScanWithScanners using string keys.
func ScanWithScanners ¶ added in v0.7.0
func ScanWithScanners(ctx context.Context, image string, scannerNames []string) (*ScanResult, error)
ScanWithScanners runs specific scanners by name against the given image.
type Scanner ¶ added in v0.7.0
type Scanner interface {
// Name returns the scanner's identifier (e.g., "grype", "trivy").
Name() string
// IsAvailable returns true if the scanner is installed and available.
IsAvailable() bool
// Scan runs the scanner against the given image and returns the output file path.
Scan(ctx context.Context, image string) (outputPath string, err error)
// ScanToPath runs the scanner and writes output to the specified path.
ScanToPath(ctx context.Context, image, outputPath string) error
// ConverterName returns the name of the converter to use for this scanner's output.
ConverterName() string
}
Scanner defines the interface for vulnerability scanners.
func GetAvailableScanners ¶ added in v0.7.0
func GetAvailableScanners() []Scanner
GetAvailableScanners returns all available scanners from the default registry.
func GetScanner ¶ added in v0.7.0
GetScanner returns a scanner by name from the default registry.
type SnykScanner ¶ added in v0.7.0
type SnykScanner struct{}
SnykScanner implements the Scanner interface for Snyk.
func NewSnykScanner ¶ added in v0.7.0
func NewSnykScanner() *SnykScanner
NewSnykScanner creates a new Snyk scanner.
func (*SnykScanner) ConverterName ¶ added in v0.7.0
func (s *SnykScanner) ConverterName() string
ConverterName returns the converter name for snyk output.
func (*SnykScanner) IsAvailable ¶ added in v0.7.0
func (s *SnykScanner) IsAvailable() bool
IsAvailable returns true if snyk is installed.
func (*SnykScanner) Name ¶ added in v0.7.0
func (s *SnykScanner) Name() string
Name returns the scanner's identifier.
func (*SnykScanner) ScanToPath ¶ added in v0.7.0
func (s *SnykScanner) ScanToPath(ctx context.Context, image, outputPath string) error
ScanToPath runs snyk and writes output to the specified path.
type TrivyScanner ¶ added in v0.7.0
type TrivyScanner struct{}
TrivyScanner implements the Scanner interface for Trivy.
func NewTrivyScanner ¶ added in v0.7.0
func NewTrivyScanner() *TrivyScanner
NewTrivyScanner creates a new Trivy scanner.
func (*TrivyScanner) ConverterName ¶ added in v0.7.0
func (t *TrivyScanner) ConverterName() string
ConverterName returns the converter name for trivy output.
func (*TrivyScanner) IsAvailable ¶ added in v0.7.0
func (t *TrivyScanner) IsAvailable() bool
IsAvailable returns true if trivy is installed.
func (*TrivyScanner) Name ¶ added in v0.7.0
func (t *TrivyScanner) Name() string
Name returns the scanner's identifier.
func (*TrivyScanner) ScanToPath ¶ added in v0.7.0
func (t *TrivyScanner) ScanToPath(ctx context.Context, image, outputPath string) error
ScanToPath runs trivy and writes output to the specified path.