mirror of
https://github.com/project-zot/zot.git
synced 2026-06-16 04:17:55 +08:00
fix(cve): Fix CVE scanning in images containing Jar files (#1475)
This commit is contained in:
@@ -641,6 +641,13 @@ func TestServeSearchEnabled(t *testing.T) {
|
||||
substring := `"Extensions":{"Search":{"Enable":true,"CVE":null}`
|
||||
|
||||
found, err := readLogFileAndSearchString(logPath, substring, readLogFileTimeout)
|
||||
|
||||
if !found {
|
||||
data, err := os.ReadFile(logPath)
|
||||
So(err, ShouldBeNil)
|
||||
t.Log(string(data))
|
||||
}
|
||||
|
||||
So(found, ShouldBeTrue)
|
||||
So(err, ShouldBeNil)
|
||||
})
|
||||
@@ -680,20 +687,26 @@ func TestServeSearchEnabledCVE(t *testing.T) {
|
||||
// to avoid data race when multiple go routines write to trivy DB instance.
|
||||
WaitTillTrivyDBDownloadStarted(tempDir)
|
||||
|
||||
substring := "\"Search\":{\"Enable\":true,\"CVE\":{\"UpdateInterval\":3600000000000,\"Trivy\":null}}"
|
||||
// The default config handling logic will convert the 1h interval to a 2h interval
|
||||
substring := "\"Search\":{\"Enable\":true,\"CVE\":{\"UpdateInterval\":7200000000000,\"Trivy\":" +
|
||||
"{\"DBRepository\":\"ghcr.io/aquasecurity/trivy-db\",\"JavaDBRepository\":\"ghcr.io/aquasecurity/trivy-java-db\"}}}"
|
||||
|
||||
found, err := readLogFileAndSearchString(logPath, substring, readLogFileTimeout)
|
||||
|
||||
defer func() {
|
||||
if !found {
|
||||
data, err := os.ReadFile(logPath)
|
||||
So(err, ShouldBeNil)
|
||||
t.Log(string(data))
|
||||
}
|
||||
}()
|
||||
|
||||
So(found, ShouldBeTrue)
|
||||
So(err, ShouldBeNil)
|
||||
|
||||
found, err = readLogFileAndSearchString(logPath, "updating the CVE database", readLogFileTimeout)
|
||||
So(found, ShouldBeTrue)
|
||||
So(err, ShouldBeNil)
|
||||
|
||||
substring = "CVE update interval set to too-short interval < 2h, changing update duration to 2 hours and continuing." //nolint:lll // gofumpt conflicts with lll
|
||||
found, err = readLogFileAndSearchString(logPath, substring, readLogFileTimeout)
|
||||
So(found, ShouldBeTrue)
|
||||
So(err, ShouldBeNil)
|
||||
})
|
||||
}
|
||||
|
||||
@@ -729,6 +742,13 @@ func TestServeSearchEnabledNoCVE(t *testing.T) {
|
||||
|
||||
substring := `"Extensions":{"Search":{"Enable":true,"CVE":null}` //nolint:lll // gofumpt conflicts with lll
|
||||
found, err := readLogFileAndSearchString(logPath, substring, readLogFileTimeout)
|
||||
|
||||
if !found {
|
||||
data, err := os.ReadFile(logPath)
|
||||
So(err, ShouldBeNil)
|
||||
t.Log(string(data))
|
||||
}
|
||||
|
||||
So(found, ShouldBeTrue)
|
||||
So(err, ShouldBeNil)
|
||||
})
|
||||
|
||||
+30
-1
@@ -448,7 +448,7 @@ func validateAuthzPolicies(config *config.Config) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
//nolint:gocyclo
|
||||
//nolint:gocyclo,cyclop,nestif
|
||||
func applyDefaultValues(config *config.Config, viperInstance *viper.Viper) {
|
||||
defaultVal := true
|
||||
|
||||
@@ -503,6 +503,35 @@ func applyDefaultValues(config *config.Config, viperInstance *viper.Viper) {
|
||||
if config.Extensions.Search.Enable == nil {
|
||||
config.Extensions.Search.Enable = &defaultVal
|
||||
}
|
||||
|
||||
if *config.Extensions.Search.Enable && config.Extensions.Search.CVE != nil {
|
||||
defaultUpdateInterval, _ := time.ParseDuration("2h")
|
||||
|
||||
if config.Extensions.Search.CVE.UpdateInterval < defaultUpdateInterval {
|
||||
config.Extensions.Search.CVE.UpdateInterval = defaultUpdateInterval
|
||||
|
||||
log.Warn().Msg("CVE update interval set to too-short interval < 2h, " +
|
||||
"changing update duration to 2 hours and continuing.")
|
||||
}
|
||||
|
||||
if config.Extensions.Search.CVE.Trivy == nil {
|
||||
config.Extensions.Search.CVE.Trivy = &extconf.TrivyConfig{}
|
||||
}
|
||||
|
||||
if config.Extensions.Search.CVE.Trivy.DBRepository == "" {
|
||||
defaultDBDownloadURL := "ghcr.io/aquasecurity/trivy-db"
|
||||
log.Info().Str("trivyDownloadURL", defaultDBDownloadURL).
|
||||
Msg("Config: using default Trivy DB download URL.")
|
||||
config.Extensions.Search.CVE.Trivy.DBRepository = defaultDBDownloadURL
|
||||
}
|
||||
|
||||
if config.Extensions.Search.CVE.Trivy.JavaDBRepository == "" {
|
||||
defaultJavaDBDownloadURL := "ghcr.io/aquasecurity/trivy-java-db"
|
||||
log.Info().Str("trivyJavaDownloadURL", defaultJavaDBDownloadURL).
|
||||
Msg("Config: using default Trivy Java DB download URL.")
|
||||
config.Extensions.Search.CVE.Trivy.JavaDBRepository = defaultJavaDBDownloadURL
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if config.Extensions.Metrics != nil {
|
||||
|
||||
Reference in New Issue
Block a user