diff --git a/pkg/scan/apk.go b/pkg/scan/apk.go index b23a92e79..80641cea5 100644 --- a/pkg/scan/apk.go +++ b/pkg/scan/apk.go @@ -139,11 +139,23 @@ func NewScanner(opts Options) (*Scanner, error) { dbDestDir = DefaultGrypeDBDir } + // Default to 24 hours if GRYPE_DB_MAX_ALLOWED_BUILT_AGE is unset + maxAllowedBuiltAge := 24 * time.Hour + + grypeMaxAllowedBuiltAge := os.Getenv("GRYPE_DB_MAX_ALLOWED_BUILT_AGE") + if grypeMaxAllowedBuiltAge != "" { + parseMaxAllowedBuiltAge, err := time.ParseDuration(grypeMaxAllowedBuiltAge) + if err != nil { + return nil, fmt.Errorf("could not parse GRYPE_DB_MAX_ALLOWED_BUILT_AGE: %w", err) + } + maxAllowedBuiltAge = parseMaxAllowedBuiltAge + } + installCfg := installation.Config{ DBRootDir: dbDestDir, ValidateChecksum: true, ValidateAge: !opts.DisableDatabaseAgeValidation, - MaxAllowedBuiltAge: 24 * time.Hour, + MaxAllowedBuiltAge: maxAllowedBuiltAge, UpdateCheckMaxFrequency: 1 * time.Hour, }