mirror of
https://github.com/aquasecurity/trivy.git
synced 2025-12-18 18:22:40 -08:00
* detector/alpine: Add LayerID to detect vulns Signed-off-by: Simarpreet Singh <simar@linux.com> * amazon: Add LayerID to DetectedVulns Signed-off-by: Simarpreet Singh <simar@linux.com> * debian: Add LayerID to DetectVulns + tests Signed-off-by: Simarpreet Singh <simar@linux.com> * oracle: Add LayerID to DetectVulns + tests Signed-off-by: Simarpreet Singh <simar@linux.com> * photon: Add LayerID to DetectVulns + tests Signed-off-by: Simarpreet Singh <simar@linux.com> * redhat: Add LayerID to DetectVulns + tests Signed-off-by: Simarpreet Singh <simar@linux.com> * suse: Add LayerID to DetectVulns + tests Signed-off-by: Simarpreet Singh <simar@linux.com> * ubuntu: Add LayerID to DetectVulns + tests Signed-off-by: Simarpreet Singh <simar@linux.com> * integration: Fix integration tests to include LayerID Signed-off-by: Simarpreet Singh <simar@linux.com> * fix(rpc): add layer_id * fix(rpc): insert layer_id to the struct * fix(extractor): add cleanup function * fix(library): add layer ID to detected vulnerabilities * test: update mocks * chore(mod): point to the feature branch of fanal * mod: Point to fanal/master Signed-off-by: Simarpreet Singh <simar@linux.com> * scan_test: Include LayerID as part of the assertion Signed-off-by: Simarpreet Singh <simar@linux.com> * docker_engine_test.go: Update an error message to conform with fanal/master. Signed-off-by: Simarpreet Singh <simar@linux.com> Co-authored-by: Teppei Fukuda <knqyf263@gmail.com>
97 lines
2.6 KiB
Go
97 lines
2.6 KiB
Go
package oracle
|
|
|
|
import (
|
|
"strings"
|
|
"time"
|
|
|
|
oracleoval "github.com/aquasecurity/trivy-db/pkg/vulnsrc/oracle-oval"
|
|
version "github.com/knqyf263/go-rpm-version"
|
|
|
|
"golang.org/x/xerrors"
|
|
|
|
ftypes "github.com/aquasecurity/fanal/types"
|
|
dbTypes "github.com/aquasecurity/trivy-db/pkg/types"
|
|
"github.com/aquasecurity/trivy/pkg/log"
|
|
"github.com/aquasecurity/trivy/pkg/scanner/utils"
|
|
"github.com/aquasecurity/trivy/pkg/types"
|
|
|
|
"k8s.io/utils/clock"
|
|
)
|
|
|
|
var (
|
|
eolDates = map[string]time.Time{
|
|
// Source:
|
|
// https://www.oracle.com/a/ocom/docs/elsp-lifetime-069338.pdf
|
|
// https://community.oracle.com/docs/DOC-917964
|
|
"3": time.Date(2011, 12, 31, 23, 59, 59, 0, time.UTC),
|
|
"4": time.Date(2013, 12, 31, 23, 59, 59, 0, time.UTC),
|
|
"5": time.Date(2017, 12, 31, 23, 59, 59, 0, time.UTC),
|
|
"6": time.Date(2021, 3, 21, 23, 59, 59, 0, time.UTC),
|
|
"7": time.Date(2024, 7, 23, 23, 59, 59, 0, time.UTC),
|
|
"8": time.Date(2029, 7, 18, 23, 59, 59, 0, time.UTC),
|
|
}
|
|
)
|
|
|
|
type Scanner struct {
|
|
vs dbTypes.VulnSrc
|
|
clock clock.Clock
|
|
}
|
|
|
|
func NewScanner() *Scanner {
|
|
return &Scanner{
|
|
vs: oracleoval.NewVulnSrc(),
|
|
clock: clock.RealClock{},
|
|
}
|
|
}
|
|
|
|
func (s *Scanner) Detect(osVer string, pkgs []ftypes.Package) ([]types.DetectedVulnerability, error) {
|
|
log.Logger.Info("Detecting Oracle Linux vulnerabilities...")
|
|
|
|
if strings.Count(osVer, ".") > 0 {
|
|
osVer = osVer[:strings.Index(osVer, ".")]
|
|
}
|
|
|
|
log.Logger.Debugf("Oracle Linux: os version: %s", osVer)
|
|
log.Logger.Debugf("Oracle Linux: the number of packages: %d", len(pkgs))
|
|
|
|
var vulns []types.DetectedVulnerability
|
|
for _, pkg := range pkgs {
|
|
advisories, err := s.vs.Get(osVer, pkg.SrcName)
|
|
if err != nil {
|
|
return nil, xerrors.Errorf("failed to get Oracle Linux advisory: %w", err)
|
|
}
|
|
|
|
installed := utils.FormatVersion(pkg)
|
|
installedVersion := version.NewVersion(installed)
|
|
for _, adv := range advisories {
|
|
// TODO: We don't seem to ignore advisories with no FixedVersion like we do elsewhere, expected?
|
|
fixedVersion := version.NewVersion(adv.FixedVersion)
|
|
vuln := types.DetectedVulnerability{
|
|
VulnerabilityID: adv.VulnerabilityID,
|
|
PkgName: pkg.Name,
|
|
InstalledVersion: installed,
|
|
LayerID: pkg.LayerID,
|
|
}
|
|
if installedVersion.LessThan(fixedVersion) {
|
|
vuln.FixedVersion = adv.FixedVersion
|
|
vulns = append(vulns, vuln)
|
|
}
|
|
}
|
|
}
|
|
return vulns, nil
|
|
}
|
|
|
|
func (s *Scanner) IsSupportedVersion(osFamily, osVer string) bool {
|
|
if strings.Count(osVer, ".") > 0 {
|
|
osVer = osVer[:strings.Index(osVer, ".")]
|
|
}
|
|
|
|
eol, ok := eolDates[osVer]
|
|
if !ok {
|
|
log.Logger.Warnf("This OS version is not on the EOL list: %s %s", osFamily, osVer)
|
|
return false
|
|
}
|
|
|
|
return s.clock.Now().Before(eol)
|
|
}
|