Skip to content

Commit

Permalink
disable os detection for registry images
Browse files Browse the repository at this point in the history
Signed-off-by: Ivan Milchev <[email protected]>
  • Loading branch information
imilchev committed Feb 13, 2024
1 parent 3fbfe31 commit 7d26245
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 7 deletions.
30 changes: 25 additions & 5 deletions providers/os/connection/docker_container.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,8 +174,16 @@ func (c *DockerContainerConnection) RunCommand(command string) (*shared.Command,
return res, err
}

type DockerRegistryImageConnection struct {
*TarConnection
}

func (c *DockerRegistryImageConnection) Type() shared.ConnectionType {
return shared.Type_RegistryImage
}

// NewContainerRegistryImage loads a container image from a remote registry
func NewContainerRegistryImage(id uint32, conf *inventory.Config, asset *inventory.Asset) (*TarConnection, error) {
func NewContainerRegistryImage(id uint32, conf *inventory.Config, asset *inventory.Asset) (*DockerRegistryImageConnection, error) {
ref, err := name.ParseReference(conf.Host, name.WeakValidation)
if err == nil {
log.Debug().Str("ref", ref.Name()).Msg("found valid container registry reference")
Expand Down Expand Up @@ -235,7 +243,7 @@ func NewContainerRegistryImage(id uint32, conf *inventory.Config, asset *invento
conn.Metadata.Labels = labels
asset.Labels = labels

return conn, err
return &DockerRegistryImageConnection{TarConnection: conn}, err
}
log.Debug().Str("image", conf.Host).Msg("Could not detect a valid repository url")
return nil, err
Expand Down Expand Up @@ -285,7 +293,15 @@ func NewDockerEngineContainer(id uint32, conf *inventory.Config, asset *inventor
}
}

func NewDockerContainerImageConnection(id uint32, conf *inventory.Config, asset *inventory.Asset) (*TarConnection, error) {
type DockerImageConnection struct {
*TarConnection
}

func (c *DockerImageConnection) Type() shared.ConnectionType {
return shared.Type_DockerImage
}

func NewDockerContainerImageConnection(id uint32, conf *inventory.Config, asset *inventory.Asset) (shared.Connection, error) {
disableInmemoryCache := false
if _, ok := conf.Options["disable-cache"]; ok {
var err error
Expand All @@ -310,7 +326,11 @@ func NewDockerContainerImageConnection(id uint32, conf *inventory.Config, asset
asset.Name = resolvedAssets[0].Name
asset.PlatformIds = resolvedAssets[0].PlatformIds
asset.Labels = resolvedAssets[0].Labels
return NewContainerRegistryImage(id, conf, asset)
conn, err := NewContainerRegistryImage(id, conf, asset)
if err != nil {
return nil, err
}
return conn, nil
}

// could be an image id/name, container id/name or a short reference to an image in docker engine
Expand Down Expand Up @@ -357,7 +377,7 @@ func NewDockerContainerImageConnection(id uint32, conf *inventory.Config, asset
tarConn.PlatformIdentifier = identifier
tarConn.Metadata.Name = ii.Name
tarConn.Metadata.Labels = ii.Labels
return tarConn, nil
return &DockerImageConnection{TarConnection: tarConn}, nil
}

// based on the target, try and find out what kind of connection we are dealing with, this can be either a
Expand Down
1 change: 1 addition & 0 deletions providers/os/connection/tar.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ func NewTarConnectionForContainer(id uint32, conf *inventory.Config, asset *inve
asset: asset,
Fs: provider_tar.NewFs(""),
fetchFn: func() (string, error) {
log.Warn().Msg("loading container image into tar connection")
err = cache.StreamToTmpFile(mutate.Extract(img), f)
if err != nil {
os.Remove(f.Name())
Expand Down
8 changes: 6 additions & 2 deletions providers/os/detector/platform_resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,15 @@ func (r *PlatformResolver) Resolve(conn shared.Connection) (*inventory.Platform,
di.Family = make([]string, 0)

// start recursive platform resolution
pi, resolved := r.resolvePlatform(di, conn)
pi := &inventory.Platform{}
resolved := conn.Type() == shared.Type_RegistryImage
if conn.Type() != shared.Type_RegistryImage {
pi, resolved = r.resolvePlatform(di, conn)
}

// if we have a container image use the architecture specified in the transport as it is resolved
// using the container image properties
tarConn, ok := conn.(*connection.TarConnection)
tarConn, ok := conn.(*connection.DockerRegistryImageConnection)
if resolved && ok {
pi.Arch = tarConn.PlatformArchitecture
di.Runtime = "docker-image"
Expand Down

0 comments on commit 7d26245

Please sign in to comment.