diff --git a/plugins/runner/go.mod b/plugins/runner/go.mod index ad0f35fd9..3aafbb730 100644 --- a/plugins/runner/go.mod +++ b/plugins/runner/go.mod @@ -5,6 +5,7 @@ go 1.22.4 require ( github.com/docker/docker v26.1.4+incompatible github.com/docker/go-connections v0.5.0 + github.com/google/uuid v1.6.0 github.com/hashicorp/go-multierror v1.1.1 github.com/oapi-codegen/oapi-codegen/v2 v2.3.0 github.com/openclarity/vmclarity/core v0.7.2 @@ -54,7 +55,6 @@ require ( github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect github.com/google/go-cmp v0.6.0 // indirect github.com/google/go-containerregistry v0.19.2 // indirect - github.com/google/uuid v1.6.0 // indirect github.com/hashicorp/errwrap v1.1.0 // indirect github.com/invopop/yaml v0.2.0 // indirect github.com/josharian/intern v1.0.0 // indirect diff --git a/plugins/runner/internal/runtimehandler/binary/handler.go b/plugins/runner/internal/runtimehandler/binary/handler.go index 81426ed38..5930eb42d 100644 --- a/plugins/runner/internal/runtimehandler/binary/handler.go +++ b/plugins/runner/internal/runtimehandler/binary/handler.go @@ -30,6 +30,7 @@ import ( "sync" "syscall" + "github.com/google/uuid" multierror "github.com/hashicorp/go-multierror" "github.com/openclarity/vmclarity/plugins/runner/internal/runtimehandler" @@ -45,18 +46,20 @@ type binaryRuntimeHandler struct { stdoutPipe io.ReadCloser stderrPipe io.ReadCloser + pluginServerEndpoint string + outputFilePath string pluginDir string inputDirMountPoint string - pluginServerEndpoint string - ready bool imageCleanup func() + ready bool mu sync.Mutex } func New(ctx context.Context, config types.PluginConfig) (runtimehandler.PluginRuntimeHandler, error) { return &binaryRuntimeHandler{ - config: config, + config: config, + outputFilePath: fmt.Sprintf("/tmp/%s.json", uuid.New().String()), }, nil } @@ -196,6 +199,10 @@ func (h *binaryRuntimeHandler) GetPluginServerEndpoint(ctx context.Context) (str return h.pluginServerEndpoint, nil } +func (h *binaryRuntimeHandler) GetOutputFilePath(ctx context.Context) (string, error) { + return h.outputFilePath, nil +} + func (h *binaryRuntimeHandler) Logs(ctx context.Context) (io.ReadCloser, error) { if h.cmd == nil { return nil, errors.New("plugin process is not running") @@ -216,7 +223,7 @@ func (h *binaryRuntimeHandler) Logs(ctx context.Context) (io.ReadCloser, error) } func (h *binaryRuntimeHandler) Result(ctx context.Context) (io.ReadCloser, error) { - f, err := os.Open(filepath.Join(h.pluginDir, runtimehandler.RemoteScanResultFileOverride)) + f, err := os.Open(filepath.Join(h.pluginDir, h.outputFilePath)) if err != nil { return nil, fmt.Errorf("unable to open result file: %w", err) } diff --git a/plugins/runner/internal/runtimehandler/docker/handler.go b/plugins/runner/internal/runtimehandler/docker/handler.go index a67f38cf6..ed0d99d6b 100644 --- a/plugins/runner/internal/runtimehandler/docker/handler.go +++ b/plugins/runner/internal/runtimehandler/docker/handler.go @@ -229,6 +229,10 @@ func (h *containerRuntimeHandler) GetPluginServerEndpoint(ctx context.Context) ( return "http://" + net.JoinHostPort("127.0.0.1", hostPorts[0].HostPort), nil } +func (h *containerRuntimeHandler) GetOutputFilePath(ctx context.Context) (string, error) { + return runtimehandler.RemoteScanResultFileOverride, nil +} + func (h *containerRuntimeHandler) Result(ctx context.Context) (io.ReadCloser, error) { // Copy result file from container reader, _, err := h.client.CopyFromContainer(ctx, h.containerID, runtimehandler.RemoteScanResultFileOverride) diff --git a/plugins/runner/internal/runtimehandler/types.go b/plugins/runner/internal/runtimehandler/types.go index 7ebc431b7..87e17d255 100644 --- a/plugins/runner/internal/runtimehandler/types.go +++ b/plugins/runner/internal/runtimehandler/types.go @@ -33,6 +33,7 @@ type PluginRuntimeHandler interface { Start(ctx context.Context) error Ready() (bool, error) GetPluginServerEndpoint(ctx context.Context) (string, error) + GetOutputFilePath(ctx context.Context) (string, error) Logs(ctx context.Context) (io.ReadCloser, error) Result(ctx context.Context) (io.ReadCloser, error) Remove(ctx context.Context) error @@ -43,7 +44,7 @@ type PluginRuntimeHandler interface { func WithOverrides(c plugintypes.Config) plugintypes.Config { return plugintypes.Config{ InputDir: RemoteScanInputDirOverride, - OutputFile: RemoteScanResultFileOverride, + OutputFile: c.OutputFile, ScannerConfig: c.ScannerConfig, TimeoutSeconds: c.TimeoutSeconds, } diff --git a/plugins/runner/runner.go b/plugins/runner/runner.go index 7ac7ab07c..e691060f1 100644 --- a/plugins/runner/runner.go +++ b/plugins/runner/runner.go @@ -142,9 +142,14 @@ func (r *pluginRunner) Run(ctx context.Context) error { return errors.New("client missing, did not wait for ready state") } - _, err := r.client.PostConfigWithResponse( + outputFilePath, err := r.runtimeHandler.GetOutputFilePath(ctx) + if err != nil { + return fmt.Errorf("failed to get plugin output file path: %w", err) + } + _, err = r.client.PostConfigWithResponse( ctx, runtimehandler.WithOverrides(plugintypes.Config{ + OutputFile: outputFilePath, ScannerConfig: to.Ptr(r.config.ScannerConfig), TimeoutSeconds: int(types.ScanTimeout.Seconds()), }),