Modern Docker Management, Designed for Everyone
Go composecontainer-managementcontainersdockerdocker-composedocker-managementgoself-hostedsveltekittypescriptweb-ui
refactor: use arcane/tools image for volume browser and trivy scans (#2409)
Kyle Mendell45ab5e01b6fd
diff --git a/backend/internal/models/settings.go b/backend/internal/models/settings.goindex 001f24db2..c3ca1ae91 100644--- a/backend/internal/models/settings.go+++ b/backend/internal/models/settings.go@@ -136,7 +136,7 @@ type Settings struct {AuthPasswordPolicy SettingVariable `key:"authPasswordPolicy" meta:"label=Password Policy;type=select;keywords=password,policy,strength,complexity,requirements,security,rules;category=authentication;description=Set password strength requirements"`VulnerabilityScanEnabled SettingVariable `key:"vulnerabilityScanEnabled" meta:"label=Scheduled Vulnerability Scan;type=boolean;keywords=vulnerability,scan,security,trivy,schedule,automatic,cve;category=security;description=Enable scheduled vulnerability scanning of all Docker images" catmeta:"id=security;title=Security;icon=shield;url=/settings/security;description=Configure vulnerability scanning and runtime security settings"`VulnerabilityScanInterval SettingVariable `key:"vulnerabilityScanInterval" meta:"label=Vulnerability Scan Interval;type=cron;keywords=vulnerability,scan,interval,schedule,frequency,trivy,cve;category=security;description=How often to run scheduled vulnerability scans (cron expression)"`- TrivyImage SettingVariable `key:"trivyImage" meta:"label=Trivy Image;type=text;keywords=trivy,scanner,vulnerability,security,image;category=security;description=Override the Trivy image used for vulnerability scans"`+ TrivyImage SettingVariable `key:"trivyImage" meta:"label=Arcane Tools Image;type=text;keywords=trivy,scanner,vulnerability,security,image,tools;category=security;description=Override the Arcane tools image used to run Trivy vulnerability scans"`TrivyNetwork SettingVariable `key:"trivyNetwork,envOverride" meta:"label=Trivy Network;type=text;keywords=trivy,network,mode,bridge,host,none,scanner,vulnerability,security;category=security;description=Docker network mode/network name used for Trivy scan containers. Leave empty to inherit Arcane's network automatically."`TrivySecurityOpts SettingVariable `key:"trivySecurityOpts,envOverride" meta:"label=Trivy Security Options;type=textarea;keywords=trivy,security,opt,security_opt,selinux,labels,apparmor,scanner;category=security;description=Docker security options applied to Trivy scan containers. Use commas or new lines to separate entries (for example: label=disable)"`TrivyPrivileged SettingVariable `key:"trivyPrivileged,envOverride" meta:"label=Trivy Privileged;type=boolean;keywords=trivy,privileged,security,selinux,scanner;category=security;description=Run Trivy scan containers in privileged mode when required by the host security policy"`diff --git a/backend/internal/services/volume_service.go b/backend/internal/services/volume_service.goindex ab495ad1d..de7940122 100644--- a/backend/internal/services/volume_service.go+++ b/backend/internal/services/volume_service.go@@ -44,7 +44,7 @@ type VolumeService struct {helperByVolume map[string]string}-const volumeHelperImage = "busybox:stable-musl"+const volumeHelperImage = DefaultArcaneToolsImagetype backupStorageMode string@@ -296,7 +296,7 @@ func (s *VolumeService) ListDirectory(ctx context.Context, volumeName, dirPath stargetPath := path.Join("/volume", sanitizedPath)quotedPath := strconv.Quote(targetPath)- cmd := []string{"sh", "-c", fmt.Sprintf("find %s -mindepth 1 -maxdepth 1 -exec sh -c 'for f; do out=$(stat -c \"%%s %%Y %%f %%A\" -- \"$f\" 2>/dev/null) || continue; printf \"%%s\\0%%s\\0\" \"$f\" \"$out\"; done' sh {} + || true", quotedPath)}+ cmd := []string{"sh", "-c", fmt.Sprintf("find %s -mindepth 1 -maxdepth 1 | while IFS= read -r f; do out=$(stat -c \"%%s %%Y %%f %%A\" -- \"$f\" 2>/dev/null) || continue; printf \"%%s\\0%%s\\0\" \"$f\" \"$out\"; done", quotedPath)}stdout, _, err := s.execInContainerInternal(ctx, containerID, cmd)if err != nil {return nil, fmt.Errorf("failed to list directory: %w", err)@@ -431,7 +431,7 @@ func (s *VolumeService) getHelperImageInternal(ctx context.Context, dockerClient}if _, err := dockerClient.ImageInspect(ctx, volumeHelperImage); err == nil {- slog.InfoContext(ctx, "volume service: helper image strategy selected", "strategy", "busybox-local", "image", volumeHelperImage)+ slog.InfoContext(ctx, "volume service: helper image strategy selected", "strategy", "tools-local", "image", volumeHelperImage)return volumeHelperImage, nil}@@ -439,11 +439,11 @@ func (s *VolumeService) getHelperImageInternal(ctx context.Context, dockerClientif s.imageService != nil {pullImageErr := s.imageService.PullImage(ctx, volumeHelperImage, io.Discard, systemUser, nil)if pullImageErr == nil {- slog.InfoContext(ctx, "volume service: helper image strategy selected", "strategy", "busybox-pulled", "image", volumeHelperImage)+ slog.InfoContext(ctx, "volume service: helper image strategy selected", "strategy", "tools-pulled", "image", volumeHelperImage)return volumeHelperImage, nil}pullErr = pullImageErr- slog.WarnContext(ctx, "volume service: failed to pull busybox helper image, attempting arcane fallback", "error", pullImageErr.Error())+ slog.WarnContext(ctx, "volume service: failed to pull tools helper image, attempting arcane fallback", "error", pullImageErr.Error())} else {pullErr = fmt.Errorf("image service unavailable")slog.WarnContext(ctx, "volume service: image service unavailable, attempting arcane fallback")@@ -454,7 +454,11 @@ func (s *VolumeService) getHelperImageInternal(ctx context.Context, dockerClientreturn fallbackImage, nil}- return "", fmt.Errorf("failed to resolve helper image: busybox unavailable and arcane fallback not found (pull error: %w)", pullErr)+ return "", fmt.Errorf("failed to resolve helper image: tools image unavailable and arcane fallback not found (pull error: %w)", pullErr)+}++func (s *VolumeService) getArchiveHelperImageInternal(ctx context.Context, dockerClient *client.Client) (string, error) {+ return s.getHelperImageInternal(ctx, dockerClient)}func (s *VolumeService) resolveArcaneHelperImageInternal(ctx context.Context, dockerClient *client.Client) (string, string, bool) {@@ -598,7 +602,7 @@ func (s *VolumeService) getArcaneContainerIDInternal(ctx context.Context, dockerreturn containers.Items[0].ID}-func (s *VolumeService) createBackupTempContainerWithMountInternal(ctx context.Context, dockerClient *client.Client, backupMount mount.Mount) (string, func(), error) {+func (s *VolumeService) createBackupTempContainerWithMountInternal(ctx context.Context, dockerClient *client.Client, helperImage string, backupMount mount.Mount) (string, func(), error) {var err errorif dockerClient == nil {dockerClient, err = s.dockerService.GetClient(ctx)@@ -607,9 +611,11 @@ func (s *VolumeService) createBackupTempContainerWithMountInternal(ctx context.C}}- helperImage, err := s.getHelperImageInternal(ctx, dockerClient)- if err != nil {- return "", nil, err+ if strings.TrimSpace(helperImage) == "" {+ helperImage, err = s.getHelperImageInternal(ctx, dockerClient)+ if err != nil {+ return "", nil, err+ }}config := &container.Config{@@ -656,7 +662,7 @@ func (s *VolumeService) createBackupTempContainerInternal(ctx context.Context, dreturn "", nil, err}- return s.createBackupTempContainerWithMountInternal(ctx, dockerClient, backupStorage.mount)+ return s.createBackupTempContainerWithMountInternal(ctx, dockerClient, "", backupStorage.mount)}type cleanupReadCloser struct {@@ -896,6 +902,22 @@ func (s *VolumeService) execInContainerInternal(ctx context.Context, containerIDreturn "", "", err}+ inspect, err := dockerClient.ExecInspect(ctx, execResp.ID, client.ExecInspectOptions{})+ if err != nil {+ return stdout.String(), stderr.String(), fmt.Errorf("failed to inspect exec result: %w", err)+ }++ if inspect.ExitCode != 0 {+ execErr := strings.TrimSpace(stderr.String())+ if execErr == "" {+ execErr = strings.TrimSpace(stdout.String())+ }+ if execErr != "" {+ return stdout.String(), stderr.String(), fmt.Errorf("command exited with code %d: %s", inspect.ExitCode, execErr)+ }+ return stdout.String(), stderr.String(), fmt.Errorf("command exited with code %d", inspect.ExitCode)+ }+return stdout.String(), stderr.String(), nil}@@ -1077,7 +1099,7 @@ func (s *VolumeService) CreateBackup(ctx context.Context, volumeName string, usereturn nil, err}- helperImage, err := s.getHelperImageInternal(ctx, dockerClient)+ helperImage, err := s.getArchiveHelperImageInternal(ctx, dockerClient)if err != nil {return nil, err}@@ -1126,7 +1148,7 @@ func (s *VolumeService) CreateBackup(ctx context.Context, volumeName string, usesizeCheckMount.Target = "/volume"sizeCheckMount.ReadOnly = true- tempContainerID, cleanup, err := s.createBackupTempContainerWithMountInternal(ctx, dockerClient, sizeCheckMount)+ tempContainerID, cleanup, err := s.createBackupTempContainerWithMountInternal(ctx, dockerClient, "", sizeCheckMount)if err != nil {return nil, err}@@ -1320,7 +1342,7 @@ func (s *VolumeService) RestoreBackup(ctx context.Context, volumeName, backupIDreturn err}- helperImage, err := s.getHelperImageInternal(ctx, dockerClient)+ helperImage, err := s.getArchiveHelperImageInternal(ctx, dockerClient)if err != nil {return err}@@ -1460,7 +1482,22 @@ func (s *VolumeService) BackupHasPath(ctx context.Context, backupID string, filereturn false, err}- containerID, cleanup, err := s.createBackupTempContainerInternal(ctx, nil, "/volume", true)+ dockerClient, err := s.dockerService.GetClient(ctx)+ if err != nil {+ return false, err+ }++ helperImage, err := s.getArchiveHelperImageInternal(ctx, dockerClient)+ if err != nil {+ return false, err+ }++ backupStorage, err := s.resolveUsableBackupStorageMountInternal(ctx, dockerClient, "/volume", true)+ if err != nil {+ return false, err+ }++ containerID, cleanup, err := s.createBackupTempContainerWithMountInternal(ctx, dockerClient, helperImage, backupStorage.mount)if err != nil {return false, err}@@ -1502,7 +1539,22 @@ func (s *VolumeService) ListBackupFiles(ctx context.Context, backupID string) ([return nil, err}- containerID, cleanup, err := s.createBackupTempContainerInternal(ctx, nil, "/volume", true)+ dockerClient, err := s.dockerService.GetClient(ctx)+ if err != nil {+ return nil, err+ }++ helperImage, err := s.getArchiveHelperImageInternal(ctx, dockerClient)+ if err != nil {+ return nil, err+ }++ backupStorage, err := s.resolveUsableBackupStorageMountInternal(ctx, dockerClient, "/volume", true)+ if err != nil {+ return nil, err+ }++ containerID, cleanup, err := s.createBackupTempContainerWithMountInternal(ctx, dockerClient, helperImage, backupStorage.mount)if err != nil {return nil, err}@@ -1584,7 +1636,7 @@ func (s *VolumeService) RestoreBackupFiles(ctx context.Context, volumeName, backreturn err}- helperImage, err := s.getHelperImageInternal(ctx, dockerClient)+ helperImage, err := s.getArchiveHelperImageInternal(ctx, dockerClient)if err != nil {return err}diff --git a/backend/internal/services/vulnerability_service.go b/backend/internal/services/vulnerability_service.goindex dd00a111f..d6ea69c79 100644--- a/backend/internal/services/vulnerability_service.go+++ b/backend/internal/services/vulnerability_service.go@@ -39,8 +39,12 @@ import ()const (- // DefaultTrivyImage is pinned to Trivy 0.70.0- DefaultTrivyImage = "ghcr.io/aquasecurity/trivy@sha256:be1190afcb28352bfddc4ddeb71470835d16462af68d310f9f4bca710961a41e"+ // DefaultArcaneToolsImage is the shared Arcane toolbox image used for+ // helper commands and Trivy-based vulnerability scans.+ DefaultArcaneToolsImage = "ghcr.io/getarcaneapp/tools:latest"+ // DefaultTrivyImage preserves the existing setting name, but now points at+ // the shared Arcane tools image that includes the Trivy binary.+ DefaultTrivyImage = DefaultArcaneToolsImageDefaultTrivyNetworkMode = "bridge"trivyCacheVolumeName = "arcane-trivy-cache"trivyCacheMountTarget = "/root/.cache"@@ -1544,7 +1548,7 @@ func (s *VulnerabilityService) CleanupOrphanedScanRecords(ctx context.Context) (return result.RowsAffected, nil}-// GetTrivyVersion returns the Trivy version from the Trivy container image+// GetTrivyVersion returns the Trivy version from the configured scanner image.func (s *VulnerabilityService) GetTrivyVersion(ctx context.Context) string {dockerClient, err := s.dockerService.GetClient(ctx)if err != nil {@@ -1557,8 +1561,9 @@ func (s *VulnerabilityService) GetTrivyVersion(ctx context.Context) string {}config := &containertypes.Config{- Image: trivyImage,- Cmd: []string{"--version"},+ Image: trivyImage,+ Entrypoint: []string{"trivy"},+ Cmd: []string{"--version"},Labels: map[string]string{libarcane.InternalResourceLabel: "true",},@@ -2018,13 +2023,13 @@ func (s *VulnerabilityService) ensureTrivyImageInternal(ctx context.Context) (stpullReader, err := dockerClient.ImagePull(pullCtx, trivyImage, client.ImagePullOptions{})if err != nil {if errors.Is(pullCtx.Err(), context.DeadlineExceeded) {- return "", fmt.Errorf("trivy image pull timed out for %s (increase DOCKER_IMAGE_PULL_TIMEOUT or setting)", trivyImage)+ return "", fmt.Errorf("scanner image pull timed out for %s (increase DOCKER_IMAGE_PULL_TIMEOUT or setting)", trivyImage)}- return "", fmt.Errorf("pull trivy image %s: %w", trivyImage, err)+ return "", fmt.Errorf("pull scanner image %s: %w", trivyImage, err)}if err := dockerutils.ConsumeJSONMessageStream(pullReader, nil); err != nil {_ = pullReader.Close()- return "", fmt.Errorf("failed to complete trivy image pull: %w", err)+ return "", fmt.Errorf("failed to complete scanner image pull: %w", err)}_ = pullReader.Close()@@ -2148,9 +2153,10 @@ func (s *VulnerabilityService) buildTrivyCommandArgs(func buildTrivyContainerConfig(trivyImage string, cmdArgs []string, env []string) *containertypes.Config {return &containertypes.Config{- Image: trivyImage,- Cmd: cmdArgs,- Env: append([]string(nil), env...),+ Image: trivyImage,+ Entrypoint: []string{"trivy"},+ Cmd: cmdArgs,+ Env: append([]string(nil), env...),Labels: map[string]string{libarcane.InternalResourceLabel: "true",},diff --git a/backend/internal/services/vulnerability_service_test.go b/backend/internal/services/vulnerability_service_test.goindex 6dfed9fdd..e5968564b 100644--- a/backend/internal/services/vulnerability_service_test.go+++ b/backend/internal/services/vulnerability_service_test.go@@ -297,6 +297,7 @@ func TestBuildTrivyContainerConfig_IncludesEnv(t *testing.T) {[]string{"DOCKER_HOST=tcp://docker-socket-proxy:2375"},)+ require.Equal(t, []string{"trivy"}, config.Entrypoint)require.Equal(t, []string{"DOCKER_HOST=tcp://docker-socket-proxy:2375"}, config.Env)}diff --git a/frontend/messages/en.json b/frontend/messages/en.jsonindex c57cbbeb8..3e6268a90 100644--- a/frontend/messages/en.json+++ b/frontend/messages/en.json@@ -1380,9 +1380,9 @@"security_password_policy_standard_tooltip": "10+ chars with upper, lower, and a number.","security_password_policy_strong_tooltip": "12+ chars with upper, lower, number, and symbol.","security_vulnerability_scanning_heading": "Vulnerability Scanning",- "security_trivy_image_label": "Trivy Image",- "security_trivy_image_description": "Container image used for vulnerability scans.",- "security_trivy_image_note": "Note: This must be a Trivy image (for example, ghcr.io/aquasecurity/trivy:latest).",+ "security_trivy_image_label": "Arcane Tools Image",+ "security_trivy_image_description": "Container image used to run Trivy vulnerability scans.",+ "security_trivy_image_note": "Note: This must be an Arcane tools image that includes Trivy (for example, ghcr.io/getarcaneapp/tools:latest).","security_trivy_network_label": "Trivy Network","security_trivy_network_description": "Docker network mode/network name used for Trivy scan containers.","security_trivy_network_help": "Leave this on Auto to inherit Arcane's network. Choose host, none, bridge, or a custom Docker network only when you need to override it.",diff --git a/frontend/src/lib/components/settings/trivy-security-settings.svelte b/frontend/src/lib/components/settings/trivy-security-settings.svelteindex 355968378..04d41dcac 100644--- a/frontend/src/lib/components/settings/trivy-security-settings.svelte+++ b/frontend/src/lib/components/settings/trivy-security-settings.svelte@@ -1,5 +1,4 @@<script lang="ts">- import { onMount } from 'svelte';import * as Card from '$lib/components/ui/card/index.js';import { Label } from '$lib/components/ui/label';import { Switch } from '$lib/components/ui/switch/index.js';@@ -127,7 +126,7 @@}}- onMount(() => {+ $effect(() => {void loadTrivyNetworkOptions();});</script>@@ -153,7 +152,7 @@error={$formInputs.trivyImage.error}disabled={true}label={m.security_trivy_image_label()}- placeholder="ghcr.io/aquasecurity/trivy@sha256:bcc376de8d77cfe086a917230e818dc9f8528e3c852f7b1aff648949b6258d1c"+ placeholder="ghcr.io/getarcaneapp/tools:latest"type="text"/></div>