Skip to content

Commit

Permalink
fix docker image scan for remote images (#3646)
Browse files Browse the repository at this point in the history
Signed-off-by: Ivan Milchev <[email protected]>
  • Loading branch information
imilchev authored Mar 26, 2024
1 parent 3af3e01 commit 1d86261
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 deletions.
5 changes: 4 additions & 1 deletion providers/os/connection/container/image_connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package container
import (
"errors"
"os"
"slices"

"github.com/google/go-containerregistry/pkg/name"
v1 "github.com/google/go-containerregistry/pkg/v1"
Expand Down Expand Up @@ -95,7 +96,9 @@ func NewRegistryImage(id uint32, conf *inventory.Config, asset *inventory.Asset)
if len(asset.PlatformIds) == 0 {
asset.PlatformIds = []string{identifier}
} else {
asset.PlatformIds = append(asset.PlatformIds, identifier)
if !slices.Contains(asset.PlatformIds, identifier) {
asset.PlatformIds = append(asset.PlatformIds, identifier)
}
}

// set the platform architecture using the image configuration
Expand Down
18 changes: 9 additions & 9 deletions providers/os/connection/docker/container_connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,15 @@ func NewContainerImageConnection(id uint32, conf *inventory.Config, asset *inven
return nil, err
}
}
if conf.Options == nil {
conf.Options = map[string]string{}
}
// FIXME: DEPRECATED, remove in v12.0 vv
// The DelayDiscovery flag should always be set from v12
if conf.Options == nil || conf.Options[plugin.DISABLE_DELAYED_DISCOVERY_OPTION] == "" {
conf.DelayDiscovery = true // Delay discovery, to make sure we don't directly download the image
}
// ^^
// Determine whether the image is locally present or not.
resolver := dockerDiscovery.Resolver{}
resolvedAssets, err := resolver.Resolve(context.Background(), asset, conf, nil)
Expand Down Expand Up @@ -297,16 +306,7 @@ func NewContainerImageConnection(id uint32, conf *inventory.Config, asset *inven
}
filename = tmpFile.Name()

if conf.Options == nil {
conf.Options = map[string]string{}
}
conf.Options[tar.OPTION_FILE] = filename
// FIXME: DEPRECATED, remove in v12.0 vv
// The DelayDiscovery flag should always be set from v12
if conf.Options == nil || conf.Options[plugin.DISABLE_DELAYED_DISCOVERY_OPTION] == "" {
conf.DelayDiscovery = true // Delay discovery, to make sure we don't directly download the image
}
// ^^

tarConn, err := tar.NewConnection(
id,
Expand Down

0 comments on commit 1d86261

Please sign in to comment.