Skip to content

Modern Docker Management, Designed for Everyone

fix: incorrect backend arg used for trivy on 32bit hosts (#2587)

Kyle Mendell84713bfc070a
diff --git a/backend/internal/services/vulnerability_service.go b/backend/internal/services/vulnerability_service.go
index 81ec59f95..9c62ce1c6 100644
--- a/backend/internal/services/vulnerability_service.go
+++ b/backend/internal/services/vulnerability_service.go
@@ -1399,7 +1399,7 @@ func (s *VulnerabilityService) execTrivyScanInContainer(ctx context.Context, con
defer cleanupTrivyOutputFileInContainerInternal(ctx, dockerClient, containerID, outputPath)
execCmd := []string{"trivy", "image", "--format", "json", "--quiet", "--output", outputPath, "--timeout", trivyTimeout}
- execCmd = append(execCmd, trivyDBBackendArgsInternal()...)
+ execCmd = append(execCmd, trivyScanCacheBackendArgsInternal()...)
execCmd = append(execCmd, imageName)
execCfg := client.ExecCreateOptions{
@@ -2118,21 +2118,21 @@ func cleanupTempFiles(ctx context.Context, tempFiles []string) {
}
}
-// trivyDBBackendArgsForArchInternal returns extra Trivy flags that switch the
-// vulnerability DB to an in-memory backend on 32-bit architectures. bbolt's
-// default mmap-based backend can fail with ENOMEM on arm/v7 and 386 because
+// trivyScanCacheBackendArgsForArchInternal returns extra Trivy flags that switch
+// the scan cache to Trivy's documented in-memory backend on 32-bit architectures.
+// The default BoltDB-backed cache can fail with ENOMEM on arm/v7 and 386 because
// Go's heap reservations fragment the limited 32-bit virtual address space.
-func trivyDBBackendArgsForArchInternal(arch string) []string {
+func trivyScanCacheBackendArgsForArchInternal(arch string) []string {
switch arch {
case "arm", "386", "mips", "mipsle":
- return []string{"--db-backend", "memory"}
+ return []string{"--cache-backend", "memory"}
default:
return nil
}
}
-func trivyDBBackendArgsInternal() []string {
- return trivyDBBackendArgsForArchInternal(runtime.GOARCH)
+func trivyScanCacheBackendArgsInternal() []string {
+ return trivyScanCacheBackendArgsForArchInternal(runtime.GOARCH)
}
func (s *VulnerabilityService) buildTrivyCommandArgs(
@@ -2144,7 +2144,7 @@ func (s *VulnerabilityService) buildTrivyCommandArgs(
outputPath string,
) ([]string, []string) {
cmdArgs := []string{"image", "--format", "json", "--quiet", "--timeout", s.getTrivyScanTimeoutArg()}
- cmdArgs = append(cmdArgs, trivyDBBackendArgsInternal()...)
+ cmdArgs = append(cmdArgs, trivyScanCacheBackendArgsInternal()...)
var tempFiles []string
if strings.TrimSpace(configContent) != "" {
diff --git a/backend/internal/services/vulnerability_service_test.go b/backend/internal/services/vulnerability_service_test.go
index 0a49275f9..cae1715da 100644
--- a/backend/internal/services/vulnerability_service_test.go
+++ b/backend/internal/services/vulnerability_service_test.go
@@ -290,8 +290,8 @@ func TestBuildTrivyCommandArgs_WithoutCacheDir(t *testing.T) {
require.Equal(t, "alpine:3.20", cmdArgs[len(cmdArgs)-1])
}
-func TestTrivyDBBackendArgsForArch(t *testing.T) {
- memoryBackend := []string{"--db-backend", "memory"}
+func TestTrivyScanCacheBackendArgsForArch(t *testing.T) {
+ memoryBackend := []string{"--cache-backend", "memory"}
tests := []struct {
arch string
@@ -310,7 +310,9 @@ func TestTrivyDBBackendArgsForArch(t *testing.T) {
for _, tt := range tests {
t.Run(tt.arch, func(t *testing.T) {
- require.Equal(t, tt.want, trivyDBBackendArgsForArchInternal(tt.arch))
+ got := trivyScanCacheBackendArgsForArchInternal(tt.arch)
+ require.Equal(t, tt.want, got)
+ require.NotContains(t, got, "--db-backend")
})
}
}