From 1aa9c4b967b37e2a5720b5c71fc527c28a8424b5 Mon Sep 17 00:00:00 2001 From: Zbigniew Baranowski Date: Sat, 1 Jun 2024 10:23:08 +0200 Subject: [PATCH] fix: don't map the image name in sbom reports (#647) fixes: #645 Co-authored-by: Zbigniew BARANOWSKI --- internal/processor/processor.go | 11 ----------- internal/syft/syft.go | 9 +++++++++ 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/internal/processor/processor.go b/internal/processor/processor.go index 44be8226..30364b00 100644 --- a/internal/processor/processor.go +++ b/internal/processor/processor.go @@ -7,7 +7,6 @@ import ( libk8s "github.com/ckotzbauer/libk8soci/pkg/kubernetes" liboci "github.com/ckotzbauer/libk8soci/pkg/oci" - "github.com/ckotzbauer/libstandard" "github.com/ckotzbauer/sbom-operator/internal" "github.com/ckotzbauer/sbom-operator/internal/job" "github.com/ckotzbauer/sbom-operator/internal/kubernetes" @@ -185,11 +184,6 @@ func (p *Processor) executeSyftScans(pods []libk8s.PodInfo, allImages []*liboci. targetImages := t.LoadImages() removableImages := make([]*liboci.RegistryImage, 0) for _, t := range targetImages { - err := kubernetes.ApplyProxyRegistry(t, false, libstandard.ToMap(internal.OperatorConfig.RegistryProxies)) - if err != nil { - logrus.WithError(err).Debugf("Could not parse image") - } - if !containsImage(allImages, t.ImageID) { removableImages = append(removableImages, t) delete(p.imageMap, t.ImageID) @@ -287,11 +281,6 @@ func (p *Processor) cleanupImagesIfNeeded(removedContainers []*libk8s.ContainerI for _, po := range allPods { pod := po.(*corev1.Pod) info := p.K8s.Client.ExtractPodInfos(*pod) - err := kubernetes.ApplyProxyRegistry(c.Image, false, libstandard.ToMap(internal.OperatorConfig.RegistryProxies)) - if err != nil { - logrus.WithError(err).Debugf("Could not parse image") - } - found = found || containsContainerImage(info.Containers, c.Image.ImageID) } diff --git a/internal/syft/syft.go b/internal/syft/syft.go index d9b380e2..b20effa1 100644 --- a/internal/syft/syft.go +++ b/internal/syft/syft.go @@ -54,6 +54,10 @@ func (s Syft) WithSyftVersion(version string) Syft { func (s *Syft) ExecuteSyft(img *oci.RegistryImage) (string, error) { logrus.Infof("Processing image %s", img.ImageID) + + oriImage := img.Image + oriImageID := img.ImageID + err := kubernetes.ApplyProxyRegistry(img, true, s.proxyRegistryMap) if err != nil { return "", err @@ -61,6 +65,11 @@ func (s *Syft) ExecuteSyft(img *oci.RegistryImage) (string, error) { opts := &image.RegistryOptions{Credentials: oci.ConvertSecrets(*img, s.proxyRegistryMap)} src, err := getSource(context.Background(), opts, img.ImageID) + + // revert image info to the original value - we want to register with original names + img.Image = oriImage + img.ImageID = oriImageID + if err != nil { logrus.WithError(fmt.Errorf("failed to construct source from input registry:%s: %w", img.ImageID, err)).Error("Source-Creation failed") return "", err