From a70a04fa99c8dcc721a0633b749512aa147fcd76 Mon Sep 17 00:00:00 2001 From: Ivan Milchev Date: Wed, 6 Mar 2024 11:30:43 +0100 Subject: [PATCH] skip discovery only for new clients Signed-off-by: Ivan Milchev --- providers-sdk/v1/plugin/service.go | 8 ++++++++ .../os/connection/container/image_connection.go | 8 +++++++- .../os/connection/docker/container_connection.go | 14 ++++++++++++-- 3 files changed, 27 insertions(+), 3 deletions(-) diff --git a/providers-sdk/v1/plugin/service.go b/providers-sdk/v1/plugin/service.go index 7ec9427ecf..38913b900e 100644 --- a/providers-sdk/v1/plugin/service.go +++ b/providers-sdk/v1/plugin/service.go @@ -15,6 +15,8 @@ import ( inventory "go.mondoo.com/cnquery/v10/providers-sdk/v1/inventory" ) +const DISABLE_DELAYED_DISCOVERY_OPTION = "disable-delayed-discovery" + type Service struct { runtimes map[uint32]*Runtime lastConnectionID uint32 @@ -39,6 +41,12 @@ func (s *Service) AddRuntime(conf *inventory.Config, createRuntime func(connId u // FIXME: DEPRECATED, remove in v12.0 vv // This approach is used only when old clients use new providers. We will throw it away in v12 if conf.Id == 0 { + if conf.Options == nil { + conf.Options = make(map[string]string) + } + + // Disable delayed discovery for old clients since they don't know how to handle it + conf.Options[DISABLE_DELAYED_DISCOVERY_OPTION] = "true" return s.deprecatedAddRuntime(createRuntime) } // ^^ diff --git a/providers/os/connection/container/image_connection.go b/providers/os/connection/container/image_connection.go index 00dae8be8e..0353f0c326 100644 --- a/providers/os/connection/container/image_connection.go +++ b/providers/os/connection/container/image_connection.go @@ -13,6 +13,7 @@ import ( "github.com/google/go-containerregistry/pkg/v1/tarball" "github.com/rs/zerolog/log" "go.mondoo.com/cnquery/v10/providers-sdk/v1/inventory" + "go.mondoo.com/cnquery/v10/providers-sdk/v1/plugin" "go.mondoo.com/cnquery/v10/providers/os/connection/container/auth" "go.mondoo.com/cnquery/v10/providers/os/connection/container/image" "go.mondoo.com/cnquery/v10/providers/os/connection/tar" @@ -21,7 +22,12 @@ import ( // NewImageConnection uses a container image reference as input and creates a tar connection func NewImageConnection(id uint32, conf *inventory.Config, asset *inventory.Asset, img v1.Image) (*tar.Connection, error) { - conf.SkipDiscovery = true + // FIXME: DEPRECATED, remove in v12.0 vv + // The SkipDiscovery flag should always be set from v12 + if conf.Options == nil || conf.Options[plugin.DISABLE_DELAYED_DISCOVERY_OPTION] == "" { + conf.SkipDiscovery = true // Skip discovery, to make sure we don't directly download the image + } + // ^^ f, err := tar.RandomFile() if err != nil { return nil, err diff --git a/providers/os/connection/docker/container_connection.go b/providers/os/connection/docker/container_connection.go index c4a70b7614..e83abf8b03 100644 --- a/providers/os/connection/docker/container_connection.go +++ b/providers/os/connection/docker/container_connection.go @@ -216,7 +216,12 @@ func NewDockerEngineContainer(id uint32, conf *inventory.Config, asset *inventor conn.PlatformIdentifier = containerid.MondooContainerID(ci.ID) conn.Metadata.Name = containerid.ShortContainerImageID(ci.ID) conn.Metadata.Labels = ci.Labels - conf.SkipDiscovery = true // Skip discovery, to make sure we don't directly download the image + // FIXME: DEPRECATED, remove in v12.0 vv + // The SkipDiscovery flag should always be set from v12 + if conf.Options == nil || conf.Options[plugin.DISABLE_DELAYED_DISCOVERY_OPTION] == "" { + conf.SkipDiscovery = true // Skip discovery, to make sure we don't directly download the image + } + // ^^ asset.Name = ci.Name asset.PlatformIds = []string{containerid.MondooContainerID(ci.ID)} return conn, nil @@ -296,7 +301,12 @@ func NewContainerImageConnection(id uint32, conf *inventory.Config, asset *inven conf.Options = map[string]string{} } conf.Options[tar.OPTION_FILE] = filename - conf.SkipDiscovery = true // Skip discovery, to make sure we don't directly download the image + // FIXME: DEPRECATED, remove in v12.0 vv + // The SkipDiscovery flag should always be set from v12 + if conf.Options == nil || conf.Options[plugin.DISABLE_DELAYED_DISCOVERY_OPTION] == "" { + conf.SkipDiscovery = true // Skip discovery, to make sure we don't directly download the image + } + // ^^ tarConn, err := tar.NewConnection( id,