Documentation
¶
Overview ¶
Package scanner implements CVE and malware scanners.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func New ¶
func New(cfg config.ScannerConfig) (gate.AVScanner, error)
New builds an AV scanner from its config. Unknown types are an error. The scanner reports cfg.DisplayName() as the engine of its verdicts.
func NewLimitedScanner ¶
NewLimitedScanner wraps inner so that at most limit scans run concurrently. A limit <= 0 disables limiting and returns inner unchanged.
Types ¶
type ClamAVScanner ¶
type ClamAVScanner struct {
// contains filtered or unexported fields
}
ClamAVScanner is a clamd client that scans files via the INSTREAM command. It implements gate.AVScanner.
func NewClamAVScanner ¶
func NewClamAVScanner(address string, timeout time.Duration) (*ClamAVScanner, error)
NewClamAVScanner creates a scanner for the given clamd address. address is "unix:///var/run/clamav/clamd.sock" or "tcp:host:3310".
type ICAPScanner ¶
type ICAPScanner struct {
// contains filtered or unexported fields
}
ICAPScanner scans files via the ICAP RESPMOD method. It works with any ICAP AV server (Kaspersky, Dr.Web, ClamAV behind c-icap). Implements gate.AVScanner.
func NewICAPScanner ¶
func NewICAPScanner(address, service string, timeout time.Duration) (*ICAPScanner, error)
NewICAPScanner creates a scanner for an ICAP server at address with the given service name. address is "unix:///path" or "tcp:host:port".
type LimitedOption ¶ added in v0.6.0
type LimitedOption func(*LimitedScanner)
LimitedOption customises a LimitedScanner.
func WithWaitObserver ¶ added in v0.6.0
func WithWaitObserver(f func(time.Duration)) LimitedOption
WithWaitObserver reports, once per Scan that acquires a slot, how long it waited in the queue. A nil f is a no-op and skips timing entirely.
type LimitedScanner ¶
type LimitedScanner struct {
// contains filtered or unexported fields
}
LimitedScanner caps the number of concurrent scans run against the wrapped engine. It exists to apply backpressure: clamd (and ICAP servers) have a bounded worker pool, so firing more concurrent INSTREAM/RESPMOD requests than the engine can serve makes responses queue past the per-scan deadline and surface as "i/o timeout". Bounding in-flight scans keeps each one fast enough to beat its deadline. It implements gate.AVScanner.
type MultiScanner ¶
type MultiScanner struct {
// contains filtered or unexported fields
}
MultiScanner runs several AV engines concurrently on the same file, so a scan takes as long as the slowest engine rather than the sum of all of them. It implements gate.AVScanner and fails closed: any engine reporting malware or failing blocks the artifact.
func NewMultiScanner ¶
func NewMultiScanner(scanners ...gate.AVScanner) *MultiScanner
NewMultiScanner wraps the given scanners. Their order decides which result is reported when several engines detect or fail on the same file.
func (*MultiScanner) Scan ¶
Scan runs every engine at once and waits for all of them, so no engine is still reading the file (or holding a concurrency slot) once Scan returns. A detection cancels the others' context. The verdict is the first detection in engine order; failing that, the first error; failing that, the first incomplete scan; else clean. A detection outranks an error because both block and the detection says why; an engine giving up on the file must never hide another engine's detection, so it ranks last.
type OSVOption ¶ added in v1.0.0
type OSVOption func(*OSVScanner)
OSVOption configures an OSVScanner.
func WithOSVHTTPClient ¶ added in v1.0.0
WithOSVHTTPClient sets the client OSV lookups use. The proxy passes one on its shared upstream transport, so lookups honour tls.ca_files (a TLS-inspecting corporate proxy would otherwise fail every lookup, and the CVE gate with it) and count against the per-host rate limits.
type OSVScanner ¶
type OSVScanner struct {
// contains filtered or unexported fields
}
OSVScanner queries api.osv.dev for known vulnerabilities. It implements gate.CVEScanner and caches results in memory.
func NewOSVScanner ¶
func NewOSVScanner(baseURL string, ttl time.Duration, opts ...OSVOption) *OSVScanner
NewOSVScanner creates an OSVScanner with the given base URL and cache TTL. baseURL should be "https://api.osv.dev" (or a mock server URL in tests). Without WithOSVHTTPClient it uses a private client with a 15 s timeout.
func (*OSVScanner) Close ¶
func (s *OSVScanner) Close() error
Close stops the janitor goroutine and waits for it to exit. Safe to call more than once.
func (*OSVScanner) Health ¶
func (s *OSVScanner) Health() health.Sample
Health reports the result of the last live query as a passive health sample. Before any live query runs, HasData is false (status unknown). Cache hits do not update it.
func (*OSVScanner) Scan ¶
func (s *OSVScanner) Scan(ctx context.Context, ref *gate.PackageRef) (*gate.ScanResult, error)
Scan implements gate.CVEScanner.