Documentation
¶
Overview ¶
Package harbor implements Harbor's pluggable scanner adapter API (spec v1.2, https://github.com/goharbor/pluggable-scanner-spec), so that Harbor scans every pushed image with meles. Harbor knows vulnerability and SBOM reports only: malware findings become vulnerabilities of severity Critical, so that Harbor's "prevent vulnerable images from running" blocks infected images at the registry. Optionally the adapter chains an upstream adapter such as Trivy's: a project keeps its CVE scan and gets the malware findings in the same report.
Index ¶
- func ValidSeverity(s string) bool
- type Adapter
- type Artifact
- type Capability
- type Config
- type ImageScanner
- type Metadata
- type Registry
- type ScanRequest
- type ScanResponse
- type Scanner
- type Upstream
- func (u *Upstream) Metadata(ctx context.Context) (Metadata, error)
- func (u *Upstream) Report(ctx context.Context, id, accept string, query url.Values) (*http.Response, error)
- func (u *Upstream) Scan(ctx context.Context, body []byte) (string, error)
- func (u *Upstream) WaitVulnerabilities(ctx context.Context, id string) (*VulnerabilityReport, error)
- type Vulnerability
- type VulnerabilityReport
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ValidSeverity ¶
ValidSeverity reports whether s is one of Harbor's severities.
Types ¶
type Adapter ¶
type Adapter struct {
// contains filtered or unexported fields
}
Adapter serves the scanner adapter API.
type Artifact ¶
type Artifact struct {
Repository string `json:"repository"`
Digest string `json:"digest"`
Tag string `json:"tag,omitempty"`
MimeType string `json:"mime_type,omitempty"`
}
Artifact is the image to scan.
type Capability ¶
type Capability struct {
Type string `json:"type,omitempty"`
ConsumesMimeTypes []string `json:"consumes_mime_types"`
ProducesMimeTypes []string `json:"produces_mime_types"`
AdditionalAttributes map[string]any `json:"additional_attributes,omitempty"`
}
Capability is what a scanner consumes and produces.
type Config ¶
type Config struct {
Scanner ImageScanner
// Version of meles, reported as the scanner version.
Version string
// Token, if set, is the bearer token Harbor must send (scanner
// registration: Authorization "Bearer").
Token string
// Rules are ignore rules; ignored entries are left out of the report.
Rules *ignore.Rules
// SkippedSeverity is the severity of files that were not scanned
// (default Critical: an unscanned file must not pass a gate).
SkippedSeverity string
// Upstream, if set, is chained: e.g. Trivy's adapter for CVEs.
Upstream *Upstream
// Workers is the number of images scanned in parallel.
Workers int
// ScanTimeout bounds a scan, including the upstream's.
ScanTimeout time.Duration
// KeepReports is how long reports are kept for Harbor to fetch.
KeepReports time.Duration
// HarborNamespace completes the short service names Harbor sends as its
// registry address ("http://harbor-core:80" with use_internal_addr), so
// that the adapter can run in another namespace.
HarborNamespace string
Logger *slog.Logger
}
Config configures an Adapter.
type ImageScanner ¶
type ImageScanner interface {
Scan(ctx context.Context, ref string, platforms source.PlatformFilter, progress func(scan.Progress), opts ...scan.Option) (*scan.Report, error)
}
ImageScanner scans one image; *scan.Scanner implements it.
type Metadata ¶
type Metadata struct {
Scanner Scanner `json:"scanner"`
Capabilities []Capability `json:"capabilities"`
Properties map[string]string `json:"properties,omitempty"`
}
Metadata is the answer to GET /api/v1/metadata.
type Registry ¶
type Registry struct {
URL string `json:"url"`
// Authorization is the value of an HTTP Authorization header for the
// registry, e.g. "Basic …" of a robot account.
Authorization string `json:"authorization"`
}
Registry is where Harbor stores the artifact, with credentials for it.
type ScanRequest ¶
type ScanRequest struct {
Registry Registry `json:"registry"`
Artifact Artifact `json:"artifact"`
EnabledCapabilities []map[string]any `json:"enabled_capabilities,omitempty"`
}
ScanRequest is the body of POST /api/v1/scan.
type ScanResponse ¶
type ScanResponse struct {
ID string `json:"id"`
}
ScanResponse is the answer to POST /api/v1/scan.
type Scanner ¶
type Scanner struct {
Name string `json:"name"`
Vendor string `json:"vendor"`
Version string `json:"version"`
}
Scanner identifies a scanner.
type Upstream ¶
type Upstream struct {
// URL of the adapter, e.g. http://harbor-trivy:8080.
URL string
// Authorization is sent as the Authorization header, e.g. "Bearer …".
Authorization string
Client *http.Client
}
Upstream is another scanner adapter, e.g. Trivy's, that the adapter chains: scan requests go to both, and the reports are merged.
func (*Upstream) Report ¶
func (u *Upstream) Report(ctx context.Context, id, accept string, query url.Values) (*http.Response, error)
Report fetches a report as is, for passing it through (e.g. an SBOM).
func (*Upstream) Scan ¶
Scan forwards Harbor's scan request unchanged and returns the upstream's scan request ID.
func (*Upstream) WaitVulnerabilities ¶
func (u *Upstream) WaitVulnerabilities(ctx context.Context, id string) (*VulnerabilityReport, error)
WaitVulnerabilities polls the upstream's vulnerability report until it is ready or ctx ends.
type Vulnerability ¶
type Vulnerability struct {
ID string `json:"id"`
Package string `json:"package"`
Version string `json:"version"`
FixVersion string `json:"fix_version,omitempty"`
Severity string `json:"severity"`
Description string `json:"description,omitempty"`
Links []string `json:"links,omitempty"`
PreferredCVSS map[string]any `json:"preferred_cvss,omitempty"`
CWEIDs []string `json:"cwe_ids,omitempty"`
VendorAttributes map[string]any `json:"vendor_attributes,omitempty"`
}
Vulnerability is one entry of a report: a CVE from an upstream scanner, or a malware finding or skipped file of meles.
type VulnerabilityReport ¶
type VulnerabilityReport struct {
GeneratedAt time.Time `json:"generated_at"`
Artifact Artifact `json:"artifact"`
Scanner Scanner `json:"scanner"`
Severity string `json:"severity"`
Vulnerabilities []Vulnerability `json:"vulnerabilities"`
}
VulnerabilityReport is Harbor's vulnerability report.