Modern Docker Management, Designed for Everyone
Go composecontainer-managementcontainersdockerdocker-composedocker-managementgoself-hostedsveltekittypescriptweb-ui
fix: forward proxy config to Trivy scan containers (#4168)
Kyle Mendell85b9b16baa0d
diff --git a/backend/internal/config/config.go b/backend/internal/config/config.goindex 82ae4e9f5..57c03385c 100644--- a/backend/internal/config/config.go+++ b/backend/internal/config/config.go@@ -109,6 +109,11 @@ type Config struct {HTTPClientTimeout int `env:"HTTP_CLIENT_TIMEOUT" default:"0"`BackupVolumeName string `env:"ARCANE_BACKUP_VOLUME_NAME" default:"arcane-backups"`+ // HTTPProxy, HTTPSProxy and NoProxy are forwarded to temporary Trivy scan containers.+ HTTPProxy string `env:"HTTP_PROXY" default:""`+ HTTPSProxy string `env:"HTTPS_PROXY" default:""`+ NoProxy string `env:"NO_PROXY" default:""`+// Timezone for cron job scheduling. Uses IANA timezone names (e.g., "America/New_York", "Europe/London").// "Local" uses the system's local timezone, "UTC" for Coordinated Universal Time.Timezone string `env:"TZ" default:"Local"`diff --git a/backend/internal/config/schema/schema_test.go b/backend/internal/config/schema/schema_test.goindex e65d9842e..29a33ef59 100644--- a/backend/internal/config/schema/schema_test.go+++ b/backend/internal/config/schema/schema_test.go@@ -227,13 +227,16 @@ var expectedEnvConfigVars = []string{"GIT_WORK_DIR","GPU_MONITORING_ENABLED","GPU_TYPE",+ "HTTPS_PROXY","HTTP_CLIENT_TIMEOUT",+ "HTTP_PROXY","JWT_REFRESH_EXPIRY","JWT_SECRET","LISTEN","LOG_JSON","LOG_LEVEL","MANAGER_API_URL",+ "NO_PROXY","OIDC_AUTO_REDIRECT_TO_PROVIDER","OIDC_CLIENT_ID","OIDC_CLIENT_SECRET",diff --git a/backend/internal/vulnerability/vulnerability.go b/backend/internal/vulnerability/vulnerability.goindex 1d279fd19..6f9dd5059 100644--- a/backend/internal/vulnerability/vulnerability.go+++ b/backend/internal/vulnerability/vulnerability.go@@ -7,6 +7,7 @@ import ("github.com/getarcaneapp/arcane/backend/v2/internal/registry""github.com/getarcaneapp/arcane/backend/v2/internal/activity"+ "github.com/getarcaneapp/arcane/backend/v2/internal/config""github.com/getarcaneapp/arcane/backend/v2/internal/database""github.com/getarcaneapp/arcane/backend/v2/internal/docker""github.com/getarcaneapp/arcane/backend/v2/internal/event"@@ -31,6 +32,7 @@ const (// VulnerabilityService handles vulnerability scanning of container imagestype VulnerabilityService struct {db *database.DB+ config *config.ConfigdockerService *docker.DockerClientServiceeventService *event.EventServicesettingsService *settings.SettingsService@@ -50,9 +52,10 @@ type VulnerabilityService struct {}// NewVulnerabilityService creates a new VulnerabilityService instance-func NewVulnerabilityService(db *database.DB, dockerService *docker.DockerClientService, eventService *event.EventService, settingsService *settings.SettingsService, notificationService *notification.NotificationService, activityService *activity.ActivityService, registryService *registry.ContainerRegistryService, kvService *kv.KVService) *VulnerabilityService {+func NewVulnerabilityService(db *database.DB, cfg *config.Config, dockerService *docker.DockerClientService, eventService *event.EventService, settingsService *settings.SettingsService, notificationService *notification.NotificationService, activityService *activity.ActivityService, registryService *registry.ContainerRegistryService, kvService *kv.KVService) *VulnerabilityService {return &VulnerabilityService{db: db,+ config: cfg,dockerService: dockerService,eventService: eventService,settingsService: settingsService,diff --git a/backend/internal/vulnerability/vulnerability_trivy.go b/backend/internal/vulnerability/vulnerability_trivy.goindex 80769611e..c604b92ee 100644--- a/backend/internal/vulnerability/vulnerability_trivy.go+++ b/backend/internal/vulnerability/vulnerability_trivy.go@@ -608,6 +608,9 @@ func (s *VulnerabilityService) resolveTrivyRuntimeOptionsInternal(ctx context.Co}options.ContainerEnv = vuln.BuildDockerHostEnv(dockerHost)+ if s.config != nil {+ options.ContainerEnv = append(options.ContainerEnv, vuln.ProxyEnv(s.config.HTTPProxy, s.config.HTTPSProxy, s.config.NoProxy)...)+ }if scheme != "unix" {return options, nil}diff --git a/backend/pkg/libarcane/vuln/trivy.go b/backend/pkg/libarcane/vuln/trivy.goindex 0c5d6d523..62391304e 100644--- a/backend/pkg/libarcane/vuln/trivy.go+++ b/backend/pkg/libarcane/vuln/trivy.go@@ -117,6 +117,22 @@ func BuildDockerHostEnv(dockerHost string) []string {return []string{"DOCKER_HOST=" + dockerHost}}+// ProxyEnv returns HTTP_PROXY, HTTPS_PROXY and NO_PROXY entries for the non-empty values+// so Trivy containers download databases through the same proxy as Arcane (#4163).+func ProxyEnv(httpProxy, httpsProxy, noProxy string) []string {+ values := [...][2]string{{"HTTP_PROXY", httpProxy}, {"HTTPS_PROXY", httpsProxy}, {"NO_PROXY", noProxy}}+ env := make([]string, 0, len(values))+ for _, kv := range values {+ if value := strings.TrimSpace(kv[1]); value != "" {+ env = append(env, kv[0]+"="+value)+ }+ }+ if len(env) == 0 {+ return nil+ }+ return env+}+// ScanCacheBackendArgsForArch returns the Trivy cache-backend flags for a GOARCH.// 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.diff --git a/backend/pkg/libarcane/vuln/trivy_test.go b/backend/pkg/libarcane/vuln/trivy_test.goindex bb00c80c5..9e4386355 100644--- a/backend/pkg/libarcane/vuln/trivy_test.go+++ b/backend/pkg/libarcane/vuln/trivy_test.go@@ -166,6 +166,45 @@ func TestIgnoreUnfixedArgs(t *testing.T) {require.Nil(t, IgnoreUnfixedArgs(false))}+func TestProxyEnv(t *testing.T) {+ tests := []struct {+ name string+ httpProxy string+ httpsProxy string+ noProxy string+ want []string+ }{+ {+ name: "empty values return nil",+ httpsProxy: " ",+ want: nil,+ },+ {+ name: "all values in fixed order",+ httpProxy: "http://proxy:3128",+ httpsProxy: "http://user:pass@proxy:3128",+ noProxy: "localhost,127.0.0.1,.corp.example",+ want: []string{+ "HTTP_PROXY=http://proxy:3128",+ "HTTPS_PROXY=http://user:pass@proxy:3128",+ "NO_PROXY=localhost,127.0.0.1,.corp.example",+ },+ },+ {+ name: "trims values and skips blanks",+ httpsProxy: " http://proxy:3128 ",+ noProxy: " ",+ want: []string{"HTTPS_PROXY=http://proxy:3128"},+ },+ }++ for _, tt := range tests {+ t.Run(tt.name, func(t *testing.T) {+ require.Equal(t, tt.want, ProxyEnv(tt.httpProxy, tt.httpsProxy, tt.noProxy))+ })+ }+}+func TestBuildContainerConfig_IncludesEnv(t *testing.T) {config := BuildContainerConfig("ghcr.io/getarcaneapp/tools:latest",