diff --git a/cmd/docker-scan/main.go b/cmd/docker-scan/main.go index 8aed11ad..ff40ac31 100644 --- a/cmd/docker-scan/main.go +++ b/cmd/docker-scan/main.go @@ -214,7 +214,7 @@ func runAuthentication(ctx context.Context, dockerCli command.Cli, flags options func runScan(ctx context.Context, cmd *cobra.Command, dockerCli command.Cli, flags options, args []string) error { scanProvider, err := configureProvider(ctx, dockerCli, flags, provider.WithAuthConfig(func(hub *registry.IndexInfo) types.AuthConfig { return command.ResolveAuthConfig(context.Background(), dockerCli, hub) - })) + }), provider.WithVersion(internal.Version)) if len(args) != 1 { if err := cmd.Usage(); err != nil { return err diff --git a/e2e/version_test.go b/e2e/version_test.go index 428c9584..4e708d38 100644 --- a/e2e/version_test.go +++ b/e2e/version_test.go @@ -123,7 +123,7 @@ Provider: %s } func getProviderVersion(env string) string { - if runtime.GOOS != "windows" { + if runtime.GOOS == "linux" { return fmt.Sprintf("Snyk (%s (standalone))", os.Getenv(env)) } return fmt.Sprintf("Snyk (%s)", os.Getenv(env)) diff --git a/internal/provider/containerizedsnyk.go b/internal/provider/containerizedsnyk.go index f565bab8..626d54e8 100644 --- a/internal/provider/containerizedsnyk.go +++ b/internal/provider/containerizedsnyk.go @@ -144,6 +144,7 @@ func (d *dockerSnykProvider) createContainer(token string, containerName string) "NO_UPDATE_NOTIFIER=true", "SNYK_CFG_DISABLESUGGESTIONS=true", "SNYK_INTEGRATION_NAME=DOCKER_DESKTOP", + "SNYK_INTEGRATION_VERSION=" + d.version, "SNYK_UTM_MEDIUM=Partner", "SNYK_UTM_SOURCE=Docker", "SNYK_UTM_CAMPAIGN=Docker-Desktop-2020", @@ -282,8 +283,12 @@ func (d *dockerSnykProvider) newCommand(envVars []string, arg ...string) (string arg[index] = "--file=/app/Dockerfile" } } - defaultEnvs := []string{"NO_UPDATE_NOTIFIER=true", "SNYK_CFG_DISABLESUGGESTIONS=true", - "SNYK_INTEGRATION_NAME=DOCKER_DESKTOP"} + defaultEnvs := []string{ + "NO_UPDATE_NOTIFIER=true", + "SNYK_CFG_DISABLESUGGESTIONS=true", + "SNYK_INTEGRATION_NAME=DOCKER_DESKTOP", + "SNYK_INTEGRATION_VERSION=" + d.version, + } envVars = append(envVars, defaultEnvs...) args := strslice.StrSlice{"snyk"} diff --git a/internal/provider/provider.go b/internal/provider/provider.go index f0520289..cae4a0f8 100644 --- a/internal/provider/provider.go +++ b/internal/provider/provider.go @@ -45,6 +45,7 @@ type Options struct { out io.Writer err io.Writer path string + version string } // NewProvider returns default provider options setup with the give options @@ -78,7 +79,7 @@ func WithAuthConfig(authResolver func(*registry.IndexInfo) types.AuthConfig) Ops } } -//WithContext update the provider with a cancelable context +// WithContext update the provider with a cancelable context func WithContext(ctx context.Context) Ops { return func(options *Options) error { options.context = ctx @@ -86,7 +87,7 @@ func WithContext(ctx context.Context) Ops { } } -//WithStreams sets the out and err streams to be used by commands +// WithStreams sets the out and err streams to be used by commands func WithStreams(out, err io.Writer) Ops { return func(options *Options) error { options.out = out @@ -184,6 +185,14 @@ func WithExperimental() Ops { } } +// WithVersion set the version of the scan cli plugin to the provider +func WithVersion(version string) Ops { + return func(provider *Options) error { + provider.version = version + return nil + } +} + func getToken(opts Options) (string, error) { if opts.auth.Username == "" { return "", fmt.Errorf(`You need to be logged in to Docker Hub to use the scan feature. diff --git a/internal/provider/snyk.go b/internal/provider/snyk.go index 8f06d418..c03b739f 100644 --- a/internal/provider/snyk.go +++ b/internal/provider/snyk.go @@ -112,7 +112,9 @@ func (s *snykProvider) newCommand(arg ...string) *exec.Cmd { cmd.Env = append(os.Environ(), "NO_UPDATE_NOTIFIER=true", "SNYK_CFG_DISABLESUGGESTIONS=true", - "SNYK_INTEGRATION_NAME=DOCKER_DESKTOP") + "SNYK_INTEGRATION_NAME=DOCKER_DESKTOP", + "SNYK_INTEGRATION_VERSION="+s.version, + ) return cmd } diff --git a/internal/provider/snyk_test.go b/internal/provider/snyk_test.go index 934944d4..30d7cbbd 100644 --- a/internal/provider/snyk_test.go +++ b/internal/provider/snyk_test.go @@ -35,7 +35,8 @@ var ( ) const ( - snykToken = "aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee" + snykToken = "aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee" + fakeVersion = "abcd1234" ) func TestSnykLoginEnvVars(t *testing.T) { @@ -48,8 +49,10 @@ func TestSnykLoginEnvVars(t *testing.T) { err := provider.Authenticate(snykToken) assert.NilError(t, err) - // SNYK_INTEGRATION is always set + // SNYK_INTEGRATION_NAME is always set assert.Assert(t, strings.Contains(outStream.String(), "SNYK_INTEGRATION_NAME=DOCKER_DESKTOP")) + // SNYK_INTEGRATION_VERSION is always set + assert.Assert(t, strings.Contains(outStream.String(), "SNYK_INTEGRATION_VERSION="+fakeVersion)) // NO_UPDATE_NOTIFIER disables node.js automatic update notification in console assert.Assert(t, strings.Contains(outStream.String(), "NO_UPDATE_NOTIFIER=true")) // SNYK_CFG_DISABLESUGGESTIONS removes user hints from snyk @@ -78,8 +81,10 @@ func TestSnykScanEnvVars(t *testing.T) { err := provider.Scan("image") assert.NilError(t, err) - // SNYK_INTEGRATION is always set + // SNYK_INTEGRATION_NAME is always set assert.Assert(t, strings.Contains(outStream.String(), "SNYK_INTEGRATION_NAME=DOCKER_DESKTOP")) + // SNYK_INTEGRATION_VERSION is always set + assert.Assert(t, strings.Contains(outStream.String(), "SNYK_INTEGRATION_VERSION="+fakeVersion)) // NO_UPDATE_NOTIFIER disables node.js automatic update notification in console assert.Assert(t, strings.Contains(outStream.String(), "NO_UPDATE_NOTIFIER=true")) // SNYK_CFG_DISABLESUGGESTIONS removes user hints from snyk @@ -95,7 +100,9 @@ func setupMockSnykBinary(t *testing.T) (Provider, *bytes.Buffer) { defaultProvider, err := NewProvider(WithContext(context.Background()), WithPath(snykPath), - WithStreams(outStream, errStream)) + WithStreams(outStream, errStream), + WithVersion(fakeVersion), + ) assert.NilError(t, err) provider, err := NewSnykProvider( defaultProvider) diff --git a/vars.mk b/vars.mk index 079794da..b12fef4a 100644 --- a/vars.mk +++ b/vars.mk @@ -1,9 +1,9 @@ # Pinned Versions -SNYK_DESKTOP_VERSION=1.1025.0 -SNYK_USER_VERSION=1.1025.0 +SNYK_DESKTOP_VERSION=1.1054.0 +SNYK_USER_VERSION=1.1054.0 SNYK_OLD_VERSION=1.382.1 -# Digest of the 1.1025.0 snyk/snyk:docker image -SNYK_IMAGE_DIGEST=sha256:b979e1827473ce7675439213a918687ac532481c3370818bce61884735bdb09d +# Digest of the 1.1054.0 snyk/snyk:docker image +SNYK_IMAGE_DIGEST=sha256:81c312b1dd662a492a1cf40e597359dd391653293bd17674f8f60a021d687c58 GO_VERSION=1.17.5 CLI_VERSION=20.10.11 ALPINE_VERSION=3.15.0