Documentation
¶
Overview ¶
Package store keeps configured scans, scan runs and their findings, and the history of the cluster's MalwareReports in SQLite (pure Go driver, no CGO).
Index ¶
- Constants
- Variables
- type ClusterDay
- type ClusterEvent
- type ClusterKey
- type ClusterReportKey
- type Day
- type FindingRow
- type Run
- type RunFilter
- type Scan
- type SignatureCount
- type Stats
- type Store
- func (s *Store) Close() error
- func (s *Store) ClusterDaily(ctx context.Context, cluster string, days int, loc *time.Location) ([]ClusterDay, error)
- func (s *Store) ClusterHistory(ctx context.Context, cluster, namespace, group string, limit int) ([]ClusterEvent, error)
- func (s *Store) ClusterStatusSince(ctx context.Context, cluster string) (map[ClusterKey]time.Time, error)
- func (s *Store) CountRuns(ctx context.Context, f RunFilter) (int, error)
- func (s *Store) CreateRun(ctx context.Context, r *Run) error
- func (s *Store) CreateScan(ctx context.Context, sc *Scan) error
- func (s *Store) Daily(ctx context.Context, days int, loc *time.Location) ([]Day, error)
- func (s *Store) DeleteScan(ctx context.Context, id int64) error
- func (s *Store) FailUnfinished(ctx context.Context) (int64, error)
- func (s *Store) Findings(ctx context.Context, since time.Time) ([]FindingRow, error)
- func (s *Store) FinishRun(ctx context.Context, id int64, rep *scan.Report, runErr error) error
- func (s *Store) GetReport(ctx context.Context, id int64) (*scan.Report, error)
- func (s *Store) GetRun(ctx context.Context, id int64) (*Run, error)
- func (s *Store) GetScan(ctx context.Context, id int64) (*Scan, error)
- func (s *Store) HasActiveRun(ctx context.Context, scanID int64) (bool, error)
- func (s *Store) ImageStatus(ctx context.Context) ([]Run, error)
- func (s *Store) ListRuns(ctx context.Context, f RunFilter) ([]Run, error)
- func (s *Store) ListScans(ctx context.Context) ([]Scan, error)
- func (s *Store) LiveClusterReports(ctx context.Context, cluster string) (map[ClusterReportKey]ClusterEvent, error)
- func (s *Store) Ping(ctx context.Context) error
- func (s *Store) PruneClusterEvents(ctx context.Context, before time.Time) (int64, error)
- func (s *Store) RecordClusterEvent(ctx context.Context, e *ClusterEvent) (bool, error)
- func (s *Store) SetProgress(ctx context.Context, id int64, progress string) error
- func (s *Store) StartRun(ctx context.Context, id int64) error
- func (s *Store) Stats(ctx context.Context, since time.Time) (Stats, error)
- func (s *Store) TopSignatures(ctx context.Context, since time.Time, limit int) ([]SignatureCount, error)
- func (s *Store) UpdateScan(ctx context.Context, sc *Scan) error
Constants ¶
const ( StatusQueued = "queued" StatusRunning = "running" StatusClean = "clean" StatusInfected = "infected" StatusError = "error" )
Run statuses. Only clean means the image was fully scanned without findings.
const ( TriggerManual = "manual" TriggerSchedule = "schedule" TriggerAPI = "api" )
Run triggers.
const MaxDays = 366
MaxDays bounds the days of Daily and ClusterDaily: each day is one entry allocated up front.
Variables ¶
var ErrNotFound = errors.New("not found")
ErrNotFound is returned when a scan or run does not exist.
Functions ¶
This section is empty.
Types ¶
type ClusterDay ¶
type ClusterDay struct {
Date time.Time `json:"date"`
Clean int `json:"clean"`
Infected int `json:"infected"`
Incomplete int `json:"incomplete"`
Errors int `json:"errors"`
}
ClusterDay counts the cluster's reports by status at the end of a day (for today: now).
func (ClusterDay) Total ¶
func (d ClusterDay) Total() int
Total returns the number of reports of the day.
type ClusterEvent ¶
type ClusterEvent struct {
ID int64 `json:"id"`
// Cluster is the name of the cluster (empty for a single cluster).
Cluster string `json:"cluster,omitempty"`
Namespace string `json:"namespace"`
Report string `json:"report"`
// Group identifies the workload and container across rollouts:
// "Deployment/web/app" for the ReplicaSets of a Deployment, otherwise
// "<kind>/<name>/<container>".
Group string `json:"group"`
WorkloadKind string `json:"workloadKind"`
WorkloadName string `json:"workloadName"`
Container string `json:"container"`
Repository string `json:"repository"`
Reference string `json:"reference,omitempty"`
Digest string `json:"digest"`
// Status of the report (Clean, Infected, Incomplete, Error); empty for a
// deletion.
Status string `json:"status,omitempty"`
Deleted bool `json:"deleted,omitempty"`
Findings int `json:"findings"`
Skipped int `json:"skipped"`
Files int `json:"files"`
Engine string `json:"engine,omitempty"`
Signatures string `json:"signatures,omitempty"`
Error string `json:"error,omitempty"`
ScannedAt time.Time `json:"scannedAt"`
RecordedAt time.Time `json:"recordedAt"`
// StatusSince is when the group got its current status.
StatusSince time.Time `json:"statusSince"`
}
ClusterEvent is a change of a MalwareReport of the meles operator: a new scan result, or the deletion of the report.
type ClusterKey ¶
type ClusterKey struct{ Namespace, Group string }
ClusterKey identifies a workload group in a namespace.
type ClusterReportKey ¶
type ClusterReportKey struct{ Namespace, Report string }
ClusterReportKey identifies a report.
type FindingRow ¶
type FindingRow struct {
RunID int64
FinishedAt time.Time
ImageRef string
Digest string
Platform string
Layer int
Path string
Signature string
Status string
}
FindingRow is a finding with its run, for exports.
type Run ¶
type Run struct {
ID int64 `json:"id"`
ScanID *int64 `json:"scanId,omitempty"`
ScanName string `json:"scanName,omitempty"`
ImageRef string `json:"imageRef"`
Platforms string `json:"platforms"`
Trigger string `json:"trigger"`
Status string `json:"status"`
QueuedAt time.Time `json:"queuedAt"`
StartedAt *time.Time `json:"startedAt,omitempty"`
FinishedAt *time.Time `json:"finishedAt,omitempty"`
Digest string `json:"digest,omitempty"`
Engine string `json:"engine,omitempty"`
Signatures string `json:"signatures,omitempty"`
Files int `json:"files"`
// Findings and Skipped count what is not ignored by a rule.
Findings int `json:"findings"`
Skipped int `json:"skipped"`
Progress string `json:"progress,omitempty"`
Error string `json:"error,omitempty"`
}
Run is one execution of a scan or an ad-hoc scan.
type RunFilter ¶
type RunFilter struct {
ScanID int64
Status string
ImageRef string
Since time.Time
Limit int
Offset int
}
RunFilter selects runs. Zero values mean no restriction.
type Scan ¶
type Scan struct {
ID int64 `json:"id"`
Name string `json:"name"`
ImageRef string `json:"imageRef"`
Platforms string `json:"platforms"`
// Schedule is a cron expression; empty means manual runs only.
Schedule string `json:"schedule"`
Enabled bool `json:"enabled"`
CreatedAt time.Time `json:"createdAt"`
UpdatedAt time.Time `json:"updatedAt"`
// LastRun is the most recent run, if any (not stored with the scan).
LastRun *Run `json:"lastRun,omitempty"`
}
Scan is a configured scan of an image reference.
type SignatureCount ¶
SignatureCount aggregates findings of one signature.
type Stats ¶
type Stats struct {
Scans int
ScheduledScans int
Runs int
Clean int
Infected int
Errors int
// InfectedImages counts images whose latest finished run found malware.
InfectedImages int
// Images counts distinct image references with a finished run.
Images int
}
Stats summarises the database for the dashboard.
type Store ¶
type Store struct {
// contains filtered or unexported fields
}
Store is a SQLite database.
func (*Store) ClusterDaily ¶
func (s *Store) ClusterDaily(ctx context.Context, cluster string, days int, loc *time.Location) ([]ClusterDay, error)
ClusterDaily replays the history to the state at the end of each of the last days days (oldest first) in loc. Days before the history began count nothing.
func (*Store) ClusterHistory ¶
func (s *Store) ClusterHistory(ctx context.Context, cluster, namespace, group string, limit int) ([]ClusterEvent, error)
ClusterHistory returns the newest events of a workload group, newest first.
func (*Store) ClusterStatusSince ¶
func (s *Store) ClusterStatusSince(ctx context.Context, cluster string) (map[ClusterKey]time.Time, error)
ClusterStatusSince returns, per workload group, since when its current status holds.
func (*Store) CreateScan ¶
CreateScan stores a new scan and sets its ID.
func (*Store) Daily ¶
Daily returns one entry per day for the last days days (oldest first), grouped by the day the run finished in loc.
func (*Store) DeleteScan ¶
DeleteScan deletes a scan. Its runs are kept as ad-hoc runs.
func (*Store) FailUnfinished ¶
FailUnfinished marks runs left queued or running by a previous process as failed. Call it once at startup.
func (*Store) FinishRun ¶
FinishRun stores the result of a run: the report, or the error that stopped it. A run with an error is never stored as clean.
func (*Store) GetReport ¶
GetReport returns the scan report of a finished run, or nil if the run has none (still running or failed).
func (*Store) HasActiveRun ¶
HasActiveRun reports whether a scan has a queued or running run.
func (*Store) ImageStatus ¶
ImageStatus returns the latest finished run of every image reference, infected images first.
func (*Store) LiveClusterReports ¶
func (s *Store) LiveClusterReports(ctx context.Context, cluster string) (map[ClusterReportKey]ClusterEvent, error)
LiveClusterReports returns the reports whose last event is not a deletion, with that event, to record deletions missed while the server was down.
func (*Store) PruneClusterEvents ¶
PruneClusterEvents deletes events recorded before t, except the last event of each report: it holds the current state and its StatusSince.
func (*Store) RecordClusterEvent ¶
RecordClusterEvent stores e unless it repeats the last event of the report: the same scan (status, digest, scan time), or a second deletion. Reports seen again after a restart therefore add nothing. If the group of the report changed (e.g. its Deployment became known), its earlier events move to the new group. It sets e.ID and e.StatusSince and reports whether e was stored.
func (*Store) SetProgress ¶
SetProgress updates the progress text of a running run.
func (*Store) TopSignatures ¶
func (s *Store) TopSignatures(ctx context.Context, since time.Time, limit int) ([]SignatureCount, error)
TopSignatures returns the most frequent signatures of runs finished since since.