Skip to content

Commit b202e39

Browse files
committed
feat(scan/apk): Respect GRYPE_DB_MAX_ALLOWED_BUILT_AGE
There was about a one hour window of time where I couldn't scan Hadoop or gRPC while working through vulnerabilities without possibly building the database locally (because it hadn't been updated yet) so I took a quick look at how we handle this in wolfictl and found it deviates from the behavior in grype Similar to grype, respect GRYPE_DB_MAX_ALLOWED_BUILT_AGE so that users can set this to whatever their preferred duration is. Default to 24 hours Signed-off-by: RJ Sampson <[email protected]>
1 parent ffb7f8d commit b202e39

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

pkg/scan/apk.go

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,11 +139,23 @@ func NewScanner(opts Options) (*Scanner, error) {
139139
dbDestDir = DefaultGrypeDBDir
140140
}
141141

142+
// Default to 24 hours if GRYPE_DB_MAX_ALLOWED_BUILT_AGE is unset
143+
maxAllowedBuiltAge := 24 * time.Hour
144+
145+
grypeMaxAllowedBuiltAge := os.Getenv("GRYPE_DB_MAX_ALLOWED_BUILT_AGE")
146+
if grypeMaxAllowedBuiltAge != "" {
147+
parseMaxAllowedBuiltAge, err := time.ParseDuration(grypeMaxAllowedBuiltAge)
148+
if err != nil {
149+
return nil, fmt.Errorf("could not parse GRYPE_DB_MAX_ALLOWED_BUILT_AGE: %w", err)
150+
}
151+
maxAllowedBuiltAge = parseMaxAllowedBuiltAge
152+
}
153+
142154
installCfg := installation.Config{
143155
DBRootDir: dbDestDir,
144156
ValidateChecksum: true,
145157
ValidateAge: !opts.DisableDatabaseAgeValidation,
146-
MaxAllowedBuiltAge: 24 * time.Hour,
158+
MaxAllowedBuiltAge: maxAllowedBuiltAge,
147159
UpdateCheckMaxFrequency: 1 * time.Hour,
148160
}
149161

0 commit comments

Comments
 (0)