2022-09-28 13:39:54 -05:00
|
|
|
package model
|
|
|
|
|
2023-04-18 13:07:47 -05:00
|
|
|
import (
|
|
|
|
"time"
|
|
|
|
|
|
|
|
godigest "github.com/opencontainers/go-digest"
|
|
|
|
)
|
|
|
|
|
2023-07-06 03:36:26 -05:00
|
|
|
type ImageCVESummary struct {
|
2023-12-13 12:16:31 -05:00
|
|
|
Count int
|
|
|
|
UnknownCount int
|
|
|
|
LowCount int
|
|
|
|
MediumCount int
|
|
|
|
HighCount int
|
|
|
|
CriticalCount int
|
|
|
|
MaxSeverity string
|
2023-07-06 03:36:26 -05:00
|
|
|
}
|
|
|
|
|
2022-09-28 13:39:54 -05:00
|
|
|
//nolint:tagliatelle // graphQL schema
|
|
|
|
type CVE struct {
|
|
|
|
ID string `json:"Id"`
|
|
|
|
Description string `json:"Description"`
|
|
|
|
Severity string `json:"Severity"`
|
|
|
|
Title string `json:"Title"`
|
2023-11-29 13:59:00 -05:00
|
|
|
Reference string `json:"Reference"`
|
2022-09-28 13:39:54 -05:00
|
|
|
PackageList []Package `json:"PackageList"`
|
|
|
|
}
|
|
|
|
|
|
|
|
//nolint:tagliatelle // graphQL schema
|
|
|
|
type Package struct {
|
|
|
|
Name string `json:"Name"`
|
|
|
|
InstalledVersion string `json:"InstalledVersion"`
|
|
|
|
FixedVersion string `json:"FixedVersion"`
|
|
|
|
}
|
2023-02-27 14:23:18 -05:00
|
|
|
|
|
|
|
const (
|
2023-09-17 17:12:20 -05:00
|
|
|
unScanned = iota
|
|
|
|
none
|
|
|
|
unknown
|
|
|
|
low
|
|
|
|
medium
|
|
|
|
high
|
|
|
|
critical
|
2023-02-27 14:23:18 -05:00
|
|
|
)
|
|
|
|
|
2023-09-17 17:12:20 -05:00
|
|
|
// Values from https://www.first.org/cvss/v3.0/specification-document
|
|
|
|
const (
|
|
|
|
SeverityNotScanned = "" // scanning was not done or was not complete
|
|
|
|
SeverityNone = "NONE" // no vulnerabilities were detected at all
|
|
|
|
SeverityUnknown = "UNKNOWN" // coresponds to CVSS 3 score NONE
|
|
|
|
SeverityLow = "LOW" // coresponds to CVSS 3 score LOW
|
|
|
|
SeverityMedium = "MEDIUM" // coresponds to CVSS 3 score MEDIUM
|
|
|
|
SeverityHigh = "HIGH" // coresponds to CVSS 3 score HIGH
|
|
|
|
SeverityCritical = "CRITICAL" // coresponds to CVSS 3 score CRITICAL
|
|
|
|
)
|
|
|
|
|
|
|
|
func severityInt(severity string) int {
|
2023-02-27 14:23:18 -05:00
|
|
|
sevMap := map[string]int{
|
2023-09-17 17:12:20 -05:00
|
|
|
SeverityNotScanned: unScanned,
|
|
|
|
SeverityNone: none,
|
|
|
|
SeverityUnknown: unknown,
|
|
|
|
SeverityLow: low,
|
|
|
|
SeverityMedium: medium,
|
|
|
|
SeverityHigh: high,
|
|
|
|
SeverityCritical: critical,
|
|
|
|
}
|
|
|
|
|
|
|
|
severityInt, ok := sevMap[severity]
|
|
|
|
|
|
|
|
if !ok {
|
|
|
|
// In the unlikely case the key is not in the map we
|
|
|
|
// return the unknown severity level
|
|
|
|
return unknown
|
2023-02-27 14:23:18 -05:00
|
|
|
}
|
|
|
|
|
2023-09-17 17:12:20 -05:00
|
|
|
return severityInt
|
|
|
|
}
|
|
|
|
|
|
|
|
func CompareSeverities(sev1, sev2 string) int {
|
|
|
|
return severityInt(sev2) - severityInt(sev1)
|
2023-02-27 14:23:18 -05:00
|
|
|
}
|
2023-04-18 13:07:47 -05:00
|
|
|
|
|
|
|
type Descriptor struct {
|
|
|
|
Digest godigest.Digest
|
|
|
|
MediaType string
|
|
|
|
}
|
|
|
|
|
2023-07-06 03:36:26 -05:00
|
|
|
type DescriptorInfo struct {
|
|
|
|
Descriptor
|
|
|
|
|
|
|
|
Timestamp time.Time
|
|
|
|
}
|
|
|
|
|
2023-04-18 13:07:47 -05:00
|
|
|
type TagInfo struct {
|
2023-07-06 03:36:26 -05:00
|
|
|
Tag string
|
2023-04-18 13:07:47 -05:00
|
|
|
Descriptor Descriptor
|
2023-07-06 03:36:26 -05:00
|
|
|
Manifests []DescriptorInfo
|
2023-04-18 13:07:47 -05:00
|
|
|
Timestamp time.Time
|
|
|
|
}
|