Modern Docker Management, Designed for Everyone
Go composecontainer-managementcontainersdockerdocker-composedocker-managementgoself-hostedsveltekittypescriptweb-ui
fix: fail image patching early when Docker lacks the containerd image store (#3928)
Kyle Mendell6fdcf37c2dba
diff --git a/backend/internal/common/errors.go b/backend/internal/common/errors.goindex 19ae6b8d0..18706723c 100644--- a/backend/internal/common/errors.go+++ b/backend/internal/common/errors.go@@ -82,6 +82,7 @@ var (ErrGlobalVariableSecretValueRequired = Classify(ErrValidation, errors.Sentinel("A new value is required when making a secret variable readable"))ErrImageUntagged = Classify(ErrBadRequest, errors.Sentinel("image has no tag; only tagged images can be patched"))ErrImageLocalOnly = Classify(ErrBadRequest, errors.Sentinel("locally built image has no registry source to patch from; rebuild it to update its packages"))+ ErrPatchRequiresContainerdImageStore = Classify(ErrBadRequest, errors.Sentinel("image patching requires Docker's containerd image store; enable the containerd-snapshotter feature in daemon.json and restart Docker"))ErrPatchScanReportUnavailable = Classify(ErrNotFound, errors.Sentinel("no stored scan report is available for this scan; re-scan the image or patch without a report"))ErrPatchScanImageMismatch = Classify(ErrBadRequest, errors.Sentinel("the selected scan does not belong to this image"))ErrContainerComposeManaged = Classify(ErrConflict, errors.Sentinel("container is managed by a compose project; edit it via the project editor"))diff --git a/backend/internal/imagepatch/imagepatch.go b/backend/internal/imagepatch/imagepatch.goindex fae0dc8c7..98a51c70c 100644--- a/backend/internal/imagepatch/imagepatch.go+++ b/backend/internal/imagepatch/imagepatch.go@@ -20,6 +20,7 @@ import ("github.com/google/go-containerregistry/pkg/name""github.com/google/go-containerregistry/pkg/v1/remote""github.com/moby/buildkit/util/progress/progressui"+ "github.com/moby/moby/client"ispec "github.com/opencontainers/image-spec/specs-go/v1"copacommon "github.com/project-copacetic/copacetic/pkg/common"copapatch "github.com/project-copacetic/copacetic/pkg/patch"@@ -99,6 +100,9 @@ func (s *ImagePatchService) PatchImage(ctx context.Context, envID, imageID strinif err != nil {return nil, errors.WrapIf(err, "failed to connect to Docker")}+ if err := requireContainerdImageStoreInternal(runCtx, dockerClient); err != nil {+ return nil, err+ }imageInspect, err := dockerClient.ImageInspect(runCtx, imageID)if err != nil {@@ -279,6 +283,9 @@ func (s *ImagePatchService) patchInBackgroundInternal(ctx context.Context, recorif errors.Is(patchErr, copatypes.ErrNoUpdatesFound) {patchErr = errors.New("no OS package updates available for this image")}+ if strings.Contains(patchErr.Error(), `exporter "docker" could not be found`) {+ patchErr = common.ErrPatchRequiresContainerdImageStore+ }s.finishPatchRecordInternal(ctx, record, imagepatch.PatchStatusFailed, patchErr.Error(), nil, durationMs)slog.WarnContext(ctx, "image patch failed","environmentId", record.EnvironmentID,@@ -695,6 +702,13 @@ func (s *ImagePatchService) PatchFlaggedImages(ctx context.Context, envID stringif err := s.settingsService.RequireFeature(ctx, features.VulnerabilityManagement); err != nil {return 0, 0, err}+ dockerClient, err := s.dockerService.GetClient(ctx)+ if err != nil {+ return 0, 0, errors.WrapIf(err, "failed to connect to Docker")+ }+ if err := requireContainerdImageStoreInternal(ctx, dockerClient); err != nil {+ return 0, 0, err+ }var scans []vulnerability.VulnerabilityScanRecordif err := s.db.WithContext(ctx).Where("status = ? AND fixable_count > 0", vulnerability.ScanStatusCompleted).@@ -746,6 +760,20 @@ func (s *ImagePatchService) PatchFlaggedImages(ctx context.Context, envID stringreturn patched, skipped, nil}+// Copa needs BuildKit's docker exporter, which dockerd only offers with the containerd image store.+func requireContainerdImageStoreInternal(ctx context.Context, dockerClient *client.Client) error {+ info, err := dockerClient.Info(ctx, client.InfoOptions{})+ if err != nil {+ return errors.WrapIf(err, "failed to inspect Docker")+ }+ for _, status := range info.Info.DriverStatus {+ if status[0] == "driver-type" && status[1] == "io.containerd.snapshotter.v1" {+ return nil+ }+ }+ return common.ErrPatchRequiresContainerdImageStore+}+func (s *ImagePatchService) startPatchActivityInternal(ctx context.Context, envID, imageID, imageRef string, user *common.User) string {if s.activityService == nil {return ""diff --git a/frontend/src/routes/(app)/security/security-patch-table.svelte b/frontend/src/routes/(app)/security/security-patch-table.svelteindex 86986f069..8468ae930 100644--- a/frontend/src/routes/(app)/security/security-patch-table.svelte+++ b/frontend/src/routes/(app)/security/security-patch-table.svelte@@ -1,6 +1,7 @@<script lang="ts">import { featureStore } from '#lib/stores/features.store.svelte.js';import { tryCatch } from '#lib/utils/try-catch.js';+ import { extractApiErrorMessage } from '#lib/utils/api.js';import ArcaneTable from '#lib/components/arcane-table/arcane-table.svelte';import RowActionsMenu from '#lib/components/arcane-table/row-actions-menu.svelte';@@ -63,7 +64,7 @@const error = operationResult.error;console.error('Failed to patch image:', error);- toast.error(m.images_patch_failed());+ toast.error(m.images_patch_failed(), { description: extractApiErrorMessage(error) });}}